mirror of
https://github.com/amtoaer/bili-sync.git
synced 2026-09-05 07:28:04 +08:00
chore: 存版本号并添加入口,方便触发版本间的迁移逻辑
This commit is contained in:
@@ -0,0 +1,14 @@
|
|||||||
|
from tortoise import BaseDBAsyncClient
|
||||||
|
|
||||||
|
|
||||||
|
async def upgrade(db: BaseDBAsyncClient) -> str:
|
||||||
|
return """
|
||||||
|
CREATE TABLE IF NOT EXISTS "program" (
|
||||||
|
"id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
|
||||||
|
"version" VARCHAR(20) NOT NULL
|
||||||
|
);"""
|
||||||
|
|
||||||
|
|
||||||
|
async def downgrade(db: BaseDBAsyncClient) -> str:
|
||||||
|
return """
|
||||||
|
DROP TABLE IF EXISTS "program";"""
|
||||||
@@ -14,6 +14,7 @@ from constants import (
|
|||||||
)
|
)
|
||||||
from settings import settings
|
from settings import settings
|
||||||
from utils import aopen
|
from utils import aopen
|
||||||
|
from version import VERSION
|
||||||
|
|
||||||
|
|
||||||
class FavoriteList(Model):
|
class FavoriteList(Model):
|
||||||
@@ -148,6 +149,11 @@ class FavoriteItem(Model):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class Program(Model):
|
||||||
|
id = fields.IntField(pk=True)
|
||||||
|
version = fields.CharField(max_length=20)
|
||||||
|
|
||||||
|
|
||||||
async def init_model() -> None:
|
async def init_model() -> None:
|
||||||
await Tortoise.init(config=TORTOISE_ORM)
|
await Tortoise.init(config=TORTOISE_ORM)
|
||||||
migrate_commands = (
|
migrate_commands = (
|
||||||
@@ -157,3 +163,13 @@ async def init_model() -> None:
|
|||||||
)
|
)
|
||||||
process = await create_subprocess_exec(*migrate_commands)
|
process = await create_subprocess_exec(*migrate_commands)
|
||||||
await process.communicate()
|
await process.communicate()
|
||||||
|
program, created = await Program.get_or_create(
|
||||||
|
defaults={
|
||||||
|
"version": VERSION,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
if created or program.version != VERSION:
|
||||||
|
# 把新版本的迁移逻辑写在这里
|
||||||
|
pass
|
||||||
|
program.version = VERSION
|
||||||
|
await program.save()
|
||||||
|
|||||||
Reference in New Issue
Block a user