mirror of
https://github.com/langbot-app/LangBot.git
synced 2026-06-02 03:55:55 +00:00
* style: remove necessary imports * style: fix F841 * style: fix F401 * style: fix F811 * style: fix E402 * style: fix E721 * style: fix E722 * style: fix E722 * style: fix F541 * style: ruff format * style: all passed * style: add ruff in deps * style: more ignores in ruff.toml * style: add pre-commit
41 lines
747 B
Python
41 lines
747 B
Python
from __future__ import annotations
|
|
|
|
import typing
|
|
import abc
|
|
|
|
from ..core import app
|
|
|
|
|
|
preregistered_db_migrations: list[typing.Type[DBMigration]] = []
|
|
|
|
|
|
def migration_class(number: int):
|
|
"""迁移类装饰器"""
|
|
|
|
def wrapper(cls: typing.Type[DBMigration]) -> typing.Type[DBMigration]:
|
|
cls.number = number
|
|
preregistered_db_migrations.append(cls)
|
|
return cls
|
|
|
|
return wrapper
|
|
|
|
|
|
class DBMigration(abc.ABC):
|
|
"""数据库迁移"""
|
|
|
|
number: int
|
|
"""迁移号"""
|
|
|
|
def __init__(self, ap: app.Application):
|
|
self.ap = ap
|
|
|
|
@abc.abstractmethod
|
|
async def upgrade(self):
|
|
"""升级"""
|
|
pass
|
|
|
|
@abc.abstractmethod
|
|
async def downgrade(self):
|
|
"""降级"""
|
|
pass
|