refac: switch to meta and params, remove source

This commit is contained in:
Jun Siang Cheah
2024-05-21 22:05:16 +01:00
parent 7ccef3e77a
commit f21c8626d6
12 changed files with 70 additions and 107 deletions

View File

@@ -1,3 +1,5 @@
import json
from peewee import *
from peewee_migrate import Router
from playhouse.db_url import connect
@@ -8,6 +10,16 @@ import logging
log = logging.getLogger(__name__)
log.setLevel(SRC_LOG_LEVELS["DB"])
class JSONField(TextField):
def db_value(self, value):
return json.dumps(value)
def python_value(self, value):
if value is not None:
return json.loads(value)
# Check if the file exists
if os.path.exists(f"{DATA_DIR}/ollama.db"):
# Rename the file

View File

@@ -1,4 +1,4 @@
"""Peewee migrations -- 008_add_models.py.
"""Peewee migrations -- 009_add_models.py.
Some examples (model - class or model name)::
@@ -39,20 +39,15 @@ def migrate(migrator: Migrator, database: pw.Database, *, fake=False):
@migrator.create_model
class Model(pw.Model):
id = pw.TextField()
source = pw.TextField()
base_model = pw.TextField(null=True)
id = pw.TextField(unique=True)
meta = pw.TextField()
base_model_id = pw.TextField(null=True)
name = pw.TextField()
params = pw.TextField()
class Meta:
table_name = "model"
indexes = (
# Create a unique index on the id, source columns
(("id", "source"), True),
)
def rollback(migrator: Migrator, database: pw.Database, *, fake=False):
"""Write your rollback migrations here."""