|
1 | 1 | -- +goose Up
|
2 | 2 | -- +goose StatementBegin
|
3 |
| -ALTER TABLE public.programs ADD COLUMN program_owner VARCHAR(255); |
4 |
| -ALTER TABLE public.programs ADD COLUMN funding_type VARCHAR(50); |
5 |
| -ALTER TABLE public.facilities_programs ADD COLUMN archived_at timestamp with time zone; |
| 3 | +CREATE TYPE public.program_type AS ENUM ( |
| 4 | + 'Educational', |
| 5 | + 'Mental_Health_Behavioral', |
| 6 | + 'Religious_Faith-Based', |
| 7 | + 'Re-Entry', |
| 8 | + 'Life_Skills' |
| 9 | +); |
| 10 | +CREATE TYPE public.funding_type AS ENUM ( |
| 11 | + 'Federal_Grants', |
| 12 | + 'State_Grants', |
| 13 | + 'Nonprofit_Organizations', |
| 14 | + 'Educational_Grants', |
| 15 | + 'Inmate_Welfare_Funds', |
| 16 | + 'Other' |
| 17 | +); |
| 18 | +ALTER TABLE public.programs DROP COLUMN credit_type; |
| 19 | +ALTER TABLE public.programs DROP COLUMN program_type; |
| 20 | +ALTER TABLE public.programs ADD COLUMN program_type program_type; |
| 21 | +ALTER TABLE public.programs ADD COLUMN funding_type funding_type; |
| 22 | +ALTER TABLE public.program_tags RENAME TO program_types; |
| 23 | +ALTER TABLE public.program_types DROP COLUMN facility_id; |
| 24 | +ALTER TABLE public.facilities_programs ADD COLUMN program_owner VARCHAR(255); |
6 | 25 | ALTER TABLE public.program_sections ADD COLUMN capacity INT;
|
7 | 26 | ALTER TABLE public.program_sections ADD COLUMN name VARCHAR(255);
|
8 | 27 | ALTER TABLE public.program_sections ADD COLUMN instructor_name VARCHAR(255);
|
9 | 28 | ALTER TABLE public.program_sections ADD COLUMN description TEXT;
|
10 | 29 | ALTER TABLE public.program_sections ADD COLUMN archived_at timestamp with time zone;
|
11 | 30 | ALTER TABLE public.program_sections ADD COLUMN start_dt date;
|
12 |
| -ALTER TABLE public.program_sections ADD COLUMN duration VARCHAR(32); |
13 |
| -ALTER TABLE public.program_sections ADD COLUMN total_hours INT; |
| 31 | +ALTER TABLE public.program_sections ADD COLUMN duration VARCHAR(32) NOT NULL DEFAULT ''; |
| 32 | +ALTER TABLE public.program_sections ADD COLUMN status VARCHAR(50); |
| 33 | +ALTER TABLE public.program_sections ADD COLUMN credit_hours INT; |
14 | 34 | ALTER TABLE public.program_sections ADD COLUMN is_active boolean;
|
15 | 35 | ALTER TABLE public.program_section_enrollments ADD COLUMN enrollment_status VARCHAR(255);
|
16 | 36 | ALTER TABLE public.program_section_events RENAME COLUMN location TO room;
|
17 | 37 |
|
| 38 | +CREATE TYPE public.credit_type AS ENUM ( |
| 39 | + 'Completion', |
| 40 | + 'Participation', |
| 41 | + 'Earned-time', |
| 42 | + 'Education' |
| 43 | +); |
| 44 | + |
| 45 | +CREATE TABLE public.program_credit_types ( |
| 46 | + program_id integer NOT NULL, |
| 47 | + credit_type credit_type NOT NULL, |
| 48 | + |
| 49 | + FOREIGN KEY (program_id) REFERENCES public.programs(id) ON UPDATE CASCADE ON DELETE CASCADE, |
| 50 | + |
| 51 | + PRIMARY KEY (program_id, credit_type) |
| 52 | +); |
| 53 | + |
18 | 54 | CREATE TABLE public.program_completions (
|
19 |
| - id SERIAL NOT NULL PRIMARY KEY, |
20 |
| - program_section_id integer NOT NULL, |
21 |
| - program_id integer NOT NULL, |
22 |
| - facility_name CHARACTER VARYING(255) NOT NULL, |
23 |
| - credit_type CHARACTER VARYING(255) NOT NULL, |
24 |
| - program_owner CHARACTER VARYING(255) NOT NULL, |
25 |
| - program_name CHARACTER VARYING(255), |
26 |
| - program_section_name CHARACTER VARYING(255), |
27 |
| - program_section_start_dt CHARACTER VARYING(255), |
28 |
| - created_at timestamp with time zone, |
29 |
| - updated_at timestamp with time zone, |
30 |
| - deleted_at timestamp with time zone, |
31 |
| - |
32 |
| - FOREIGN KEY (program_section_id) REFERENCES public.program_sections(id) ON UPDATE CASCADE ON DELETE CASCADE, |
33 |
| - FOREIGN KEY (program_id) REFERENCES public.programs(id) ON UPDATE CASCADE ON DELETE CASCADE |
| 55 | + id SERIAL NOT NULL PRIMARY KEY, |
| 56 | + program_section_id integer, |
| 57 | + facility_name CHARACTER VARYING(255) NOT NULL, |
| 58 | + credit_type CHARACTER VARYING(255) NOT NULL, |
| 59 | + admin_email CHARACTER VARYING(255) NOT NULL, |
| 60 | + program_owner CHARACTER VARYING(255) NOT NULL, |
| 61 | + program_name CHARACTER VARYING(255), |
| 62 | + program_id integer NOT NULL, |
| 63 | + program_section_name CHARACTER VARYING(255), |
| 64 | + program_section_start_dt CHARACTER VARYING(255), |
| 65 | + created_at timestamp with time zone, |
| 66 | + updated_at timestamp with time zone, |
| 67 | + deleted_at timestamp with time zone, |
| 68 | + |
| 69 | + FOREIGN KEY (program_section_id) REFERENCES public.program_sections(id) ON UPDATE CASCADE ON DELETE CASCADE, |
| 70 | + FOREIGN KEY (program_id) REFERENCES public.programs(id) ON UPDATE CASCADE ON DELETE CASCADE |
34 | 71 | );
|
35 | 72 |
|
36 | 73 | CREATE TABLE public.programs_sections_history (
|
|
56 | 93 | $$ LANGUAGE plpgsql;
|
57 | 94 |
|
58 | 95 | CREATE TRIGGER sql_trigger_programs_update
|
59 |
| - AFTER UPDATE ON public.programs |
| 96 | + AFTER UPDATE ON public.programs |
60 | 97 | FOR EACH ROW
|
61 |
| - EXECUTE FUNCTION public.log_programs_sections_updates(); |
| 98 | + EXECUTE FUNCTION public.log_programs_sections_updates(); |
62 | 99 |
|
63 | 100 | CREATE TRIGGER sql_trigger_program_sections_update
|
64 |
| - AFTER UPDATE ON public.program_sections |
| 101 | + AFTER UPDATE ON public.program_sections |
65 | 102 | FOR EACH ROW
|
66 |
| - EXECUTE FUNCTION public.log_programs_sections_updates(); |
| 103 | + EXECUTE FUNCTION public.log_programs_sections_updates(); |
67 | 104 | -- +goose StatementEnd
|
68 | 105 |
|
69 | 106 | -- +goose Down
|
70 | 107 | -- +goose StatementBegin
|
| 108 | +ALTER TABLE public.programs DROP COLUMN program_type; |
| 109 | +DROP TYPE IF EXISTS public.program_type; |
| 110 | +ALTER TABLE public.programs ADD COLUMN program_type CHARACTER VARYING(50); |
| 111 | +ALTER TABLE public.program_types ADD COLUMN facility_id INTEGER DEFAULT 0; |
| 112 | +ALTER TABLE public.program_types RENAME TO program_tags; |
71 | 113 | DROP TRIGGER IF EXISTS sql_trigger_programs_update ON programs;
|
72 | 114 | DROP TRIGGER IF EXISTS sql_trigger_program_sections_update ON program_sections;
|
73 | 115 | DROP FUNCTION IF EXISTS public.log_programs_sections_updates();
|
74 | 116 | DROP TABLE IF EXISTS public.programs_sections_history CASCADE;
|
75 | 117 | DROP TABLE IF EXISTS public.program_completions CASCADE;
|
76 |
| -ALTER TABLE public.programs DROP COLUMN program_owner; |
| 118 | +DROP TABLE IF EXISTS public.program_credit_types CASCADE; |
| 119 | +DROP TYPE IF EXISTS public.credit_type; |
| 120 | +ALTER TABLE public.programs ADD COLUMN credit_type CHARACTER VARYING(50); |
77 | 121 | ALTER TABLE public.programs DROP COLUMN funding_type;
|
78 |
| -ALTER TABLE public.facilities_programs DROP COLUMN archived_at; |
| 122 | +DROP TYPE IF EXISTS public.funding_type; |
| 123 | +ALTER TABLE public.facilities_programs DROP COLUMN program_owner; |
79 | 124 | ALTER TABLE public.program_sections DROP COLUMN capacity;
|
80 | 125 | ALTER TABLE public.program_sections DROP COLUMN name;
|
81 | 126 | ALTER TABLE public.program_sections DROP COLUMN instructor_name;
|
82 | 127 | ALTER TABLE public.program_sections DROP COLUMN description;
|
83 | 128 | ALTER TABLE public.program_sections DROP COLUMN archived_at;
|
84 | 129 | ALTER TABLE public.program_sections DROP COLUMN start_dt;
|
85 | 130 | ALTER TABLE public.program_sections DROP COLUMN duration;
|
86 |
| -ALTER TABLE public.program_sections DROP COLUMN total_hours; |
| 131 | +ALTER TABLE public.program_sections DROP COLUMN status; |
| 132 | +ALTER TABLE public.program_sections DROP COLUMN credit_hours; |
87 | 133 | ALTER TABLE public.program_sections DROP COLUMN is_active;
|
88 | 134 | ALTER TABLE public.program_section_enrollments DROP COLUMN enrollment_status;
|
89 | 135 | ALTER TABLE public.program_section_events RENAME COLUMN room TO location;
|
|
0 commit comments