Repository navigation
Expand file tree
/
Copy pathmigrations.py
More file actions
61 lines (51 loc) · 1.43 KB
/
Copy pathmigrations.py
File metadata and controls
61 lines (51 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/env python3
from typing import Optional
from dotenv import load_dotenv
import typer
load_dotenv(".env")
app = typer.Typer(add_completion=False)
@app.command(
help="Run the latest migrations."
)
def migrate():
typer.echo("Migrating")
import alembic.config #вот тут я б разобрался
alembicArgs = [
'--raiseerr',
'upgrade', 'head',
]
alembic.config.main(argv=alembicArgs)
@app.command(
help="Create new migrations"
)
def create_migrations(message: Optional[str] = typer.Argument("new migrations")):
typer.echo(f"Creating migration '{message}'")
import alembic.config
alembicArgs = [
'--raiseerr',
'revision', '--autogenerate', "-m", message,
]
alembic.config.main(argv=alembicArgs)
@app.command(
help="DB values Initialization"
)
def init_values():
from crud.crud_session import connection_string_direct
import sqlalchemy as sa
from sqlalchemy.sql import text
engine = sa.create_engine(connection_string_direct)
conn = engine.connect()
# c = conn.cursor()
fd = open('Init_values.sql', 'r')
sqlFile = fd.read()
fd.close()
sqlCommands = sqlFile.split(';')
for command in sqlCommands:
try:
conn.execute(command)
except Exception as ex:
print(f'Command skipped. {command=}, {str(ex)=}')
if __name__ == "__main__":
# migrate()
# create_migrations()
app()