mirror of
https://github.com/fastapiadmin/FastapiAdmin.git
synced 2026-09-20 20:39:55 +00:00
fix: 修复文件下载和删除功能 fix: 修复Redis哈希获取方法返回值类型 fix: 修复权限检查逻辑 perf: 优化部门和服务详情查询性能 perf: 优化角色数据范围显示 style: 清理无用导入和注释 style: 统一CRUD方法命名 docs: 更新main.py中的命令说明 chore: 移动IP定位工具类位置 chore: 更新.gitignore忽略迁移版本文件
94 lines
2.7 KiB
Python
94 lines
2.7 KiB
Python
import asyncio
|
|
from logging.config import fileConfig
|
|
from sqlalchemy.ext.asyncio import create_async_engine
|
|
from sqlalchemy import pool
|
|
from alembic import context
|
|
|
|
# this is the Alembic Config object, which provides
|
|
# access to the values within the .ini file in use.
|
|
config = context.config
|
|
|
|
# Interpret the config file for Python logging.
|
|
# This line sets up loggers basically.
|
|
if config.config_file_name is not None:
|
|
fileConfig(config.config_file_name)
|
|
|
|
# add your model's MetaData object here
|
|
# for 'autogenerate' support
|
|
# from myapp import mymodel
|
|
# target_metadata = mymodel.Base.metadata
|
|
from app.core.base_model import MappedBase
|
|
target_metadata = MappedBase.metadata
|
|
|
|
# other values from the config, defined by the needs of env.py,
|
|
# can be acquired:
|
|
# my_important_option = config.get_main_option("my_important_option")
|
|
# ... etc.
|
|
from app.config.setting import settings
|
|
config.set_main_option("sqlalchemy.url", settings.ASYNC_DB_URI)
|
|
|
|
|
|
def run_migrations_offline() -> None:
|
|
"""Run migrations in 'offline' mode.
|
|
|
|
This configures the context with just a URL
|
|
and not an Engine, though an Engine is acceptable
|
|
here as well. By skipping the Engine creation
|
|
we don't even need a DBAPI to be available.
|
|
|
|
Calls to context.execute() here emit the given string to the
|
|
script output.
|
|
|
|
"""
|
|
url = config.get_main_option("sqlalchemy.url")
|
|
# 确保URL不为None
|
|
if url is None:
|
|
raise ValueError("数据库URL未正确配置,请检查环境配置文件")
|
|
|
|
context.configure(
|
|
url=url,
|
|
target_metadata=target_metadata,
|
|
literal_binds=True,
|
|
dialect_opts={"paramstyle": "named"},
|
|
)
|
|
|
|
with context.begin_transaction():
|
|
context.run_migrations()
|
|
|
|
|
|
def run_migrations_online() -> None:
|
|
"""Run migrations in 'online' mode.
|
|
|
|
In this scenario we need to create an Engine
|
|
and associate a connection with the context.
|
|
|
|
"""
|
|
url = config.get_main_option("sqlalchemy.url")
|
|
# 确保URL不为None
|
|
if url is None:
|
|
raise ValueError("数据库URL未正确配置,请检查环境配置文件")
|
|
|
|
connectable = create_async_engine(url, poolclass=pool.NullPool)
|
|
|
|
async def run_async_migrations():
|
|
async with connectable.connect() as connection:
|
|
await connection.run_sync(do_run_migrations)
|
|
|
|
def do_run_migrations(connection):
|
|
context.configure(
|
|
connection=connection,
|
|
target_metadata=target_metadata,
|
|
compare_type=True,
|
|
compare_server_default=True,
|
|
)
|
|
|
|
with context.begin_transaction():
|
|
context.run_migrations()
|
|
|
|
asyncio.run(run_async_migrations())
|
|
|
|
|
|
if context.is_offline_mode():
|
|
run_migrations_offline()
|
|
else:
|
|
run_migrations_online() |