mirror of https://github.com/Aidaho12/haproxy-wi
v8.2.0: Fix string interpolation in migration error messages
Standardize the use of formatted strings (f-strings) for error messages across all migration scripts to ensure correctness and consistency. Added missing blank lines across files to comply with PEP 8 style guidelines and improve code readability.pull/424/head
parent
bc2fe10485
commit
c20f3f8ee9
|
|
@ -10,6 +10,7 @@ SectionModel = {
|
||||||
'nginx': NginxSection,
|
'nginx': NginxSection,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def update_saved_server(server, description, saved_id):
|
def update_saved_server(server, description, saved_id):
|
||||||
try:
|
try:
|
||||||
SavedServer.update(server=server, description=description).where(SavedServer.id == saved_id).execute()
|
SavedServer.update(server=server, description=description).where(SavedServer.id == saved_id).execute()
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '../.
|
||||||
|
|
||||||
from app.modules.db.migration_manager import create_migrations_table, migrate, rollback, create_migration, list_migrations
|
from app.modules.db.migration_manager import create_migrations_table, migrate, rollback, create_migration, list_migrations
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
parser = argparse.ArgumentParser(description='Database migration tool')
|
parser = argparse.ArgumentParser(description='Database migration tool')
|
||||||
subparsers = parser.add_subparsers(dest='command', help='Command to run')
|
subparsers = parser.add_subparsers(dest='command', help='Command to run')
|
||||||
|
|
@ -17,14 +18,14 @@ def main():
|
||||||
create_parser.add_argument('name', help='Name of the migration')
|
create_parser.add_argument('name', help='Name of the migration')
|
||||||
|
|
||||||
# Migrate command
|
# Migrate command
|
||||||
migrate_parser = subparsers.add_parser('migrate', help='Apply pending migrations')
|
subparsers.add_parser('migrate', help='Apply pending migrations')
|
||||||
|
|
||||||
# Rollback command
|
# Rollback command
|
||||||
rollback_parser = subparsers.add_parser('rollback', help='Rollback migrations')
|
rollback_parser = subparsers.add_parser('rollback', help='Rollback migrations')
|
||||||
rollback_parser.add_argument('--steps', type=int, default=1, help='Number of migrations to roll back')
|
rollback_parser.add_argument('--steps', type=int, default=1, help='Number of migrations to roll back')
|
||||||
|
|
||||||
# Initialize command
|
# Initialize command
|
||||||
init_parser = subparsers.add_parser('init', help='Initialize the migrations table')
|
subparsers.add_parser('init', help='Initialize the migrations table')
|
||||||
|
|
||||||
# list command
|
# list command
|
||||||
subparsers.add_parser('list', help='List all migrations and their status')
|
subparsers.add_parser('list', help='List all migrations and their status')
|
||||||
|
|
|
||||||
|
|
@ -17,11 +17,13 @@ class Migration(BaseModel):
|
||||||
class Meta:
|
class Meta:
|
||||||
table_name = 'migrations'
|
table_name = 'migrations'
|
||||||
|
|
||||||
|
|
||||||
def create_migrations_table():
|
def create_migrations_table():
|
||||||
"""Create the migrations table if it doesn't exist."""
|
"""Create the migrations table if it doesn't exist."""
|
||||||
conn = connect()
|
conn = connect()
|
||||||
conn.create_tables([Migration], safe=True)
|
conn.create_tables([Migration], safe=True)
|
||||||
|
|
||||||
|
|
||||||
def get_migration_files():
|
def get_migration_files():
|
||||||
"""Get all migration files from the migrations directory."""
|
"""Get all migration files from the migrations directory."""
|
||||||
migrations_dir = os.path.join(os.path.dirname(__file__), 'migrations')
|
migrations_dir = os.path.join(os.path.dirname(__file__), 'migrations')
|
||||||
|
|
@ -36,10 +38,12 @@ def get_migration_files():
|
||||||
migration_files.sort()
|
migration_files.sort()
|
||||||
return migration_files
|
return migration_files
|
||||||
|
|
||||||
|
|
||||||
def get_applied_migrations():
|
def get_applied_migrations():
|
||||||
"""Get all migrations that have been applied."""
|
"""Get all migrations that have been applied."""
|
||||||
return [m.name for m in Migration.select(Migration.name)]
|
return [m.name for m in Migration.select(Migration.name)]
|
||||||
|
|
||||||
|
|
||||||
def apply_migration(migration_name):
|
def apply_migration(migration_name):
|
||||||
"""Apply a single migration."""
|
"""Apply a single migration."""
|
||||||
try:
|
try:
|
||||||
|
|
@ -55,9 +59,10 @@ def apply_migration(migration_name):
|
||||||
print(f"Migration applied: {migration_name}")
|
print(f"Migration applied: {migration_name}")
|
||||||
return True
|
return True
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print("error: applying migration {migration_name}: {str(e)}")
|
print(f"error: applying migration {migration_name}: {str(e)}")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
def rollback_migration(migration_name):
|
def rollback_migration(migration_name):
|
||||||
"""Rollback a single migration."""
|
"""Rollback a single migration."""
|
||||||
try:
|
try:
|
||||||
|
|
@ -73,9 +78,10 @@ def rollback_migration(migration_name):
|
||||||
print(f"Migration rolled back: {migration_name}")
|
print(f"Migration rolled back: {migration_name}")
|
||||||
return True
|
return True
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print("error: rolling back migration {migration_name}: {str(e)}")
|
print(f"error: rolling back migration {migration_name}: {str(e)}")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
def migrate():
|
def migrate():
|
||||||
"""Apply all pending migrations."""
|
"""Apply all pending migrations."""
|
||||||
create_migrations_table()
|
create_migrations_table()
|
||||||
|
|
@ -100,6 +106,7 @@ def migrate():
|
||||||
|
|
||||||
return success
|
return success
|
||||||
|
|
||||||
|
|
||||||
def rollback(steps=1):
|
def rollback(steps=1):
|
||||||
"""Rollback the specified number of migrations."""
|
"""Rollback the specified number of migrations."""
|
||||||
create_migrations_table()
|
create_migrations_table()
|
||||||
|
|
@ -123,6 +130,7 @@ def rollback(steps=1):
|
||||||
|
|
||||||
return success
|
return success
|
||||||
|
|
||||||
|
|
||||||
def create_migration(name):
|
def create_migration(name):
|
||||||
"""Create a new migration file."""
|
"""Create a new migration file."""
|
||||||
timestamp = datetime.now().strftime('%Y%m%d%H%M%S')
|
timestamp = datetime.now().strftime('%Y%m%d%H%M%S')
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ from app.modules.db.db_model import connect, Version
|
||||||
|
|
||||||
migrator = connect(get_migrator=1)
|
migrator = connect(get_migrator=1)
|
||||||
|
|
||||||
|
|
||||||
def up():
|
def up():
|
||||||
"""Apply the migration."""
|
"""Apply the migration."""
|
||||||
# Insert version record with version '1.0'
|
# Insert version record with version '1.0'
|
||||||
|
|
@ -12,6 +13,7 @@ def up():
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"Error inserting version record: {e}")
|
print(f"Error inserting version record: {e}")
|
||||||
|
|
||||||
|
|
||||||
def down():
|
def down():
|
||||||
"""Roll back the migration."""
|
"""Roll back the migration."""
|
||||||
# This is the initial migration, so rolling back would mean dropping all tables
|
# This is the initial migration, so rolling back would mean dropping all tables
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ from app.modules.db.db_model import connect, User, UserGroups
|
||||||
|
|
||||||
migrator = connect(get_migrator=1)
|
migrator = connect(get_migrator=1)
|
||||||
|
|
||||||
|
|
||||||
def up():
|
def up():
|
||||||
"""Apply the migration."""
|
"""Apply the migration."""
|
||||||
# This migration updates user groups
|
# This migration updates user groups
|
||||||
|
|
@ -17,6 +18,7 @@ def up():
|
||||||
else:
|
else:
|
||||||
raise e
|
raise e
|
||||||
|
|
||||||
|
|
||||||
def down():
|
def down():
|
||||||
"""Roll back the migration."""
|
"""Roll back the migration."""
|
||||||
# This migration adds data, not schema changes, so rolling back would mean deleting data
|
# This migration adds data, not schema changes, so rolling back would mean deleting data
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ from peewee import IntegerField, SQL
|
||||||
|
|
||||||
migrator = connect(get_migrator=1)
|
migrator = connect(get_migrator=1)
|
||||||
|
|
||||||
|
|
||||||
def up():
|
def up():
|
||||||
"""Apply the migration."""
|
"""Apply the migration."""
|
||||||
# This migration adds a use_src column to the ha_cluster_vips table
|
# This migration adds a use_src column to the ha_cluster_vips table
|
||||||
|
|
@ -22,6 +23,7 @@ def up():
|
||||||
else:
|
else:
|
||||||
raise e
|
raise e
|
||||||
|
|
||||||
|
|
||||||
def down():
|
def down():
|
||||||
"""Roll back the migration."""
|
"""Roll back the migration."""
|
||||||
# This migration removes the use_src column from the ha_cluster_vips table
|
# This migration removes the use_src column from the ha_cluster_vips table
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ from app.modules.db.db_model import connect
|
||||||
|
|
||||||
migrator = connect(get_migrator=1)
|
migrator = connect(get_migrator=1)
|
||||||
|
|
||||||
|
|
||||||
def up():
|
def up():
|
||||||
"""Apply the migration."""
|
"""Apply the migration."""
|
||||||
# This migration renames columns in the backups table
|
# This migration renames columns in the backups table
|
||||||
|
|
@ -19,6 +20,7 @@ def up():
|
||||||
else:
|
else:
|
||||||
raise e
|
raise e
|
||||||
|
|
||||||
|
|
||||||
def down():
|
def down():
|
||||||
"""Roll back the migration."""
|
"""Roll back the migration."""
|
||||||
# This migration renames columns back to their original names
|
# This migration renames columns back to their original names
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ from app.modules.db.db_model import connect
|
||||||
|
|
||||||
migrator = connect(get_migrator=1)
|
migrator = connect(get_migrator=1)
|
||||||
|
|
||||||
|
|
||||||
def up():
|
def up():
|
||||||
"""Apply the migration."""
|
"""Apply the migration."""
|
||||||
# This migration renames multiple columns across different tables
|
# This migration renames multiple columns across different tables
|
||||||
|
|
@ -36,6 +37,7 @@ def up():
|
||||||
else:
|
else:
|
||||||
raise e
|
raise e
|
||||||
|
|
||||||
|
|
||||||
def down():
|
def down():
|
||||||
"""Roll back the migration."""
|
"""Roll back the migration."""
|
||||||
# This migration renames columns back to their original names
|
# This migration renames columns back to their original names
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ from peewee import IntegerField, SQL
|
||||||
|
|
||||||
migrator = connect(get_migrator=1)
|
migrator = connect(get_migrator=1)
|
||||||
|
|
||||||
|
|
||||||
def up():
|
def up():
|
||||||
"""Apply the migration."""
|
"""Apply the migration."""
|
||||||
# This migration adds a shared column to the cred table
|
# This migration adds a shared column to the cred table
|
||||||
|
|
@ -22,6 +23,7 @@ def up():
|
||||||
else:
|
else:
|
||||||
raise e
|
raise e
|
||||||
|
|
||||||
|
|
||||||
def down():
|
def down():
|
||||||
"""Roll back the migration."""
|
"""Roll back the migration."""
|
||||||
# This migration removes the shared column from the cred table
|
# This migration removes the shared column from the cred table
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ from app.modules.db.db_model import connect, RoxyTool
|
||||||
|
|
||||||
migrator = connect(get_migrator=1)
|
migrator = connect(get_migrator=1)
|
||||||
|
|
||||||
|
|
||||||
def up():
|
def up():
|
||||||
"""Apply the migration."""
|
"""Apply the migration."""
|
||||||
# This migration deletes rows from the RoxyTool table
|
# This migration deletes rows from the RoxyTool table
|
||||||
|
|
@ -13,6 +14,7 @@ def up():
|
||||||
print(f"Error applying migration: {str(e)}")
|
print(f"Error applying migration: {str(e)}")
|
||||||
raise e
|
raise e
|
||||||
|
|
||||||
|
|
||||||
def down():
|
def down():
|
||||||
"""Roll back the migration."""
|
"""Roll back the migration."""
|
||||||
# This migration adds back the deleted rows to the RoxyTool table
|
# This migration adds back the deleted rows to the RoxyTool table
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ from app.modules.db.db_model import connect
|
||||||
|
|
||||||
migrator = connect(get_migrator=1)
|
migrator = connect(get_migrator=1)
|
||||||
|
|
||||||
|
|
||||||
def up():
|
def up():
|
||||||
"""Apply the migration."""
|
"""Apply the migration."""
|
||||||
# This migration renames the server column to server_id in the backups table
|
# This migration renames the server column to server_id in the backups table
|
||||||
|
|
@ -18,6 +19,7 @@ def up():
|
||||||
else:
|
else:
|
||||||
raise e
|
raise e
|
||||||
|
|
||||||
|
|
||||||
def down():
|
def down():
|
||||||
"""Roll back the migration."""
|
"""Roll back the migration."""
|
||||||
# This migration renames the server_id column back to server in the backups table
|
# This migration renames the server_id column back to server in the backups table
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ from app.modules.db.db_model import connect
|
||||||
|
|
||||||
migrator = connect(get_migrator=1)
|
migrator = connect(get_migrator=1)
|
||||||
|
|
||||||
|
|
||||||
def up():
|
def up():
|
||||||
"""Apply the migration."""
|
"""Apply the migration."""
|
||||||
# This migration renames the server column to server_id in the s3_backups table
|
# This migration renames the server column to server_id in the s3_backups table
|
||||||
|
|
@ -18,6 +19,7 @@ def up():
|
||||||
else:
|
else:
|
||||||
raise e
|
raise e
|
||||||
|
|
||||||
|
|
||||||
def down():
|
def down():
|
||||||
"""Roll back the migration."""
|
"""Roll back the migration."""
|
||||||
# This migration renames the server_id column back to server in the s3_backups table
|
# This migration renames the server_id column back to server in the s3_backups table
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ from app.modules.db.db_model import connect
|
||||||
|
|
||||||
migrator = connect(get_migrator=1)
|
migrator = connect(get_migrator=1)
|
||||||
|
|
||||||
|
|
||||||
def up():
|
def up():
|
||||||
"""Apply the migration."""
|
"""Apply the migration."""
|
||||||
# This migration renames the rhost column to rserver in the backups table
|
# This migration renames the rhost column to rserver in the backups table
|
||||||
|
|
@ -18,6 +19,7 @@ def up():
|
||||||
else:
|
else:
|
||||||
raise e
|
raise e
|
||||||
|
|
||||||
|
|
||||||
def down():
|
def down():
|
||||||
"""Roll back the migration."""
|
"""Roll back the migration."""
|
||||||
# This migration renames the rserver column back to rhost in the backups table
|
# This migration renames the rserver column back to rhost in the backups table
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ from app.modules.db.db_model import connect
|
||||||
|
|
||||||
migrator = connect(get_migrator=1)
|
migrator = connect(get_migrator=1)
|
||||||
|
|
||||||
|
|
||||||
def up():
|
def up():
|
||||||
"""Apply the migration."""
|
"""Apply the migration."""
|
||||||
# This migration renames the period column to time in the git_setting table
|
# This migration renames the period column to time in the git_setting table
|
||||||
|
|
@ -18,6 +19,7 @@ def up():
|
||||||
else:
|
else:
|
||||||
raise e
|
raise e
|
||||||
|
|
||||||
|
|
||||||
def down():
|
def down():
|
||||||
"""Roll back the migration."""
|
"""Roll back the migration."""
|
||||||
# This migration renames the time column back to period in the git_setting table
|
# This migration renames the time column back to period in the git_setting table
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ from app.modules.db.db_model import connect
|
||||||
|
|
||||||
migrator = connect(get_migrator=1)
|
migrator = connect(get_migrator=1)
|
||||||
|
|
||||||
|
|
||||||
def up():
|
def up():
|
||||||
"""Apply the migration."""
|
"""Apply the migration."""
|
||||||
# This migration renames the group column to group_id in the settings table
|
# This migration renames the group column to group_id in the settings table
|
||||||
|
|
@ -18,6 +19,7 @@ def up():
|
||||||
else:
|
else:
|
||||||
raise e
|
raise e
|
||||||
|
|
||||||
|
|
||||||
def down():
|
def down():
|
||||||
"""Roll back the migration."""
|
"""Roll back the migration."""
|
||||||
# This migration renames the group_id column back to group in the settings table
|
# This migration renames the group_id column back to group in the settings table
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ from app.modules.db.db_model import connect, TextField
|
||||||
|
|
||||||
migrator = connect(get_migrator=1)
|
migrator = connect(get_migrator=1)
|
||||||
|
|
||||||
|
|
||||||
def up():
|
def up():
|
||||||
"""Apply the migration."""
|
"""Apply the migration."""
|
||||||
# This migration adds a private_key column to the cred table
|
# This migration adds a private_key column to the cred table
|
||||||
|
|
@ -17,6 +18,7 @@ def up():
|
||||||
else:
|
else:
|
||||||
raise e
|
raise e
|
||||||
|
|
||||||
|
|
||||||
def down():
|
def down():
|
||||||
"""Roll back the migration."""
|
"""Roll back the migration."""
|
||||||
# This migration removes the private_key column from the cred table
|
# This migration removes the private_key column from the cred table
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ from peewee import IntegerField, SQL
|
||||||
|
|
||||||
migrator = connect(get_migrator=1)
|
migrator = connect(get_migrator=1)
|
||||||
|
|
||||||
|
|
||||||
def up():
|
def up():
|
||||||
"""Apply the migration."""
|
"""Apply the migration."""
|
||||||
# This migration adds an is_checker column to the udp_balancers table
|
# This migration adds an is_checker column to the udp_balancers table
|
||||||
|
|
@ -23,6 +24,7 @@ def up():
|
||||||
else:
|
else:
|
||||||
raise e
|
raise e
|
||||||
|
|
||||||
|
|
||||||
def down():
|
def down():
|
||||||
"""Roll back the migration."""
|
"""Roll back the migration."""
|
||||||
# This migration removes the is_checker column from the udp_balancers table
|
# This migration removes the is_checker column from the udp_balancers table
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ from app.modules.db.db_model import connect, Version
|
||||||
|
|
||||||
migrator = connect(get_migrator=1)
|
migrator = connect(get_migrator=1)
|
||||||
|
|
||||||
|
|
||||||
def up():
|
def up():
|
||||||
"""Apply the migration."""
|
"""Apply the migration."""
|
||||||
# This migration updates the version in the database to 8.2.0
|
# This migration updates the version in the database to 8.2.0
|
||||||
|
|
@ -12,6 +13,7 @@ def up():
|
||||||
print(f"Error updating version: {str(e)}")
|
print(f"Error updating version: {str(e)}")
|
||||||
raise e
|
raise e
|
||||||
|
|
||||||
|
|
||||||
def down():
|
def down():
|
||||||
"""Roll back the migration."""
|
"""Roll back the migration."""
|
||||||
# This migration sets the version back to 8.1.6
|
# This migration sets the version back to 8.1.6
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue