改用element
增加acme多配置
This commit is contained in:
@@ -24,4 +24,35 @@ async def get_db():
|
||||
|
||||
async def init_db():
|
||||
async with engine.begin() as conn:
|
||||
# 迁移旧表:acme_config → acme_configs
|
||||
try:
|
||||
result = await conn.execute(
|
||||
__import__("sqlalchemy").text("SELECT name FROM sqlite_master WHERE type='table' AND name='acme_config'")
|
||||
)
|
||||
if result.fetchone():
|
||||
await conn.execute(__import__("sqlalchemy").text("ALTER TABLE acme_config RENAME TO acme_configs"))
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
await conn.run_sync(Base.metadata.create_all)
|
||||
|
||||
# 迁移:给 domains 表加 acme_config_id 列
|
||||
try:
|
||||
await conn.execute(
|
||||
__import__("sqlalchemy").text("ALTER TABLE domains ADD COLUMN acme_config_id INTEGER REFERENCES acme_configs(id)")
|
||||
)
|
||||
except Exception:
|
||||
pass # 列已存在
|
||||
|
||||
# 确保至少有一条默认配置
|
||||
result = await conn.execute(
|
||||
__import__("sqlalchemy").text("SELECT COUNT(*) FROM acme_configs")
|
||||
)
|
||||
count = result.scalar()
|
||||
if count == 0:
|
||||
await conn.execute(
|
||||
__import__("sqlalchemy").text(
|
||||
"INSERT INTO acme_configs (name, acme_server, email, dns_provider, dns_credentials, renew_days) "
|
||||
"VALUES ('默认配置', 'https://acme-v02.api.letsencrypt.org/directory', '', 'aliyun', '{}', 30)"
|
||||
)
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user