removed fix_db, fixes.sql, and updated todo

This commit is contained in:
2020-11-17 21:30:51 +11:00
parent 4ee94337b2
commit f765a18327
3 changed files with 3 additions and 96 deletions

9
README
View File

@@ -14,19 +14,16 @@ sudo apt install python3-pip python3-psycopg2 libpq-dev
pip3 install --user flask sqlalchemy flask-sqlalchemy flask-marshmallow SQLAlchemy-serializer flask-wtf flask-bootstrap marshmallow-sqlalchemy
### fix up db changes by running those in fixes.sql
psql library
alter table genre_lst rename to genre;
alter table genre rename COLUMN genre to name;
# run the web server by:
python3 main.py
### TODO:
- fix up lame book linkages to tabels that are so not 3nf, *_LST tables, etc.
- ORM:
- saving a book with the ORM is probably the last oddity... probably time to try it (in a sense, the book edit page is the only time we change things, maybe we mess with that book-query as its too slow, and for book edit, if we don't allow editing items like author/publisher, then may only need to set the objects we want to change... I'm sort of curious can you save a book table based on id, without saging its author table, seems that should be okay, but how do I save both, just create 2 objects and do it, but what if the ORM has auto-connected bunches of stuff, how do I update the connected stuff.... MAYBE, I need to get say loan or something first, then try all this? (make a pop-up for stuff like loans, but what about series or sub-book editing????)
- should see if I can make the publisher, rating, covertype, condition, genre tables have generic .html files
- complete BookSchema(FlaskForm)
- use FlaskForm and newer technique in author.html (and the rest)
- consider getting rest of Book class connected, e.g. series, loan, etc.

View File

@@ -1,79 +0,0 @@
ALTER TABLE genre_lst RENAME TO genre;
ALTER TABLE genre RENAME COLUMN genre TO name;
CREATE TABLE condition (
id INTEGER,
name VARCHAR(20) not null,
constraint pk_condition primary key(id)
);
INSERT INTO condition VALUES ( 1, 'Good' );
INSERT INTO condition VALUES ( 2, 'Average' );
INSERT INTO condition VALUES ( 3, 'Needs Replacing' );
INSERT INTO condition VALUES ( 4, 'N/A' );
ALTER TABLE book ADD COLUMN temp_cond integer , ADD CONSTRAINT fk_book_condition_new foreign key(temp_cond) REFERENCES condition(id)
CREATE TABLE covertype (
id INTEGER,
name VARCHAR(20) not null,
constraint pk_covertype primary key(id)
);
INSERT INTO covertype VALUES ( 1, 'Paperback' );
INSERT INTO covertype VALUES ( 2, 'Over-size Paperback' );
INSERT INTO covertype VALUES ( 3, 'Hardcover' );
INSERT INTO covertype VALUES ( 4, 'N/A' );
ALTER TABLE book ADD COLUMN temp_cover integer , ADD CONSTRAINT fk_book_covertype_new foreign key(temp_cover) REFERENCES covertype(id)
CREATE TABLE owned (
id INTEGER,
name VARCHAR(20) not null,
constraint pk_owned primary key(id)
);
INSERT INTO owned VALUES ( 1, 'Currently Owned' );
INSERT INTO owned VALUES ( 2, 'On Wish List' );
INSERT INTO owned VALUES ( 3, 'Sold' );
ALTER TABLE book ADD COLUMN temp_owned integer , ADD CONSTRAINT fk_book_owned_new foreign key(temp_owned) REFERENCES owned(id);
CREATE TABLE rating (
id INTEGER,
name VARCHAR(20) not null,
constraint pk_rating primary key(id)
);
INSERT INTO rating VALUES ( 1, '10' );
INSERT INTO rating VALUES ( 2, '9' );
INSERT INTO rating VALUES ( 3, '8' );
INSERT INTO rating VALUES ( 4, '7' );
INSERT INTO rating VALUES ( 5, '6' );
INSERT INTO rating VALUES ( 6, '5' );
INSERT INTO rating VALUES ( 7, '4' );
INSERT INTO rating VALUES ( 8, '3' );
INSERT INTO rating VALUES ( 9, '2' );
INSERT INTO rating VALUES ( 10, '1' );
INSERT INTO rating VALUES ( 11, 'N/A' );
INSERT INTO rating VALUES ( 12, 'Undefined' );
ALTER TABLE book ADD COLUMN temp_rating integer, ADD CONSTRAINT fk_book_rating_new foreign key(temp_rating) REFERENCES rating(id);
### fore each new table (e.g do above), then
# add appropriate new field to Book class definition, eg for condition:
temp_cond = db.Column(db.Integer)
# then run python code with fix_db() -- which fixes appropriate Book.<new_field>, then:
ALTER TABLE book DROP COLUMN condition;
ALTER TABLE book RENAME COLUMN temp_cond TO condition;
ALTER TABLE book DROP COLUMN covertype;
ALTER TABLE book RENAME COLUMN temp_cover TO covertype;
ALTER TABLE book DROP COLUMN owned;
ALTER TABLE book RENAME COLUMN temp_owned TO owned;
ALTER TABLE book DROP COLUMN rating;
ALTER TABLE book RENAME COLUMN temp_rating TO rating;
DROP TABLE condition_lst;
DROP TABLE covertype_lst;
DROP TABLE owned_lst;
DROP TABLE rating_lst;
# then modify main.py again, to delete condition and rename temp_<field> to <feild> in class Book

11
main.py
View File

@@ -155,16 +155,5 @@ def book(id):
def main_page():
return render_template("base.html")
def fix_db():
books = Book.query.all()
for book in books:
rating=Rating.query.filter_by(name=book.rating).all()
book.temp_rating=rating[0].id
print(book.temp_rating)
db.session.commit()
print( "ran fix_db()")
if __name__ == "__main__":
# fix_db()
app.run(host="0.0.0.0", debug=True)