Files
radio-free-elsewhere/sql/schema.sql
T
2026-10-30 08:37:10 -05:00

66 lines
3.0 KiB
SQL

-- Radio Free Elsewhere database schema.
-- Apply with: mysql -u <user> -p <database> < sql/schema.sql
-- All DATETIME values are stored in UTC (includes/db.php sets the session time zone).
CREATE TABLE IF NOT EXISTS shows (
id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
slug VARCHAR(64) NOT NULL UNIQUE,
name VARCHAR(255) NOT NULL,
-- Filename in images/backgrounds/ used as the live.php header background; NULL keeps the default
background_image VARCHAR(255) NULL,
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
-- One row per streaming session.
-- Pending (queued by cli/set_show.php): started_at IS NULL
-- Live: started_at set, ended_at IS NULL
-- Ended: ended_at set
CREATE TABLE IF NOT EXISTS broadcasts (
id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
show_id INT UNSIGNED NULL,
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
started_at DATETIME NULL,
last_seen_at DATETIME NULL,
ended_at DATETIME NULL,
INDEX (started_at),
INDEX (ended_at),
FOREIGN KEY (show_id) REFERENCES shows (id) ON DELETE SET NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
-- Tracks are cleared ten minutes after their broadcast ends.
CREATE TABLE IF NOT EXISTS played_tracks (
id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
broadcast_id INT UNSIGNED NOT NULL,
played_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
title VARCHAR(255) NOT NULL,
artist VARCHAR(255) NOT NULL DEFAULT '',
album VARCHAR(255) NOT NULL DEFAULT '',
art_url VARCHAR(512) NOT NULL DEFAULT '',
INDEX (broadcast_id, played_at),
FOREIGN KEY (broadcast_id) REFERENCES broadcasts (id) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
-- Admin accounts are created and reset from the command line with cli/create_admin.php
CREATE TABLE IF NOT EXISTS admins (
id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
username VARCHAR(64) NOT NULL UNIQUE,
password_hash VARCHAR(255) NOT NULL,
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
last_login_at DATETIME NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
-- Failed admin logins, used to throttle password guessing
CREATE TABLE IF NOT EXISTS login_attempts (
id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
ip_address VARCHAR(45) NOT NULL,
attempted_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
INDEX (ip_address, attempted_at)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
INSERT IGNORE INTO shows (slug, name) VALUES
('omorains-pub', 'O''Morain''s Pub'),
('cosmoeuphoria', 'Cosmoeuphoria'),
('bisexual-surfers', 'Bisexual Surfers From the Twilight of Time'),
('the-bollocks', 'The Bollocks'),
('the-spin', 'The Spin');