09f6f5a5e1
CI / go-lint (push) Has been skipped
CI / python-lint (push) Has been skipped
CI / nodejs-lint (push) Has been skipped
CI / test-go-school (push) Successful in 29s
CI / test-go-edu-search (push) Successful in 29s
CI / test-python-klausur (push) Failing after 2m25s
CI / test-python-agent-core (push) Successful in 19s
CI / test-nodejs-website (push) Successful in 21s
70 lines
2.6 KiB
Go
70 lines
2.6 KiB
Go
package database
|
|
|
|
// CalendarMigrations creates the three calendar tables for Phase 9a:
|
|
//
|
|
// cal_public_event — read-only snapshot of school holidays + public
|
|
// holidays from OpenHolidaysAPI. Imported on first
|
|
// boot via seed/calendar_holidays.json.
|
|
// cal_school_config — per-Rektor bundesland selection (1 row per user).
|
|
// cal_school_event — user-managed school events (Fortbildung,
|
|
// Schulfeier, Klassenfahrt etc.).
|
|
//
|
|
// cal_public_event is global (no created_by_user_id) because the data is the
|
|
// same for every school in a given bundesland. School-events are
|
|
// per-tenant.
|
|
func CalendarMigrations() []string {
|
|
return []string{
|
|
`CREATE TABLE IF NOT EXISTS cal_public_event (
|
|
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
|
region VARCHAR(8) NOT NULL,
|
|
event_type VARCHAR(20) NOT NULL CHECK (event_type IN ('public_holiday', 'school_holiday')),
|
|
name_de VARCHAR(255) NOT NULL,
|
|
name_en VARCHAR(255),
|
|
start_date DATE NOT NULL,
|
|
end_date DATE NOT NULL,
|
|
source VARCHAR(50) DEFAULT 'OpenHolidaysAPI',
|
|
created_at TIMESTAMPTZ DEFAULT NOW(),
|
|
UNIQUE(region, event_type, name_de, start_date),
|
|
CHECK (end_date >= start_date)
|
|
)`,
|
|
|
|
`CREATE TABLE IF NOT EXISTS cal_school_config (
|
|
user_id UUID PRIMARY KEY,
|
|
bundesland VARCHAR(8) NOT NULL,
|
|
school_year_start DATE,
|
|
school_year_end DATE,
|
|
created_at TIMESTAMPTZ DEFAULT NOW(),
|
|
updated_at TIMESTAMPTZ DEFAULT NOW()
|
|
)`,
|
|
|
|
`CREATE TABLE IF NOT EXISTS cal_school_event (
|
|
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
|
created_by_user_id UUID NOT NULL,
|
|
title VARCHAR(255) NOT NULL,
|
|
description TEXT,
|
|
event_type VARCHAR(30) NOT NULL
|
|
CHECK (event_type IN ('fortbildung','schulfeier','klassenfahrt','projekttag','eltern_info','andere')),
|
|
is_school_free BOOLEAN DEFAULT false,
|
|
start_date DATE NOT NULL,
|
|
end_date DATE NOT NULL,
|
|
start_time TIME,
|
|
end_time TIME,
|
|
affected_class_ids UUID[] DEFAULT '{}',
|
|
visible_to_parents BOOLEAN DEFAULT true,
|
|
notify_parents BOOLEAN DEFAULT false,
|
|
notify_students BOOLEAN DEFAULT false,
|
|
notification_lead_days INT[] DEFAULT '{7,1}',
|
|
created_at TIMESTAMPTZ DEFAULT NOW(),
|
|
updated_at TIMESTAMPTZ DEFAULT NOW(),
|
|
CHECK (end_date >= start_date)
|
|
)`,
|
|
|
|
// Indexes — public events are queried by region + date range. School
|
|
// events are queried by owner + date range.
|
|
`CREATE INDEX IF NOT EXISTS idx_cal_public_event_region_date
|
|
ON cal_public_event(region, start_date, end_date)`,
|
|
`CREATE INDEX IF NOT EXISTS idx_cal_school_event_user_date
|
|
ON cal_school_event(created_by_user_id, start_date, end_date)`,
|
|
}
|
|
}
|