@@ -35,82 +35,75 @@ def get_database_url() -> str:
3535def run_migration (db ) -> None :
3636 """
3737 Run database migrations.
38-
38+
3939 This creates all required tables if they don't exist.
4040 """
4141 print (f"[{ datetime .now ().isoformat ()} ] Starting database migration..." )
42-
42+
4343 # Import database module
4444 from quantumpytho .modules .database import init_schema
45-
45+
4646 # Run schema initialization
4747 init_schema (db )
48-
48+
4949 print (f"[{ datetime .now ().isoformat ()} ] Migration completed successfully!" )
5050
5151
5252def check_migration_status (db ) -> None :
5353 """Check current migration status."""
5454 print (f"[{ datetime .now ().isoformat ()} ] Checking migration status..." )
55-
55+
5656 # Check if tables exist
57- tables = [
58- 'quantum_jobs' ,
59- 'vqe_results' ,
60- 'user_sessions' ,
61- 'api_logs'
62- ]
63-
57+ tables = ["quantum_jobs" , "vqe_results" , "user_sessions" , "api_logs" ]
58+
6459 for table in tables :
6560 result = db .fetch_one (
6661 "SELECT EXISTS (SELECT 1 FROM information_schema.tables WHERE table_name = %s)" ,
67- (table ,)
62+ (table ,),
6863 )
69- exists = result .get (' exists' , False ) if result else False
64+ exists = result .get (" exists" , False ) if result else False
7065 status = "✅" if exists else "❌"
7166 print (f" { status } { table } " )
72-
67+
7368 print (f"[{ datetime .now ().isoformat ()} ] Status check complete!" )
7469
7570
7671def rollback_migration (db ) -> None :
7772 """Rollback last migration (use with caution!)."""
7873 print (f"[{ datetime .now ().isoformat ()} ] WARNING: Rolling back migrations..." )
7974 print (" This will DROP all tables!" )
80-
75+
8176 confirm = input (" Are you sure? Type 'YES' to confirm: " )
8277 if confirm != "YES" :
8378 print (" Rollback cancelled." )
8479 return
85-
80+
8681 # Drop all tables
87- tables = [' api_logs' , ' user_sessions' , ' vqe_results' , ' quantum_jobs' ]
88-
82+ tables = [" api_logs" , " user_sessions" , " vqe_results" , " quantum_jobs" ]
83+
8984 for table in tables :
9085 try :
9186 db .execute (f"DROP TABLE IF EXISTS { table } CASCADE" )
9287 print (f" ✅ Dropped table: { table } " )
9388 except Exception as e :
9489 print (f" ❌ Failed to drop { table } : { e } " )
95-
90+
9691 print (f"[{ datetime .now ().isoformat ()} ] Rollback complete!" )
9792
9893
9994def main ():
10095 """Main entry point."""
10196 parser = argparse .ArgumentParser (description = "QPyth Database Migrations" )
10297 parser .add_argument (
103- "--check" ,
104- action = "store_true" ,
105- help = "Check current migration status"
98+ "--check" , action = "store_true" , help = "Check current migration status"
10699 )
107100 parser .add_argument (
108101 "--rollback" ,
109102 action = "store_true" ,
110- help = "Rollback last migration (DROPS all tables)"
103+ help = "Rollback last migration (DROPS all tables)" ,
111104 )
112105 args = parser .parse_args ()
113-
106+
114107 # Get database URL
115108 try :
116109 database_url = get_database_url ()
@@ -122,30 +115,31 @@ def main():
122115 print ("\n Or create a .env file with:" )
123116 print (" DATABASE_URL=postgresql://..." )
124117 sys .exit (1 )
125-
118+
126119 # Import and connect
127120 try :
128121 from quantumpytho .modules .database import DatabaseConfig , NeonDatabase
129-
122+
130123 config = DatabaseConfig (database_url = database_url )
131124 db = NeonDatabase (config )
132-
133- print (f "✅ Connected to database" )
134-
125+
126+ print ("✅ Connected to database" )
127+
135128 # Run appropriate command
136129 if args .rollback :
137130 rollback_migration (db )
138131 elif args .check :
139132 check_migration_status (db )
140133 else :
141134 run_migration (db )
142-
135+
143136 # Close connection
144137 db .close ()
145-
138+
146139 except Exception as e :
147140 print (f"❌ Migration failed: { e } " )
148141 import traceback
142+
149143 traceback .print_exc ()
150144 sys .exit (1 )
151145
0 commit comments