Files
Martinhal_Futebol_2026/init-db/01-init.sql
T
2026-09-13 20:20:06 +01:00

42 lines
2.0 KiB
SQL

-- Initialize database schema
-- This runs automatically when the PostgreSQL container starts for the first time
-- Create Settings table
CREATE TABLE IF NOT EXISTS "Settings" (
"id" TEXT NOT NULL DEFAULT 'main',
"apiKey" TEXT,
"selectedLeague" TEXT NOT NULL DEFAULT 'primeira_liga',
"leagueId" INTEGER NOT NULL DEFAULT 94,
"season" INTEGER NOT NULL DEFAULT 2024,
"siteName" TEXT NOT NULL DEFAULT 'Primeira Liga Stats',
"primaryColor" TEXT NOT NULL DEFAULT '#E42518',
"secondaryColor" TEXT NOT NULL DEFAULT '#006600',
"showLiveMatches" BOOLEAN NOT NULL DEFAULT true,
"showStandings" BOOLEAN NOT NULL DEFAULT true,
"showTopScorers" BOOLEAN NOT NULL DEFAULT true,
"showRecentResults" BOOLEAN NOT NULL DEFAULT true,
"showUpcoming" BOOLEAN NOT NULL DEFAULT true,
"refreshInterval" INTEGER NOT NULL DEFAULT 300,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
CONSTRAINT "Settings_pkey" PRIMARY KEY ("id")
);
-- Create ApiRequestLog table
CREATE TABLE IF NOT EXISTS "ApiRequestLog" (
"id" TEXT NOT NULL,
"endpoint" TEXT NOT NULL,
"status" INTEGER NOT NULL,
"duration" INTEGER NOT NULL,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
CONSTRAINT "ApiRequestLog_pkey" PRIMARY KEY ("id")
);
-- Create index for ApiRequestLog
CREATE INDEX IF NOT EXISTS "ApiRequestLog_createdAt_idx" ON "ApiRequestLog"("createdAt");
-- Insert default settings
INSERT INTO "Settings" ("id", "apiKey", "selectedLeague", "leagueId", "season", "siteName", "primaryColor", "secondaryColor", "showLiveMatches", "showStandings", "showTopScorers", "showRecentResults", "showUpcoming", "refreshInterval", "createdAt", "updatedAt")
VALUES ('main', '54a71050279ccaa37d29625c16f2ef70', 'primeira_liga', 94, 2024, 'Primeira Liga Stats', '#E42518', '#006600', true, true, true, true, true, 300, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP)
ON CONFLICT ("id") DO NOTHING;