first commit
This commit is contained in:
24
service_app_init/alembic_generate.py
Normal file
24
service_app_init/alembic_generate.py
Normal file
@@ -0,0 +1,24 @@
|
||||
import os
|
||||
|
||||
|
||||
def generate_alembic_with_session(text):
|
||||
from databases.sql_models.postgres_database import session
|
||||
|
||||
try:
|
||||
result = session.execute(
|
||||
text(
|
||||
"SELECT EXISTS (SELECT 1 FROM information_schema.tables WHERE table_name = "
|
||||
"'alembic_version') AS table_existence;"
|
||||
)
|
||||
)
|
||||
if result.first()[0]:
|
||||
session.execute(text("delete from alembic_version;"))
|
||||
session.commit()
|
||||
except Exception as e:
|
||||
print(e)
|
||||
finally:
|
||||
run_command = "python -m alembic stamp head;"
|
||||
run_command += (
|
||||
"python -m alembic revision --autogenerate;python -m alembic upgrade head;"
|
||||
)
|
||||
os.system(run_command)
|
||||
Reference in New Issue
Block a user