Added migrations to update command #114
This commit is contained in:
26
src/cpl_cli/migrations/__init__.py
Normal file
26
src/cpl_cli/migrations/__init__.py
Normal file
@@ -0,0 +1,26 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
cpl-cli sh-edraft Common Python library CLI
|
||||
~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
sh-edraft Common Python library Command Line Interface
|
||||
|
||||
:copyright: (c) 2020 - 2022 sh-edraft.de
|
||||
:license: MIT, see LICENSE for more details.
|
||||
|
||||
"""
|
||||
|
||||
__title__ = 'cpl_cli.migrations'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de'
|
||||
__version__ = '2022.10.11'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
|
||||
# imports
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major='2022', minor='10', micro='11')
|
26
src/cpl_cli/migrations/base/__init__.py
Normal file
26
src/cpl_cli/migrations/base/__init__.py
Normal file
@@ -0,0 +1,26 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
cpl-cli sh-edraft Common Python library CLI
|
||||
~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
sh-edraft Common Python library Command Line Interface
|
||||
|
||||
:copyright: (c) 2020 - 2022 sh-edraft.de
|
||||
:license: MIT, see LICENSE for more details.
|
||||
|
||||
"""
|
||||
|
||||
__title__ = 'cpl_cli.migrations.base'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de'
|
||||
__version__ = '2022.10.11'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
|
||||
# imports:
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major='2022', minor='10', micro='11')
|
15
src/cpl_cli/migrations/base/migration_abc.py
Normal file
15
src/cpl_cli/migrations/base/migration_abc.py
Normal file
@@ -0,0 +1,15 @@
|
||||
from abc import ABC, abstractmethod
|
||||
|
||||
|
||||
class MigrationABC(ABC):
|
||||
|
||||
@abstractmethod
|
||||
def __init__(self, version: str):
|
||||
self._version = version
|
||||
|
||||
@property
|
||||
def version(self) -> str:
|
||||
return self._version
|
||||
|
||||
@abstractmethod
|
||||
def migrate(self): pass
|
10
src/cpl_cli/migrations/base/migration_service_abc.py
Normal file
10
src/cpl_cli/migrations/base/migration_service_abc.py
Normal file
@@ -0,0 +1,10 @@
|
||||
from abc import ABC, abstractmethod
|
||||
|
||||
|
||||
class MigrationServiceABC(ABC):
|
||||
|
||||
@abstractmethod
|
||||
def __init__(self): pass
|
||||
|
||||
@abstractmethod
|
||||
def migrate_from(self, version: str): pass
|
11
src/cpl_cli/migrations/migration_2022_10.py
Normal file
11
src/cpl_cli/migrations/migration_2022_10.py
Normal file
@@ -0,0 +1,11 @@
|
||||
from cpl_cli.migrations.base.migration_abc import MigrationABC
|
||||
|
||||
|
||||
class Migration202210(MigrationABC):
|
||||
|
||||
def __init__(self):
|
||||
MigrationABC.__init__(self, '2022.10')
|
||||
|
||||
def migrate(self):
|
||||
# This migration could be deleted, but stays as an example.
|
||||
pass
|
26
src/cpl_cli/migrations/service/__init__.py
Normal file
26
src/cpl_cli/migrations/service/__init__.py
Normal file
@@ -0,0 +1,26 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
cpl-cli sh-edraft Common Python library CLI
|
||||
~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
sh-edraft Common Python library Command Line Interface
|
||||
|
||||
:copyright: (c) 2020 - 2022 sh-edraft.de
|
||||
:license: MIT, see LICENSE for more details.
|
||||
|
||||
"""
|
||||
|
||||
__title__ = 'cpl_cli.migrations.service'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de'
|
||||
__version__ = '2022.10.11'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
|
||||
# imports:
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major='2022', minor='10', micro='11')
|
21
src/cpl_cli/migrations/service/migration_service.py
Normal file
21
src/cpl_cli/migrations/service/migration_service.py
Normal file
@@ -0,0 +1,21 @@
|
||||
from packaging import version
|
||||
|
||||
from cpl_cli.migrations.base.migration_abc import MigrationABC
|
||||
from cpl_cli.migrations.base.migration_service_abc import MigrationServiceABC
|
||||
from cpl_core.dependency_injection import ServiceProviderABC
|
||||
|
||||
|
||||
class MigrationService(MigrationServiceABC):
|
||||
|
||||
def __init__(self, services: ServiceProviderABC):
|
||||
MigrationServiceABC.__init__(self)
|
||||
|
||||
self._services = services
|
||||
|
||||
def migrate_from(self, _v: str):
|
||||
for migration_type in MigrationABC.__subclasses__():
|
||||
migration: MigrationABC = self._services.get_service(migration_type)
|
||||
if version.parse(migration.version) <= version.parse(_v):
|
||||
continue
|
||||
|
||||
migration.migrate()
|
Reference in New Issue
Block a user