Skip to content

Commit ebeb86e

Browse files
authored
修复alembic迁移缺失数据 (#29)
1 parent 8dd681d commit ebeb86e

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

alembic/env.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
#!/usr/bin/env python3
12
# -*- coding: utf-8 -*-
3+
# ruff: noqa: E402
24
import asyncio
35
import os
46
from logging.config import fileConfig
@@ -24,12 +26,15 @@
2426

2527
# add your model's MetaData object here
2628
# for 'autogenerate' support
27-
from common.msd.model import MappedBase # noqa: E402
29+
# https://alembic.sqlalchemy.org/en/latest/autogenerate.html#autogenerating-multiple-metadata-collections
30+
from app.admin.model import MappedBase as AdminModel
2831

29-
target_metadata = MappedBase.metadata
32+
target_metadata = [
33+
AdminModel.metadata,
34+
]
3035

3136
# other values from the config, defined by the needs of env.py,
32-
from database.db_mysql import SQLALCHEMY_DATABASE_URL # noqa: E402
37+
from database.db_mysql import SQLALCHEMY_DATABASE_URL
3338

3439
config.set_main_option('sqlalchemy.url', SQLALCHEMY_DATABASE_URL)
3540

@@ -49,7 +54,7 @@ def run_migrations_offline():
4954
url = config.get_main_option('sqlalchemy.url')
5055
context.configure(
5156
url=url,
52-
target_metadata=target_metadata,
57+
target_metadata=target_metadata, # type: ignore
5358
literal_binds=True,
5459
dialect_opts={'paramstyle': 'named'},
5560
)
@@ -59,7 +64,7 @@ def run_migrations_offline():
5964

6065

6166
def do_run_migrations(connection):
62-
context.configure(connection=connection, target_metadata=target_metadata)
67+
context.configure(connection=connection, target_metadata=target_metadata) # type: ignore
6368

6469
with context.begin_transaction():
6570
context.run_migrations()

app/admin/model/__init__.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
11
#!/usr/bin/env python3
22
# -*- coding: utf-8 -*-
3-
"""
4-
# 导入所有模型,并将 MappedBase 放在最前面, 以便 MappedBase 拥有它们
5-
# imported by Alembic
6-
"""
7-
83
from common.msd.model import MappedBase
94
from app.admin.model.user import User

0 commit comments

Comments
 (0)