feat: draft version
This commit is contained in:
24
db_repo/versions/002_unique_repositories_index.py
Normal file
24
db_repo/versions/002_unique_repositories_index.py
Normal file
@@ -0,0 +1,24 @@
|
||||
from sqlalchemy import Table, MetaData, Index
|
||||
|
||||
meta = MetaData()
|
||||
|
||||
|
||||
def _get_indices(meta):
|
||||
meta.reflect()
|
||||
Users = Table("users", meta, autoload=True, autoload_with=meta.bind)
|
||||
Repositories = Table("users", meta, autoload=True, autoload_with=meta.bind)
|
||||
return [
|
||||
Index("repositories_name_unique_id", Users.c.id, Repositories.c.name, unique=True)
|
||||
]
|
||||
|
||||
|
||||
def upgrade(migrate_engine):
|
||||
meta.bind = migrate_engine
|
||||
for idx in _get_indices(meta):
|
||||
idx.create()
|
||||
|
||||
|
||||
def downgrade(migrate_engine):
|
||||
meta.bind = migrate_engine
|
||||
for idx in _get_indices(meta):
|
||||
idx.drop()
|
||||
Reference in New Issue
Block a user