mirror of https://gitlab.com/KKlochko/tui-rsync
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
28 lines
700 B
28 lines
700 B
from typing import List
|
|
from peewee import Model, Database
|
|
from .models import BackupPlanModel, DestinationModel
|
|
from tui_rsync.core.ports.orm import DatabaseManagerPort
|
|
|
|
|
|
class DatabaseManager(DatabaseManagerPort):
|
|
models: List[Model] = [
|
|
BackupPlanModel,
|
|
DestinationModel,
|
|
]
|
|
|
|
def __init__(self, db: Database):
|
|
self.db = db
|
|
self._update_model_meta()
|
|
self.create_tables()
|
|
|
|
def _update_model_meta(self):
|
|
for model in self.models:
|
|
model._meta.database = self.db
|
|
|
|
def get_connection(self):
|
|
return self.db
|
|
|
|
def create_tables(self):
|
|
with self.db:
|
|
self.db.create_tables(self.models, safe=True)
|