Files
proostenkrant.net/deploy/mysql/init.sql
T

92 lines
3.0 KiB
SQL
Executable File

-- ProostenKrant Database Schema
-- Dutch Family Newspaper System
CREATE DATABASE IF NOT EXISTS proostenkrant;
USE proostenkrant;
-- Users table (family members)
CREATE TABLE IF NOT EXISTS users (
id INT AUTO_INCREMENT PRIMARY KEY,
username VARCHAR(50) NOT NULL UNIQUE,
display_name VARCHAR(100) NOT NULL,
profile_image VARCHAR(255),
is_active BOOLEAN DEFAULT TRUE,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
);
-- Seasons table
CREATE TABLE IF NOT EXISTS seasons (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(50) NOT NULL,
description TEXT,
start_date DATE NOT NULL,
end_date DATE NOT NULL,
is_active BOOLEAN DEFAULT TRUE,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
-- Articles table
CREATE TABLE IF NOT EXISTS articles (
id INT AUTO_INCREMENT PRIMARY KEY,
title VARCHAR(255) NOT NULL,
content TEXT NOT NULL,
author_id INT NOT NULL,
participants TEXT, -- Comma-separated list of user IDs
event_date DATE NOT NULL,
season_id INT,
article_image VARCHAR(255),
status ENUM('draft', 'published', 'archived') DEFAULT 'draft',
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
FOREIGN KEY (author_id) REFERENCES users(id) ON DELETE CASCADE,
FOREIGN KEY (season_id) REFERENCES seasons(id) ON DELETE SET NULL
);
-- System settings table
CREATE TABLE IF NOT EXISTS settings (
id INT AUTO_INCREMENT PRIMARY KEY,
key_name VARCHAR(100) NOT NULL UNIQUE,
value TEXT,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
);
-- Insert default seasons
INSERT INTO seasons (name, description, start_date, end_date) VALUES
('Lente', 'Lente editie - Voorjaar', '2026-03-20', '2026-06-20'),
('Zomer', 'Zomer editie', '2026-06-21', '2026-09-22'),
('Herfst', 'Herfst editie', '2026-09-23', '2026-12-20'),
('Winter', 'Winter editie', '2026-12-21', '2026-03-19');
-- Insert default users (family members)
INSERT INTO users (username, display_name, profile_image) VALUES
('douwe', 'Douwe', NULL),
('pauline', 'Pauline', NULL),
('diede', 'Diede', NULL),
('dien', 'Dien', NULL),
('chris', 'Chris', NULL),
('geert', 'Geert', NULL),
('annick', 'Annick', NULL),
('cedric', 'Cedric', NULL),
('gunter', 'Gunter', NULL),
('daan', 'Daan', NULL),
('kyala', 'Kyala', NULL),
('michel', 'Michel', NULL),
('dries', 'Dries', NULL),
('pieter', 'Pieter', NULL),
('mathilde', 'Mathilde', NULL),
('kevin', 'Kevin', NULL),
('luc', 'Luc', NULL),
('tilde', 'Tilde', NULL),
('mattis', 'Mattis', NULL);
-- Insert universal password setting
INSERT INTO settings (key_name, value) VALUES
('universal_password', 'ProostenKrant2024!');
-- Create indexes for better performance
CREATE INDEX idx_articles_author ON articles(author_id);
CREATE INDEX idx_articles_season ON articles(season_id);
CREATE INDEX idx_articles_date ON articles(event_date);
CREATE INDEX idx_articles_status ON articles(status);