diff --git a/requirements.txt b/requirements.txt index 382e5c3..53152d2 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,11 +3,11 @@ Flask==2.2.2 Flask-Login==0.6.2 Flask-SQLAlchemy==3.0.2 Flask-WTF==1.0.1 -greenlet==2.0.1 -itsdangerous==2.1.2 -Jinja2==3.1.2 -MarkupSafe==2.1.1 -SQLAlchemy==1.4.44 -uWSGI==2.0.21 +greenlet==3.1.1 +itsdangerous==2.2.0 +Jinja2==3.1.4 +MarkupSafe==3.0.1 +SQLAlchemy==2.0.36 +uWSGI==2.0.27 Werkzeug==2.2.2 WTForms==2.2.1 diff --git a/src/migrate.py b/src/migrate.py index 3389fa0..1aa536b 100644 --- a/src/migrate.py +++ b/src/migrate.py @@ -1,31 +1,32 @@ from tv import app, db +from sqlalchemy import text import os import re import importlib def ensure_migration_table(): with app.app_context(): - table = db.session.execute("SELECT name FROM sqlite_master WHERE type='table' AND name='migration'") + table = db.session.execute(text("SELECT name FROM sqlite_master WHERE type='table' AND name='migration'")) if len(table.fetchall()) != 1: print("Creating migration table") - db.session.execute("CREATE TABLE IF NOT EXISTS migration (" + db.session.execute(text("CREATE TABLE IF NOT EXISTS migration (" "id INTEGER PRIMARY KEY CHECK (id = 0)," "version INTEGER" - ")") - db.session.execute("INSERT INTO migration (id, version) VALUES (0, 0)") + ")")) + db.session.execute(text("INSERT INTO migration (id, version) VALUES (0, 0)")) db.session.commit() def get_migration_version(): ensure_migration_table() with app.app_context(): - version = db.session.execute("SELECT version FROM migration").fetchall()[0][0]; + version = db.session.execute(text("SELECT version FROM migration")).fetchall()[0][0] db.session.commit() return version def set_migration_version(version): ensure_migration_table() with app.app_context(): - db.session.execute(f"UPDATE MIGRATION SET version = :version", { 'version': version }); + db.session.execute(text(f"UPDATE MIGRATION SET version = {version}")) db.session.commit() def do_migrations(): diff --git a/src/migrations/01-string-length.py b/src/migrations/01-string-length.py index d38d13a..4c4c45d 100644 --- a/src/migrations/01-string-length.py +++ b/src/migrations/01-string-length.py @@ -1,22 +1,23 @@ from tv import app, db +from sqlalchemy import text def retype(table, column, newtype): # sql injection is my passion :) [its ok cause the inputs are just hardcoded constants] - db.session.execute(f"ALTER TABLE {table} ADD COLUMN {column}_new {newtype}") - db.session.execute(f"UPDATE {table} SET {column}_new = {column}") - db.session.execute(f"ALTER TABLE {table} DROP COLUMN {column}") - db.session.execute(f"ALTER TABLE {table} RENAME COLUMN {column}_NEW TO {column}") + db.session.execute(text(f"ALTER TABLE {table} ADD COLUMN {column}_new {newtype}")) + db.session.execute(text(f"UPDATE {table} SET {column}_new = {column}")) + db.session.execute(text(f"ALTER TABLE {table} DROP COLUMN {column}")) + db.session.execute(text(f"ALTER TABLE {table} RENAME COLUMN {column}_NEW TO {column}")) def upgrade(): with app.app_context(): - db.session.execute('DROP INDEX ix_user_username') + db.session.execute(text('DROP INDEX ix_user_username')) retype("user", "username", "VARCHAR") retype("user", "password_hash", "VARCHAR") retype("user", "role", "VARCHAR") - db.session.execute('CREATE UNIQUE INDEX ix_user_username ON user (username)') + db.session.execute(text('CREATE UNIQUE INDEX ix_user_username ON user (username)')) retype("pr", "desc", "VARCHAR") retype("pr", "file_name", "VARCHAR")