Skip to content

修复alembic迁移缺失数据 #29

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions alembic/env.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# ruff: noqa: E402
import asyncio
import os
from logging.config import fileConfig
Expand All @@ -24,12 +26,15 @@

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

target_metadata = MappedBase.metadata
target_metadata = [
AdminModel.metadata,
]

# other values from the config, defined by the needs of env.py,
from database.db_mysql import SQLALCHEMY_DATABASE_URL # noqa: E402
from database.db_mysql import SQLALCHEMY_DATABASE_URL

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

Expand All @@ -49,7 +54,7 @@ def run_migrations_offline():
url = config.get_main_option('sqlalchemy.url')
context.configure(
url=url,
target_metadata=target_metadata,
target_metadata=target_metadata, # type: ignore
literal_binds=True,
dialect_opts={'paramstyle': 'named'},
)
Expand All @@ -59,7 +64,7 @@ def run_migrations_offline():


def do_run_migrations(connection):
context.configure(connection=connection, target_metadata=target_metadata)
context.configure(connection=connection, target_metadata=target_metadata) # type: ignore

with context.begin_transaction():
context.run_migrations()
Expand Down
5 changes: 0 additions & 5 deletions app/admin/model/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
# 导入所有模型,并将 MappedBase 放在最前面, 以便 MappedBase 拥有它们
# imported by Alembic
"""

from common.msd.model import MappedBase
from app.admin.model.user import User