Skip to content

Commit 7fc8778

Browse files
committed
feat: add logging for search terms and categories selected by user
1 parent 5c4d453 commit 7fc8778

File tree

1 file changed

+73
-27
lines changed

1 file changed

+73
-27
lines changed

backend/migrations/00040_alter_programs.sql

+73-27
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,73 @@
11
-- +goose Up
22
-- +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);
625
ALTER TABLE public.program_sections ADD COLUMN capacity INT;
726
ALTER TABLE public.program_sections ADD COLUMN name VARCHAR(255);
827
ALTER TABLE public.program_sections ADD COLUMN instructor_name VARCHAR(255);
928
ALTER TABLE public.program_sections ADD COLUMN description TEXT;
1029
ALTER TABLE public.program_sections ADD COLUMN archived_at timestamp with time zone;
1130
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;
1434
ALTER TABLE public.program_sections ADD COLUMN is_active boolean;
1535
ALTER TABLE public.program_section_enrollments ADD COLUMN enrollment_status VARCHAR(255);
1636
ALTER TABLE public.program_section_events RENAME COLUMN location TO room;
1737

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+
1854
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
3471
);
3572

3673
CREATE TABLE public.programs_sections_history (
@@ -56,34 +93,43 @@ END;
5693
$$ LANGUAGE plpgsql;
5794

5895
CREATE TRIGGER sql_trigger_programs_update
59-
AFTER UPDATE ON public.programs
96+
AFTER UPDATE ON public.programs
6097
FOR EACH ROW
61-
EXECUTE FUNCTION public.log_programs_sections_updates();
98+
EXECUTE FUNCTION public.log_programs_sections_updates();
6299

63100
CREATE TRIGGER sql_trigger_program_sections_update
64-
AFTER UPDATE ON public.program_sections
101+
AFTER UPDATE ON public.program_sections
65102
FOR EACH ROW
66-
EXECUTE FUNCTION public.log_programs_sections_updates();
103+
EXECUTE FUNCTION public.log_programs_sections_updates();
67104
-- +goose StatementEnd
68105

69106
-- +goose Down
70107
-- +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;
71113
DROP TRIGGER IF EXISTS sql_trigger_programs_update ON programs;
72114
DROP TRIGGER IF EXISTS sql_trigger_program_sections_update ON program_sections;
73115
DROP FUNCTION IF EXISTS public.log_programs_sections_updates();
74116
DROP TABLE IF EXISTS public.programs_sections_history CASCADE;
75117
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);
77121
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;
79124
ALTER TABLE public.program_sections DROP COLUMN capacity;
80125
ALTER TABLE public.program_sections DROP COLUMN name;
81126
ALTER TABLE public.program_sections DROP COLUMN instructor_name;
82127
ALTER TABLE public.program_sections DROP COLUMN description;
83128
ALTER TABLE public.program_sections DROP COLUMN archived_at;
84129
ALTER TABLE public.program_sections DROP COLUMN start_dt;
85130
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;
87133
ALTER TABLE public.program_sections DROP COLUMN is_active;
88134
ALTER TABLE public.program_section_enrollments DROP COLUMN enrollment_status;
89135
ALTER TABLE public.program_section_events RENAME COLUMN room TO location;

0 commit comments

Comments
 (0)