update many files

This commit is contained in:
ben
2026-08-03 16:21:10 +02:00
parent 9e69edc08b
commit cff9aa0dd1
5 changed files with 220 additions and 110 deletions
+60 -12
View File
@@ -3,8 +3,13 @@ import sqlite3
DB_NAME = "calendar.db"
conn = sqlite3.connect(DB_NAME)
# SQLite foreign keys activeren
conn.execute("PRAGMA foreign_keys = ON;")
cur = conn.cursor()
cur.execute("""
CREATE TABLE IF NOT EXISTS users (
id INTEGER PRIMARY KEY AUTOINCREMENT,
@@ -13,73 +18,116 @@ CREATE TABLE IF NOT EXISTS users (
);
""")
cur.execute("""
CREATE TABLE IF NOT EXISTS rooms (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT NOT NULL,
owner_id INTEGER NOT NULL,
invite_code TEXT UNIQUE,
invite_code TEXT NOT NULL UNIQUE,
FOREIGN KEY (owner_id) REFERENCES users(id)
);
""")
cur.execute("""
CREATE TABLE IF NOT EXISTS room_members (
room_id INTEGER NOT NULL,
user_id INTEGER NOT NULL,
role TEXT NOT NULL DEFAULT 'member',
role TEXT NOT NULL DEFAULT 'member'
CHECK(role IN ('owner', 'admin', 'member')),
PRIMARY KEY (room_id, user_id),
FOREIGN KEY (room_id) REFERENCES rooms(id) ON DELETE CASCADE,
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
FOREIGN KEY (room_id)
REFERENCES rooms(id)
ON DELETE CASCADE,
FOREIGN KEY (user_id)
REFERENCES users(id)
ON DELETE CASCADE
);
""")
cur.execute("""
CREATE TABLE IF NOT EXISTS events (
id INTEGER PRIMARY KEY AUTOINCREMENT,
room_id INTEGER NOT NULL,
creator_id INTEGER NOT NULL,
type TEXT NOT NULL CHECK(type IN ('private', 'busy', 'proposal')),
type TEXT NOT NULL
CHECK(type IN ('private', 'busy', 'proposal')),
title TEXT NOT NULL,
description TEXT,
start_time TEXT NOT NULL,
end_time TEXT NOT NULL,
visibility TEXT NOT NULL CHECK(visibility IN ('private', 'busy_only', 'room')),
visibility TEXT NOT NULL
CHECK(visibility IN ('private', 'busy_only', 'room')),
status TEXT NOT NULL DEFAULT 'draft'
CHECK(status IN ('draft', 'proposed', 'confirmed', 'cancelled')),
min_people INTEGER DEFAULT 0,
FOREIGN KEY (room_id) REFERENCES rooms(id) ON DELETE CASCADE,
FOREIGN KEY (creator_id) REFERENCES users(id)
FOREIGN KEY (room_id)
REFERENCES rooms(id)
ON DELETE CASCADE,
FOREIGN KEY (creator_id)
REFERENCES users(id)
);
""")
cur.execute("""
CREATE TABLE IF NOT EXISTS event_signups (
event_id INTEGER NOT NULL,
user_id INTEGER NOT NULL,
status TEXT NOT NULL DEFAULT 'going'
CHECK(status IN ('going', 'maybe', 'declined')),
PRIMARY KEY (event_id, user_id),
PRIMARY KEY(event_id, user_id),
FOREIGN KEY (event_id) REFERENCES events(id) ON DELETE CASCADE,
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
FOREIGN KEY(event_id)
REFERENCES events(id)
ON DELETE CASCADE,
FOREIGN KEY(user_id)
REFERENCES users(id)
ON DELETE CASCADE
);
""")
# Snellere zoekopdrachten
cur.execute("""
CREATE INDEX IF NOT EXISTS idx_room_members_user
ON room_members(user_id);
""")
cur.execute("""
CREATE INDEX IF NOT EXISTS idx_events_room
ON events(room_id);
""")
conn.commit()
print("Database aangemaakt.")
print("Tabellen:")
for row in cur.execute("SELECT name FROM sqlite_master WHERE type='table' ORDER BY name;"):
for row in cur.execute(
"SELECT name FROM sqlite_master WHERE type='table' ORDER BY name;"
):
print(" -", row[0])
conn.close()