Files
haproxy-wi/app/modules/db/migrations/20230101000006_delete_prometheus_tools.py
Aidaho b1bec4ec06 v8.2.0: Add database migration framework and initial migrations
Introduce migration management tools using Peewee's migrate module. Add scripts for migration creation, application, rollback, and listing. Include initial batch of database migrations for schema and data changes.
2025-05-17 08:51:50 +03:00

37 lines
1.2 KiB
Python

from playhouse.migrate import *
from app.modules.db.db_model import connect, RoxyTool
migrator = connect(get_migrator=1)
def up():
"""Apply the migration."""
# This migration deletes rows from the RoxyTool table
try:
RoxyTool.delete().where(RoxyTool.name == 'prometheus').execute()
RoxyTool.delete().where(RoxyTool.name == 'grafana-server').execute()
except Exception as e:
print(f"Error applying migration: {str(e)}")
raise e
def down():
"""Roll back the migration."""
# This migration adds back the deleted rows to the RoxyTool table
try:
RoxyTool.insert(
name='prometheus',
current_version='1.0',
new_version='1.0',
is_roxy=0,
desc='Prometheus monitoring system'
).on_conflict_ignore().execute()
RoxyTool.insert(
name='grafana-server',
current_version='1.0',
new_version='1.0',
is_roxy=0,
desc='Grafana visualization tool'
).on_conflict_ignore().execute()
except Exception as e:
print(f"Error rolling back migration: {str(e)}")
raise e