Add Alembic to project for database migrations
This commit is contained in:
parent
7755bfb46d
commit
7ce43a2bfe
15 changed files with 256 additions and 49 deletions
22
tofu_api/models/base.py
Normal file
22
tofu_api/models/base.py
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
from sqlalchemy import MetaData
|
||||
from sqlalchemy.orm import declarative_base
|
||||
|
||||
__all__ = [
|
||||
'metadata',
|
||||
'BaseModel',
|
||||
]
|
||||
|
||||
# Define naming convention for constraints
|
||||
_naming_convention = {
|
||||
"ix": 'ix_%(column_0_label)s',
|
||||
"uq": "uq_%(table_name)s_%(column_0_name)s",
|
||||
"ck": "ck_%(table_name)s_%(constraint_name)s",
|
||||
"fk": "fk_%(table_name)s_%(column_0_name)s_%(referred_table_name)s",
|
||||
"pk": "pk_%(table_name)s"
|
||||
}
|
||||
|
||||
# Create metadata object for database schemas
|
||||
metadata = MetaData(naming_convention=_naming_convention)
|
||||
|
||||
# Generate declarative base class for database models
|
||||
BaseModel = declarative_base(name='BaseModel', metadata=metadata)
|
||||
Loading…
Add table
Add a link
Reference in a new issue