#!/bin/python3 import sqlite3 from pathlib import Path DB_NAME = Path(__file__).parent / "calendar.db" try: conn = sqlite3.connect(DB_NAME) conn.execute("PRAGMA foreign_keys = ON;") cur = conn.cursor() cur.execute(""" CREATE TABLE IF NOT EXISTS room_invitations ( id INTEGER PRIMARY KEY AUTOINCREMENT, room_id INTEGER NOT NULL, email TEXT NOT NULL, token_hash TEXT NOT NULL UNIQUE, expires_at TEXT NOT NULL, created_at TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP, accepted_at TEXT, FOREIGN KEY (room_id) REFERENCES rooms(id) ON DELETE CASCADE ); """) cur.execute(""" CREATE INDEX IF NOT EXISTS idx_room_invitations_token ON room_invitations(token_hash); """) cur.execute(""" CREATE INDEX IF NOT EXISTS idx_room_invitations_room ON room_invitations(room_id); """) conn.commit() conn.close() print("Database updated.") except sqlite3.Error as e: print(f"Database error: {e}") try: conn.rollback() conn.close() except (NameError, sqlite3.Error): pass raise SystemExit(1) except Exception as e: print(f"Error: {e}") try: conn.rollback() conn.close() except (NameError, sqlite3.Error): pass raise SystemExit(1)