-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
105 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
from __future__ import annotations | ||
|
||
import abc | ||
import typing | ||
|
||
from ..core import app | ||
|
||
|
||
preregistered_migrations: list[typing.Type[Migration]] = [] | ||
"""当前阶段暂不支持扩展""" | ||
|
||
def migration_class(name: str, number: int): | ||
"""注册一个迁移 | ||
""" | ||
def decorator(cls: typing.Type[Migration]) -> typing.Type[Migration]: | ||
cls.name = name | ||
cls.number = number | ||
preregistered_migrations.append(cls) | ||
return cls | ||
|
||
return decorator | ||
|
||
|
||
class Migration(abc.ABC): | ||
"""一个版本的迁移 | ||
""" | ||
|
||
name: str | ||
|
||
number: int | ||
|
||
ap: app.Application | ||
|
||
def __init__(self, ap: app.Application): | ||
self.ap = ap | ||
|
||
@abc.abstractmethod | ||
async def need_migrate(self) -> bool: | ||
"""判断当前环境是否需要运行此迁移 | ||
""" | ||
pass | ||
|
||
@abc.abstractmethod | ||
async def run(self): | ||
"""执行迁移 | ||
""" | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
from .. import migration | ||
|
||
from ...core import app | ||
|
||
|
||
@migration.migration_class("001_cookies_refresh_config", 1) | ||
class Migration(migration.Migration): | ||
|
||
async def need_migrate(self) -> bool: | ||
return 'campux_qzone_cookies_refresh_strategy' not in self.ap.config.data | ||
|
||
async def migrate(self): | ||
self.ap.config.data['campux_qzone_cookies_refresh_strategy'] = 'qrcode' | ||
await self.ap.config.dump_config() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters