-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAPPLY_ABSENCE_TRACKING.sql
More file actions
40 lines (33 loc) · 1.97 KB
/
Copy pathAPPLY_ABSENCE_TRACKING.sql
File metadata and controls
40 lines (33 loc) · 1.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
-- ============================================================================
-- ABSENCE TRACKING MIGRATION
-- Run this SQL in Supabase Dashboard > SQL Editor
-- ============================================================================
-- Add absence tracking columns to checkins table
ALTER TABLE checkins
ADD COLUMN IF NOT EXISTS absent_adults integer DEFAULT 0,
ADD COLUMN IF NOT EXISTS absent_children integer DEFAULT 0,
ADD COLUMN IF NOT EXISTS absent_infants integer DEFAULT 0,
ADD COLUMN IF NOT EXISTS absence_note text DEFAULT '';
-- Add check constraints to ensure absence counts are not negative
ALTER TABLE checkins
DROP CONSTRAINT IF EXISTS check_absent_adults_non_negative,
DROP CONSTRAINT IF EXISTS check_absent_children_non_negative,
DROP CONSTRAINT IF EXISTS check_absent_infants_non_negative;
ALTER TABLE checkins
ADD CONSTRAINT check_absent_adults_non_negative CHECK (absent_adults >= 0),
ADD CONSTRAINT check_absent_children_non_negative CHECK (absent_children >= 0),
ADD CONSTRAINT check_absent_infants_non_negative CHECK (absent_infants >= 0);
-- Create index for queries that filter by absence
CREATE INDEX IF NOT EXISTS idx_checkins_with_absences
ON checkins(row_hash)
WHERE (absent_adults > 0 OR absent_children > 0 OR absent_infants > 0);
-- Comment the columns for documentation
COMMENT ON COLUMN checkins.absent_adults IS 'Number of adults who checked in but are absent (e.g., due to illness)';
COMMENT ON COLUMN checkins.absent_children IS 'Number of children who checked in but are absent (e.g., due to illness)';
COMMENT ON COLUMN checkins.absent_infants IS 'Number of infants who checked in but are absent (e.g., due to illness)';
COMMENT ON COLUMN checkins.absence_note IS 'Optional note explaining the absence reason (e.g., 体調不良)';
-- Verify the columns were added
SELECT column_name, data_type, column_default
FROM information_schema.columns
WHERE table_name = 'checkins'
AND column_name IN ('absent_adults', 'absent_children', 'absent_infants', 'absence_note');