App-template

Форк
0
78 строк · 2.1 Кб
1
from logging.config import fileConfig
2

3
from sqlalchemy import engine_from_config
4
from sqlalchemy import pool
5

6
from alembic import context
7

8
# this is the Alembic Config object, which provides
9
# access to the values within the .ini file in use.
10
config = context.config
11

12
# Interpret the config file for Python logging.
13
# This line sets up loggers basically.
14
if config.config_file_name is not None:
15
    fileConfig(config.config_file_name)
16

17
# add your model's MetaData object here
18
# for 'autogenerate' support
19
# from myapp import mymodel
20
# target_metadata = mymodel.Base.metadata
21
target_metadata = None
22

23
# other values from the config, defined by the needs of env.py,
24
# can be acquired:
25
# my_important_option = config.get_main_option("my_important_option")
26
# ... etc.
27

28

29
def run_migrations_offline() -> None:
30
    """Run migrations in 'offline' mode.
31

32
    This configures the context with just a URL
33
    and not an Engine, though an Engine is acceptable
34
    here as well.  By skipping the Engine creation
35
    we don't even need a DBAPI to be available.
36

37
    Calls to context.execute() here emit the given string to the
38
    script output.
39

40
    """
41
    url = config.get_main_option("sqlalchemy.url")
42
    context.configure(
43
        url=url,
44
        target_metadata=target_metadata,
45
        literal_binds=True,
46
        dialect_opts={"paramstyle": "named"},
47
    )
48

49
    with context.begin_transaction():
50
        context.run_migrations()
51

52

53
def run_migrations_online() -> None:
54
    """Run migrations in 'online' mode.
55

56
    In this scenario we need to create an Engine
57
    and associate a connection with the context.
58

59
    """
60
    connectable = engine_from_config(
61
        config.get_section(config.config_ini_section, {}),
62
        prefix="sqlalchemy.",
63
        poolclass=pool.NullPool,
64
    )
65

66
    with connectable.connect() as connection:
67
        context.configure(
68
            connection=connection, target_metadata=target_metadata
69
        )
70

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

74

75
if context.is_offline_mode():
76
    run_migrations_offline()
77
else:
78
    run_migrations_online()
79

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

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

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

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