fix: update logging messages for database operations and version bump
- Changed logging output for PostgreSQL readiness, schema loading, and migration status to a consistent format using [OK], [FAIL], and [WARN]. - Updated application version to 0.8.14 and modified changelog to reflect recent changes, including a fix for co-trainer backfill logic in the database migration. - Enhanced error handling messages for better clarity during migration processes.
This commit is contained in:
1 parent
0c044249d9
commit
e69aca51f6
6 files changed
+51
-36
No files matched your search
+16
-16
@@ -32,13 +32,13 @@ def wait_for_postgres(max_retries=30):
|
||||
try:
|
||||
conn = get_connection()
|
||||
conn.close()
|
||||
print("✓ PostgreSQL ready")
|
||||
print("[OK] PostgreSQL ready")
|
||||
return True
|
||||
except OperationalError:
|
||||
print(f" Waiting for PostgreSQL... (attempt {i}/{max_retries})")
|
||||
time.sleep(2)
|
||||
|
||||
print(f"✗ PostgreSQL not ready after {max_retries} attempts")
|
||||
print(f"[FAIL] PostgreSQL not ready after {max_retries} attempts")
|
||||
return False
|
||||
|
||||
def check_table_exists(table_name="profiles"):
|
||||
@@ -71,10 +71,10 @@ def load_schema(schema_file="/app/schema.sql"):
|
||||
conn.commit()
|
||||
cur.close()
|
||||
conn.close()
|
||||
print("✓ Schema loaded from schema.sql")
|
||||
print("[OK] Schema loaded from schema.sql")
|
||||
return True
|
||||
except Exception as e:
|
||||
print(f"✗ Error loading schema: {e}")
|
||||
print(f"[FAIL] Error loading schema: {e}")
|
||||
return False
|
||||
|
||||
def get_profile_count():
|
||||
@@ -146,10 +146,10 @@ def apply_migration(filepath, filename):
|
||||
conn.commit()
|
||||
cur.close()
|
||||
conn.close()
|
||||
print(f" ✓ Applied: {filename}")
|
||||
print(f" [OK] Applied: {filename}")
|
||||
return True
|
||||
except Exception as e:
|
||||
print(f" ✗ Failed to apply {filename}: {e}")
|
||||
print(f" [FAIL] Failed to apply {filename}: {e}")
|
||||
return False
|
||||
|
||||
def run_migrations(migrations_dir="/app/migrations"):
|
||||
@@ -158,7 +158,7 @@ def run_migrations(migrations_dir="/app/migrations"):
|
||||
import re
|
||||
|
||||
if not os.path.exists(migrations_dir):
|
||||
print("✓ No migrations directory found")
|
||||
print("[OK] No migrations directory found")
|
||||
return True
|
||||
|
||||
# Ensure migration tracking table exists
|
||||
@@ -174,7 +174,7 @@ def run_migrations(migrations_dir="/app/migrations"):
|
||||
migration_files = [f for f in all_files if migration_pattern.match(os.path.basename(f))]
|
||||
|
||||
if not migration_files:
|
||||
print("✓ No migration files found")
|
||||
print("[OK] No migration files found")
|
||||
return True
|
||||
|
||||
# Apply pending migrations
|
||||
@@ -185,7 +185,7 @@ def run_migrations(migrations_dir="/app/migrations"):
|
||||
pending.append((filepath, filename))
|
||||
|
||||
if not pending:
|
||||
print(f"✓ All {len(applied)} migrations already applied")
|
||||
print(f"[OK] All {len(applied)} migrations already applied")
|
||||
return True
|
||||
|
||||
print(f" Found {len(pending)} pending migration(s)...")
|
||||
@@ -211,12 +211,12 @@ if __name__ == "__main__":
|
||||
if not load_schema():
|
||||
sys.exit(1)
|
||||
else:
|
||||
print("✓ Schema already exists")
|
||||
print("[OK] Schema already exists")
|
||||
|
||||
# Run migrations
|
||||
print("\nRunning database migrations...")
|
||||
if not run_migrations():
|
||||
print("✗ Migration failed")
|
||||
print("[FAIL] Migration failed")
|
||||
sys.exit(1)
|
||||
|
||||
# Check for migration
|
||||
@@ -232,14 +232,14 @@ if __name__ == "__main__":
|
||||
from migrate_to_postgres import main as migrate
|
||||
migrate()
|
||||
except Exception as e:
|
||||
print(f"✗ Migration failed: {e}")
|
||||
print(f"[FAIL] Migration failed: {e}")
|
||||
sys.exit(1)
|
||||
elif os.path.exists(sqlite_db) and profile_count > 0:
|
||||
print(f"⚠ SQLite DB exists but PostgreSQL already has {profile_count} profiles")
|
||||
print(f"[WARN] SQLite DB exists but PostgreSQL already has {profile_count} profiles")
|
||||
print(" Skipping migration (already migrated)")
|
||||
elif not os.path.exists(sqlite_db):
|
||||
print("✓ No SQLite database found (fresh install or already migrated)")
|
||||
print("[OK] No SQLite database found (fresh install or already migrated)")
|
||||
else:
|
||||
print("✓ No migration needed")
|
||||
print("[OK] No migration needed")
|
||||
|
||||
print("\n✓ Database initialization complete")
|
||||
print("\n[OK] Database initialization complete")
|
||||
Reference in new issue
Block a user