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.
master
Aidaho 2025-05-17 11:30:44 +03:00
parent bc2fe10485
commit c20f3f8ee9
18 changed files with 60 additions and 20 deletions

View File

@ -10,6 +10,7 @@ SectionModel = {
'nginx': NginxSection,
}
def update_saved_server(server, description, saved_id):
try:
SavedServer.update(server=server, description=description).where(SavedServer.id == saved_id).execute()

View File

@ -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
def main():
parser = argparse.ArgumentParser(description='Database migration tool')
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')
# Migrate command
migrate_parser = subparsers.add_parser('migrate', help='Apply pending migrations')
subparsers.add_parser('migrate', help='Apply pending migrations')
# Rollback command
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')
# Initialize command
init_parser = subparsers.add_parser('init', help='Initialize the migrations table')
subparsers.add_parser('init', help='Initialize the migrations table')
# list command
subparsers.add_parser('list', help='List all migrations and their status')

View File

@ -17,11 +17,13 @@ class Migration(BaseModel):
class Meta:
table_name = 'migrations'
def create_migrations_table():
"""Create the migrations table if it doesn't exist."""
conn = connect()
conn.create_tables([Migration], safe=True)
def get_migration_files():
"""Get all migration files from the migrations directory."""
migrations_dir = os.path.join(os.path.dirname(__file__), 'migrations')
@ -36,10 +38,12 @@ def get_migration_files():
migration_files.sort()
return migration_files
def get_applied_migrations():
"""Get all migrations that have been applied."""
return [m.name for m in Migration.select(Migration.name)]
def apply_migration(migration_name):
"""Apply a single migration."""
try:
@ -55,9 +59,10 @@ def apply_migration(migration_name):
print(f"Migration applied: {migration_name}")
return True
except Exception as e:
print("error: applying migration {migration_name}: {str(e)}")
print(f"error: applying migration {migration_name}: {str(e)}")
return False
def rollback_migration(migration_name):
"""Rollback a single migration."""
try:
@ -73,9 +78,10 @@ def rollback_migration(migration_name):
print(f"Migration rolled back: {migration_name}")
return True
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
def migrate():
"""Apply all pending migrations."""
create_migrations_table()
@ -100,6 +106,7 @@ def migrate():
return success
def rollback(steps=1):
"""Rollback the specified number of migrations."""
create_migrations_table()
@ -123,6 +130,7 @@ def rollback(steps=1):
return success
def create_migration(name):
"""Create a new migration file."""
timestamp = datetime.now().strftime('%Y%m%d%H%M%S')

View File

@ -3,6 +3,7 @@ from app.modules.db.db_model import connect, Version
migrator = connect(get_migrator=1)
def up():
"""Apply the migration."""
# Insert version record with version '1.0'
@ -12,6 +13,7 @@ def up():
except Exception as e:
print(f"Error inserting version record: {e}")
def down():
"""Roll back the migration."""
# This is the initial migration, so rolling back would mean dropping all tables

View File

@ -3,6 +3,7 @@ from app.modules.db.db_model import connect, User, UserGroups
migrator = connect(get_migrator=1)
def up():
"""Apply the migration."""
# This migration updates user groups
@ -17,6 +18,7 @@ def up():
else:
raise e
def down():
"""Roll back the migration."""
# This migration adds data, not schema changes, so rolling back would mean deleting data

View File

@ -4,6 +4,7 @@ from peewee import IntegerField, SQL
migrator = connect(get_migrator=1)
def up():
"""Apply the migration."""
# This migration adds a use_src column to the ha_cluster_vips table
@ -22,6 +23,7 @@ def up():
else:
raise e
def down():
"""Roll back the migration."""
# This migration removes the use_src column from the ha_cluster_vips table

View File

@ -3,6 +3,7 @@ from app.modules.db.db_model import connect
migrator = connect(get_migrator=1)
def up():
"""Apply the migration."""
# This migration renames columns in the backups table
@ -19,6 +20,7 @@ def up():
else:
raise e
def down():
"""Roll back the migration."""
# This migration renames columns back to their original names

View File

@ -3,6 +3,7 @@ from app.modules.db.db_model import connect
migrator = connect(get_migrator=1)
def up():
"""Apply the migration."""
# This migration renames multiple columns across different tables
@ -36,6 +37,7 @@ def up():
else:
raise e
def down():
"""Roll back the migration."""
# This migration renames columns back to their original names

View File

@ -4,6 +4,7 @@ from peewee import IntegerField, SQL
migrator = connect(get_migrator=1)
def up():
"""Apply the migration."""
# This migration adds a shared column to the cred table
@ -22,6 +23,7 @@ def up():
else:
raise e
def down():
"""Roll back the migration."""
# This migration removes the shared column from the cred table

View File

@ -3,6 +3,7 @@ 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
@ -13,6 +14,7 @@ def up():
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

View File

@ -3,6 +3,7 @@ from app.modules.db.db_model import connect
migrator = connect(get_migrator=1)
def up():
"""Apply the migration."""
# This migration renames the server column to server_id in the backups table
@ -18,6 +19,7 @@ def up():
else:
raise e
def down():
"""Roll back the migration."""
# This migration renames the server_id column back to server in the backups table

View File

@ -3,6 +3,7 @@ from app.modules.db.db_model import connect
migrator = connect(get_migrator=1)
def up():
"""Apply the migration."""
# This migration renames the server column to server_id in the s3_backups table
@ -18,6 +19,7 @@ def up():
else:
raise e
def down():
"""Roll back the migration."""
# This migration renames the server_id column back to server in the s3_backups table

View File

@ -3,6 +3,7 @@ from app.modules.db.db_model import connect
migrator = connect(get_migrator=1)
def up():
"""Apply the migration."""
# This migration renames the rhost column to rserver in the backups table
@ -18,6 +19,7 @@ def up():
else:
raise e
def down():
"""Roll back the migration."""
# This migration renames the rserver column back to rhost in the backups table

View File

@ -3,6 +3,7 @@ from app.modules.db.db_model import connect
migrator = connect(get_migrator=1)
def up():
"""Apply the migration."""
# This migration renames the period column to time in the git_setting table
@ -18,6 +19,7 @@ def up():
else:
raise e
def down():
"""Roll back the migration."""
# This migration renames the time column back to period in the git_setting table

View File

@ -3,6 +3,7 @@ from app.modules.db.db_model import connect
migrator = connect(get_migrator=1)
def up():
"""Apply the migration."""
# This migration renames the group column to group_id in the settings table
@ -18,6 +19,7 @@ def up():
else:
raise e
def down():
"""Roll back the migration."""
# This migration renames the group_id column back to group in the settings table

View File

@ -3,6 +3,7 @@ from app.modules.db.db_model import connect, TextField
migrator = connect(get_migrator=1)
def up():
"""Apply the migration."""
# This migration adds a private_key column to the cred table
@ -17,6 +18,7 @@ def up():
else:
raise e
def down():
"""Roll back the migration."""
# This migration removes the private_key column from the cred table

View File

@ -4,6 +4,7 @@ from peewee import IntegerField, SQL
migrator = connect(get_migrator=1)
def up():
"""Apply the migration."""
# This migration adds an is_checker column to the udp_balancers table
@ -23,6 +24,7 @@ def up():
else:
raise e
def down():
"""Roll back the migration."""
# This migration removes the is_checker column from the udp_balancers table

View File

@ -3,6 +3,7 @@ from app.modules.db.db_model import connect, Version
migrator = connect(get_migrator=1)
def up():
"""Apply the migration."""
# 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)}")
raise e
def down():
"""Roll back the migration."""
# This migration sets the version back to 8.1.6