File indexing completed on 2026-04-09 07:58:19
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012 from logging.config import fileConfig
0013
0014 from sqlalchemy import engine_from_config
0015 from sqlalchemy import pool
0016
0017 from alembic import context
0018
0019
0020 from idds.orm.base.session import BASE
0021
0022
0023
0024 config = context.config
0025
0026
0027
0028 if config.config_file_name is not None:
0029 fileConfig(config.config_file_name)
0030
0031
0032
0033
0034
0035
0036 target_metadata = BASE.metadata
0037
0038
0039
0040
0041
0042
0043
0044 def run_migrations_offline() -> None:
0045 """Run migrations in 'offline' mode.
0046
0047 This configures the context with just a URL
0048 and not an Engine, though an Engine is acceptable
0049 here as well. By skipping the Engine creation
0050 we don't even need a DBAPI to be available.
0051
0052 Calls to context.execute() here emit the given string to the
0053 script output.
0054
0055 """
0056 url = config.get_main_option("sqlalchemy.url")
0057
0058 version_table_schema = config.get_main_option("version_table_schema")
0059
0060 context.configure(
0061 url=url,
0062 version_table_schema=version_table_schema,
0063 target_metadata=target_metadata,
0064 literal_binds=True,
0065 dialect_opts={"paramstyle": "named"},
0066 include_schemas=True
0067 )
0068
0069 with context.begin_transaction():
0070 context.run_migrations()
0071
0072
0073 def run_migrations_online() -> None:
0074 """Run migrations in 'online' mode.
0075
0076 In this scenario we need to create an Engine
0077 and associate a connection with the context.
0078
0079 """
0080 connectable = engine_from_config(
0081 config.get_section(config.config_ini_section),
0082 prefix="sqlalchemy.",
0083 poolclass=pool.NullPool,
0084 )
0085
0086 with connectable.connect() as connection:
0087 context.configure(
0088 connection=connection, target_metadata=target_metadata,
0089 version_table_schema=config.get_main_option("version_table_schema"),
0090 include_schemas=True
0091 )
0092
0093 with context.begin_transaction():
0094 context.run_migrations()
0095
0096
0097 if context.is_offline_mode():
0098 run_migrations_offline()
0099 else:
0100 run_migrations_online()