改用element

增加acme多配置
This commit is contained in:
2026-07-18 23:17:53 +08:00
parent ca957385f2
commit 226f6a76dd
26 changed files with 1572 additions and 1922 deletions
+31
View File
@@ -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)"
)
)