feat(agenda): Epic 0 - Database schema for agenda module
- E0.S1: Add encounter_id and intake_id columns to reports table - E0.S2: Add performance indices for reports and encounters - E0.S3: Regenerate TypeScript types 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -1 +1 @@
|
||||
v2.58.5
|
||||
v2.62.10
|
||||
28
supabase/migrations/20251202_add_agenda_indices.sql
Normal file
28
supabase/migrations/20251202_add_agenda_indices.sql
Normal file
@@ -0,0 +1,28 @@
|
||||
-- ============================================================================
|
||||
-- Migration: Add performance indices for agenda module
|
||||
-- Epic: E0 - Database & Types
|
||||
-- Story: E0.S2 - Index toevoegen voor performance
|
||||
-- ============================================================================
|
||||
|
||||
-- Index for reports.encounter_id (find reports linked to an encounter)
|
||||
CREATE INDEX IF NOT EXISTS idx_reports_encounter ON reports(encounter_id)
|
||||
WHERE encounter_id IS NOT NULL AND deleted_at IS NULL;
|
||||
|
||||
-- Index for reports.intake_id (find reports linked to an intake)
|
||||
CREATE INDEX IF NOT EXISTS idx_reports_intake ON reports(intake_id)
|
||||
WHERE intake_id IS NOT NULL AND deleted_at IS NULL;
|
||||
|
||||
-- Index for encounters.period (date range queries for calendar views)
|
||||
CREATE INDEX IF NOT EXISTS idx_encounters_period ON encounters(period_start, period_end);
|
||||
|
||||
-- Index for encounters.practitioner (filter by behandelaar)
|
||||
CREATE INDEX IF NOT EXISTS idx_encounters_practitioner ON encounters(practitioner_id)
|
||||
WHERE practitioner_id IS NOT NULL;
|
||||
|
||||
-- ============================================================================
|
||||
-- Verification
|
||||
-- ============================================================================
|
||||
DO $$
|
||||
BEGIN
|
||||
RAISE NOTICE '✓ Migration E0.S2 completed - indices created';
|
||||
END $$;
|
||||
@@ -0,0 +1,52 @@
|
||||
-- ============================================================================
|
||||
-- Migration: Add encounter_id and intake_id columns to reports table
|
||||
-- Epic: E0 - Database & Types
|
||||
-- Story: E0.S1 - encounter_id toevoegen aan reports
|
||||
-- ============================================================================
|
||||
-- This migration adds bidirectional linking between reports and encounters/intakes
|
||||
-- allowing reports to be associated with specific appointments and intake sessions.
|
||||
-- ============================================================================
|
||||
|
||||
-- Add encounter_id column
|
||||
-- Links reports to specific encounters (appointments)
|
||||
ALTER TABLE reports
|
||||
ADD COLUMN IF NOT EXISTS encounter_id UUID REFERENCES encounters(id) ON DELETE SET NULL;
|
||||
|
||||
-- Add intake_id column
|
||||
-- Links reports to specific intake sessions
|
||||
ALTER TABLE reports
|
||||
ADD COLUMN IF NOT EXISTS intake_id UUID REFERENCES intakes(id) ON DELETE SET NULL;
|
||||
|
||||
-- Add comments for documentation
|
||||
COMMENT ON COLUMN reports.encounter_id IS 'Link report to specific encounter/appointment (FHIR Encounter reference)';
|
||||
COMMENT ON COLUMN reports.intake_id IS 'Link report to specific intake session';
|
||||
|
||||
-- ============================================================================
|
||||
-- Verification
|
||||
-- ============================================================================
|
||||
DO $$
|
||||
BEGIN
|
||||
-- Check encounter_id column exists
|
||||
IF EXISTS (
|
||||
SELECT 1 FROM information_schema.columns
|
||||
WHERE table_name = 'reports' AND column_name = 'encounter_id'
|
||||
) THEN
|
||||
RAISE NOTICE '✓ encounter_id column added to reports table';
|
||||
ELSE
|
||||
RAISE EXCEPTION 'encounter_id column not found in reports table';
|
||||
END IF;
|
||||
|
||||
-- Check intake_id column exists
|
||||
IF EXISTS (
|
||||
SELECT 1 FROM information_schema.columns
|
||||
WHERE table_name = 'reports' AND column_name = 'intake_id'
|
||||
) THEN
|
||||
RAISE NOTICE '✓ intake_id column added to reports table';
|
||||
ELSE
|
||||
RAISE EXCEPTION 'intake_id column not found in reports table';
|
||||
END IF;
|
||||
|
||||
RAISE NOTICE '============================================';
|
||||
RAISE NOTICE 'Migration E0.S1 completed successfully';
|
||||
RAISE NOTICE '============================================';
|
||||
END $$;
|
||||
Reference in New Issue
Block a user