Skip to content

Commit e8b7e6a

Browse files
Update create_db.py
1 parent c7b8599 commit e8b7e6a

1 file changed

Lines changed: 28 additions & 8 deletions

File tree

.github/create_db.py

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,44 @@
11
import sqlite3
2+
import os
23

3-
conn = sqlite3.connect("sites.db")
4+
# Match the path used by your Flask app
5+
DB_NAME = os.path.join(os.path.dirname(os.path.abspath(__file__)), "sites.db")
6+
7+
conn = sqlite3.connect(DB_NAME)
48
conn.execute("""
59
CREATE TABLE IF NOT EXISTS sites (
6-
id INTEGER PRIMARY KEY,
7-
url TEXT,
8-
check_interval INTEGER,
10+
id INTEGER PRIMARY KEY AUTOINCREMENT,
11+
url TEXT NOT NULL,
12+
check_interval INTEGER DEFAULT 60,
913
expected_text TEXT,
10-
enabled INTEGER
14+
enabled INTEGER DEFAULT 1
1115
)
1216
""")
1317
conn.execute("""
1418
CREATE TABLE IF NOT EXISTS logs (
15-
id INTEGER PRIMARY KEY,
19+
id INTEGER PRIMARY KEY AUTOINCREMENT,
1620
site_id INTEGER,
1721
status INTEGER,
1822
response_time REAL,
19-
timestamp TEXT
23+
timestamp TEXT,
24+
FOREIGN KEY (site_id) REFERENCES sites (id)
2025
)
2126
""")
27+
28+
# Add column if missing (safe to run every time)
29+
try:
30+
conn.execute("ALTER TABLE sites ADD COLUMN check_interval INTEGER DEFAULT 60")
31+
except sqlite3.OperationalError:
32+
pass # Column already exists
33+
34+
try:
35+
conn.execute("ALTER TABLE sites ADD COLUMN enabled INTEGER DEFAULT 1")
36+
except sqlite3.OperationalError:
37+
pass
38+
2239
conn.commit()
2340
conn.close()
24-
print("✅ Test database created")
41+
42+
print(f"✅ Database created at: {DB_NAME}")
43+
print("Contents:")
44+
print(open(DB_NAME, "rb").read(100)) # Optional: debug binary output

0 commit comments

Comments
 (0)