You've already forked haproxy-wi
mirror of
https://github.com/roxy-wi/roxy-wi.git
synced 2025-12-15 11:54:05 +08:00
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.
37 lines
1.2 KiB
Python
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 |