Files
huntingclubroster/migrations/002_roster.sql
T
jric11 1e63076123
Security and workflow regressions / regression (push) Has been cancelled
Chat's updates for security, db and workflow
2026-10-20 06:45:30 -04:00

51 lines
2.6 KiB
SQL

CREATE TABLE IF NOT EXISTS clubs (
club_serial BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
club_name VARCHAR(128) NOT NULL,
club_status ENUM('active','archived') NOT NULL DEFAULT 'active',
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
UNIQUE KEY (club_name)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE IF NOT EXISTS club_memberships (
membership_serial BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
club_serial BIGINT UNSIGNED NOT NULL,
user_serial BIGINT UNSIGNED NOT NULL,
membership_status ENUM('active','inactive') NOT NULL DEFAULT 'active',
joined_on DATE NOT NULL,
UNIQUE KEY (club_serial,user_serial),
UNIQUE KEY (membership_serial,club_serial),
FOREIGN KEY (club_serial) REFERENCES clubs(club_serial) ON DELETE RESTRICT,
FOREIGN KEY (user_serial) REFERENCES users(user_serial) ON DELETE RESTRICT
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE IF NOT EXISTS club_seasons (
season_serial BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
club_serial BIGINT UNSIGNED NOT NULL,
season_name VARCHAR(100) NOT NULL,
starts_on DATE NOT NULL,
ends_on DATE NOT NULL,
UNIQUE KEY (club_serial,season_name),
UNIQUE KEY (season_serial,club_serial),
FOREIGN KEY (club_serial) REFERENCES clubs(club_serial) ON DELETE RESTRICT,
CHECK (ends_on>=starts_on)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE IF NOT EXISTS club_dues (
due_serial BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
club_serial BIGINT UNSIGNED NOT NULL,
membership_serial BIGINT UNSIGNED NOT NULL,
season_serial BIGINT UNSIGNED NOT NULL,
amount_cents BIGINT UNSIGNED NOT NULL,
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
UNIQUE KEY (membership_serial,season_serial),
FOREIGN KEY (membership_serial,club_serial) REFERENCES club_memberships(membership_serial,club_serial) ON DELETE RESTRICT,
FOREIGN KEY (season_serial,club_serial) REFERENCES club_seasons(season_serial,club_serial) ON DELETE RESTRICT
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE IF NOT EXISTS club_payments (
payment_serial BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
due_serial BIGINT UNSIGNED NOT NULL,
amount_cents BIGINT UNSIGNED NOT NULL,
paid_on DATE NOT NULL,
request_key CHAR(64) CHARACTER SET ascii COLLATE ascii_bin NOT NULL UNIQUE,
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (due_serial) REFERENCES club_dues(due_serial) ON DELETE RESTRICT,
CHECK (amount_cents>0)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;