-- UTF-8 Encoding für deutsche Sonderzeichen sicherstellen SET client_encoding = 'UTF8'; CREATE TABLE IF NOT EXISTS customers ( id SERIAL PRIMARY KEY, name TEXT NOT NULL, email TEXT, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ); CREATE TABLE IF NOT EXISTS licenses ( id SERIAL PRIMARY KEY, license_key TEXT UNIQUE NOT NULL, customer_id INTEGER REFERENCES customers(id), license_type TEXT NOT NULL, valid_from DATE NOT NULL, valid_until DATE NOT NULL, is_active BOOLEAN DEFAULT TRUE ); CREATE TABLE IF NOT EXISTS sessions ( id SERIAL PRIMARY KEY, license_id INTEGER REFERENCES licenses(id), session_id TEXT UNIQUE NOT NULL, ip_address TEXT, user_agent TEXT, started_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, last_heartbeat TIMESTAMP DEFAULT CURRENT_TIMESTAMP, ended_at TIMESTAMP, is_active BOOLEAN DEFAULT TRUE ); -- Audit-Log-Tabelle für Änderungsprotokolle CREATE TABLE IF NOT EXISTS audit_log ( id SERIAL PRIMARY KEY, timestamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP, username TEXT NOT NULL, action TEXT NOT NULL, entity_type TEXT NOT NULL, entity_id INTEGER, old_values JSONB, new_values JSONB, ip_address TEXT, user_agent TEXT, additional_info TEXT ); -- Index für bessere Performance bei Abfragen CREATE INDEX idx_audit_log_timestamp ON audit_log(timestamp DESC); CREATE INDEX idx_audit_log_username ON audit_log(username); CREATE INDEX idx_audit_log_entity ON audit_log(entity_type, entity_id);