lavkach3

Форк
0
97 строк · 2.9 Кб
1
import asyncio
2
import os
3
import sys
4
from logging.config import fileConfig
5

6
from alembic import context
7
from sqlalchemy import pool
8
from sqlalchemy.ext.asyncio import create_async_engine
9

10
parent_dir = os.path.abspath(os.path.join(os.getcwd(), ".."))
11
sys.path.append(parent_dir)
12

13
# this is the Alembic Config object, which provides
14
# access to the values within the .ini file in use.
15
config = context.config
16
fileConfig(config.config_file_name)
17
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.realpath(__file__))))
18

19

20
# Interpret the config file for Python logging.
21
# This line sets up loggers basically.
22
fileConfig(config.config_file_name)
23

24
# add your model's MetaData object here
25
# for 'autogenerate' support
26
# from myapp import mymodel
27
# target_metadata = mymodel.Base.metadata
28

29
# For auto generate schemas
30

31
from core.db_config import config
32
from app.inventory.quant.models import *
33
from core.core_apps.base.company.models import *
34
from app.basic.product.models import *
35
from app.basic.store.models import *
36
from core.core_apps.base.user.models import *
37
from app.basic.partner.models import *
38
from app.basic.uom.models import *
39
from app.inventory.location.models import *
40
from app.inventory.order.models import *
41
from app.inventory.product_storage.models import *
42
from core.core_apps.bus.bus.models.bus_models import *
43

44
target_metadata = Base.metadata
45

46
# other values from the config, defined by the needs of env.py,
47
# can be acquired:
48
# my_important_option = config.get_main_option("my_important_option")
49
# ... etc.
50

51

52
def run_migrations_offline():
53
    """Run migrations in 'offline' mode.
54
    This configures the context with just a URL
55
    and not an Engine, though an Engine is acceptable
56
    here as well.  By skipping the Engine creation
57
    we don't even need a DBAPI to be available.
58
    Calls to context.execute() here emit the given string to the
59
    script output.
60
    """
61
    url = config.get_main_option("sqlalchemy.url")
62
    print(config.WRITER_DB_URL)
63
    context.configure(
64
        url=config.WRITER_DB_URL,
65
        target_metadata=target_metadata,
66
        literal_binds=True,
67
        dialect_opts={"paramstyle": "named"},
68
    )
69

70
    with context.begin_transaction():
71
        context.run_migrations()
72

73

74
def do_run_migrations(connection):
75
    context.configure(connection=connection, target_metadata=target_metadata)
76

77
    with context.begin_transaction():
78
        context.run_migrations()
79

80

81
async def run_migrations_online():
82
    """Run migrations in 'online' mode.
83
    In this scenario we need to create an Engine
84
    and associate a connection with the context.
85
    """
86
    connectable = create_async_engine(config.WRITER_DB_URL, poolclass=pool.NullPool, echo=True)
87

88
    async with connectable.connect() as connection:
89
        await connection.run_sync(do_run_migrations)
90

91
    await connectable.dispose()
92

93

94
if context.is_offline_mode():
95
    run_migrations_offline()
96
else:
97
    asyncio.run(run_migrations_online())
98

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.