Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from importlib import import_module

from sqlalchemy import Boolean, MetaData, Table, create_engine
from sqlalchemy.schema import AddConstraint, DropConstraint, ForeignKeyConstraint
from sqlalchemy.schema import AddConstraint, CreateTable, DropConstraint, ForeignKeyConstraint


def warninger(message, category, filename, lineno, line=None):
Expand Down Expand Up @@ -175,7 +175,22 @@ def warninger(message, category, filename, lineno, line=None):

if args.drop_first:
table.drop(engine, checkfirst=True)
table.create(engine, checkfirst=True)

# SQLAlchemy neumi SQLite STRICT tables, tak to udelame trochu humpolacky
if engine.name == "sqlite":
ddl = CreateTable(table).compile(engine).string
ddl += " STRICT"
ddl = ddl.replace(" BIGINT", " INT")
ddl = ddl.replace(" SMALLINT", " INT")
ddl = ddl.replace(" DATE", " TEXT")
ddl = ddl.replace(" TIME", " TEXT")
ddl = ddl.replace(" JSON", " TEXT")
ddl = ddl.replace(" BOOLEAN", " INT")
# TODO: NUMERIC
conn = engine.raw_connection()
conn.execute(ddl)
else:
table.create(engine, checkfirst=True)

# dropni fkeys pred nahravanim dat
# z nejakeho duvodu jsou v sqlite nepojmenovany klice
Expand Down