Skip to content

Commit

Permalink
Update dependencies in order to build
Browse files Browse the repository at this point in the history
  • Loading branch information
Multipacker authored and The1Penguin committed Oct 17, 2024
1 parent f5cce62 commit b3665a8
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 18 deletions.
12 changes: 6 additions & 6 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
13 changes: 7 additions & 6 deletions src/migrate.py
Original file line number Diff line number Diff line change
@@ -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():
Expand Down
13 changes: 7 additions & 6 deletions src/migrations/01-string-length.py
Original file line number Diff line number Diff line change
@@ -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")
Expand Down

0 comments on commit b3665a8

Please sign in to comment.