Added migrations to update command #114

This commit is contained in:
2022-09-19 22:59:21 +02:00
parent df3f9f0306
commit c52bf961e1
55 changed files with 266 additions and 90 deletions

View 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')

View 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')

View 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

View 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

View 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

View 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')

View 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()