Files
breakpilot-lehrer/school-service/internal/database/parent_migrations.go
T
Benjamin Admin 85957ed5db
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 36s
CI / test-go-edu-search (push) Successful in 33s
CI / test-python-klausur (push) Failing after 2m45s
CI / test-python-agent-core (push) Successful in 23s
CI / test-nodejs-website (push) Successful in 27s
gofmt parent backend files
2026-05-22 11:52:51 +02:00

54 lines
2.1 KiB
Go

package database
// ParentMigrations creates the four parent-side tables for Phase 9c:
//
// parent_account — one row per invited parent (email, language)
// parent_child — kids linked to a parent and a tt_class
// parent_magic_link — one-shot invite tokens, hashed
// parent_session — active browser sessions after redeeming a link
//
// The teacher owns the invite (created_by_user_id on account); parent sees
// only data scoped to their own children's class via tt_class.id.
func ParentMigrations() []string {
return []string{
`CREATE TABLE IF NOT EXISTS parent_account (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
created_by_user_id UUID NOT NULL,
email VARCHAR(255) NOT NULL,
preferred_language VARCHAR(8) DEFAULT 'de',
created_at TIMESTAMPTZ DEFAULT NOW(),
UNIQUE(created_by_user_id, email)
)`,
`CREATE TABLE IF NOT EXISTS parent_child (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
parent_id UUID NOT NULL REFERENCES parent_account(id) ON DELETE CASCADE,
tt_class_id UUID NOT NULL REFERENCES tt_class(id) ON DELETE CASCADE,
first_name VARCHAR(100) NOT NULL,
last_name VARCHAR(100) NOT NULL,
created_at TIMESTAMPTZ DEFAULT NOW()
)`,
`CREATE TABLE IF NOT EXISTS parent_magic_link (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
parent_id UUID NOT NULL REFERENCES parent_account(id) ON DELETE CASCADE,
token_hash VARCHAR(64) NOT NULL UNIQUE,
expires_at TIMESTAMPTZ NOT NULL,
used_at TIMESTAMPTZ,
created_at TIMESTAMPTZ DEFAULT NOW()
)`,
`CREATE TABLE IF NOT EXISTS parent_session (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
parent_id UUID NOT NULL REFERENCES parent_account(id) ON DELETE CASCADE,
token_hash VARCHAR(64) NOT NULL UNIQUE,
expires_at TIMESTAMPTZ NOT NULL,
created_at TIMESTAMPTZ DEFAULT NOW()
)`,
`CREATE INDEX IF NOT EXISTS idx_parent_account_owner ON parent_account(created_by_user_id)`,
`CREATE INDEX IF NOT EXISTS idx_parent_child_parent ON parent_child(parent_id)`,
`CREATE INDEX IF NOT EXISTS idx_parent_child_class ON parent_child(tt_class_id)`,
}
}