-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapply_next_build_schema.py
More file actions
70 lines (56 loc) · 2.17 KB
/
Copy pathapply_next_build_schema.py
File metadata and controls
70 lines (56 loc) · 2.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/env python3
"""Apply next build reports database schema"""
import mysql.connector
import os
def apply_schema():
try:
# Connect to database
connection = mysql.connector.connect(
host='localhost',
user='root',
password='G`/C#Pi"5uqHNrZ@r<pT',
database='lfs_builds'
)
cursor = connection.cursor()
# Read schema file
schema_path = 'src/database/next_build_reports_schema.sql'
with open(schema_path, 'r') as f:
schema_sql = f.read()
# Split and execute statements
statements = schema_sql.split(';')
for statement in statements:
statement = statement.strip()
if statement and not statement.startswith('--'):
try:
cursor.execute(statement)
print(f"✅ Executed: {statement[:50]}...")
except mysql.connector.Error as e:
if "already exists" in str(e):
print(f"⚠️ Already exists: {statement[:50]}...")
else:
print(f"❌ Error: {e}")
print(f"Statement: {statement}")
connection.commit()
cursor.close()
connection.close()
print("\n✅ Next build reports schema applied successfully!")
# Test the tables
connection = mysql.connector.connect(
host='localhost',
user='root',
password='G`/C#Pi"5uqHNrZ@r<pT',
database='lfs_builds'
)
cursor = connection.cursor()
cursor.execute("SHOW TABLES LIKE 'next_build_reports'")
if cursor.fetchone():
print("✅ next_build_reports table created successfully")
cursor.execute("SHOW TABLES LIKE 'report_access_log'")
if cursor.fetchone():
print("✅ report_access_log table created successfully")
cursor.close()
connection.close()
except Exception as e:
print(f"❌ Failed to apply schema: {e}")
if __name__ == "__main__":
apply_schema()