added database
This commit is contained in:
BIN
Binary file not shown.
@@ -0,0 +1,85 @@
|
||||
import sqlite3
|
||||
|
||||
DB_NAME = "calendar.db"
|
||||
|
||||
conn = sqlite3.connect(DB_NAME)
|
||||
cur = conn.cursor()
|
||||
|
||||
cur.execute("""
|
||||
CREATE TABLE IF NOT EXISTS users (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
username TEXT NOT NULL UNIQUE,
|
||||
password_hash TEXT NOT NULL
|
||||
);
|
||||
""")
|
||||
|
||||
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,
|
||||
|
||||
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',
|
||||
|
||||
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
|
||||
);
|
||||
""")
|
||||
|
||||
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')),
|
||||
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')),
|
||||
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)
|
||||
);
|
||||
""")
|
||||
|
||||
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),
|
||||
|
||||
FOREIGN KEY (event_id) REFERENCES events(id) ON DELETE CASCADE,
|
||||
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
|
||||
);
|
||||
""")
|
||||
|
||||
conn.commit()
|
||||
|
||||
print("Database aangemaakt.")
|
||||
print("Tabellen:")
|
||||
for row in cur.execute("SELECT name FROM sqlite_master WHERE type='table' ORDER BY name;"):
|
||||
print(" -", row[0])
|
||||
|
||||
conn.close()
|
||||
Reference in New Issue
Block a user