mirror of
https://github.com/asterisk/asterisk.git
synced 2025-09-20 03:59:01 +00:00
alembic: Add support for MS-SQL
MS-SQL has no native Enum-type support and therefore needs to work with constraints. Since these constraints need unique names the suggested approach referenced in the following alembic documentation has been applied: http://bit.ly/2x9r8pb ASTERISK-27255 #close Change-Id: I8b579750dae0c549f1103ee50172644afb9b2f95
This commit is contained in:
committed by
Kevin Harwell
parent
2857a3334a
commit
e9a81157ac
@@ -2,7 +2,8 @@ from __future__ import with_statement
|
||||
from alembic import context
|
||||
from alembic.script import ScriptDirectory
|
||||
from alembic.operations import Operations
|
||||
from sqlalchemy import engine_from_config, pool
|
||||
from sqlalchemy import engine_from_config, pool, MetaData
|
||||
from sqlalchemy.ext.declarative import declarative_base
|
||||
from logging.config import fileConfig
|
||||
import logging
|
||||
|
||||
@@ -17,12 +18,24 @@ try:
|
||||
except:
|
||||
pass
|
||||
|
||||
## below block is needed for mssql
|
||||
meta = MetaData(naming_convention = {
|
||||
"ix": 'ix_%(column_0_label)s',
|
||||
"uq": "uq_%(table_name)s_%(column_0_name)s",
|
||||
"ck": "ck_%(table_name)s_%(column_0_name)s_%(constraint_name)s",
|
||||
"fk": "fk_%(table_name)s_%(column_0_name)s_%(referred_table_name)s",
|
||||
"pk": "pk_%(table_name)s"
|
||||
})
|
||||
Base = declarative_base(metadata=meta)
|
||||
|
||||
logger = logging.getLogger('alembic.runtime.setup')
|
||||
# add your model's MetaData object here
|
||||
# for 'autogenerate' support
|
||||
# from myapp import mymodel
|
||||
# target_metadata = mymodel.Base.metadata
|
||||
target_metadata = None
|
||||
#Comment above line and uncomment below line for mssql
|
||||
#target_metadata = Base.metadata
|
||||
|
||||
# other values from the config, defined by the needs of env.py,
|
||||
# can be acquired:
|
||||
@@ -42,7 +55,7 @@ def run_migrations_offline():
|
||||
|
||||
"""
|
||||
url = config.get_main_option("sqlalchemy.url")
|
||||
context.configure(url=url)
|
||||
context.configure(url=url,target_metadata=target_metadata)
|
||||
|
||||
with context.begin_transaction():
|
||||
context.run_migrations()
|
||||
|
Reference in New Issue
Block a user