Skip to content

Commit

Permalink
Refactor the fmtm_base_schema migrations file (#2023)
Browse files Browse the repository at this point in the history
* fix(migrations): refactor the fmtm_base_schema migrations file

* fix: add username to task_event table

* fix: username column with varying character
  • Loading branch information
Sujanadh authored Dec 24, 2024
1 parent 4387176 commit 13ce03e
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions src/backend/migrations/init/fmtm_base_schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ ALTER SCHEMA public OWNER TO fmtm;

-- PostGIS

CREATE SCHEMA tiger;
CREATE SCHEMA IF NOT EXISTS tiger;
ALTER SCHEMA tiger OWNER TO fmtm;

CREATE SCHEMA tiger_data;
CREATE SCHEMA IF NOT EXISTS tiger_data;
ALTER SCHEMA tiger_data OWNER TO fmtm;

CREATE SCHEMA topology;
CREATE SCHEMA IF NOT EXISTS topology;
ALTER SCHEMA topology OWNER TO fmtm;

CREATE EXTENSION IF NOT EXISTS fuzzystrmatch WITH SCHEMA public;
Expand Down Expand Up @@ -287,6 +287,7 @@ CREATE TABLE public.task_events (
task_id integer NOT NULL,
project_id integer,
user_id integer,
username character varying,
state public.mappingstate,
comment text,
created_at timestamp with time zone NOT NULL DEFAULT now()
Expand Down Expand Up @@ -343,7 +344,7 @@ ALTER TABLE public.users OWNER TO fmtm;

CREATE TABLE public.odk_entities (
entity_id UUID NOT NULL,
status entitystate NOT NULL,
status public.entitystate NOT NULL,
project_id integer NOT NULL,
task_id integer
);
Expand Down Expand Up @@ -495,10 +496,6 @@ CREATE INDEX idx_task_event_user_id
ON public.task_events USING btree (
task_id, user_id
);
CREATE INDEX idx_task_history_date
ON public.task_history USING btree (
task_id, created_at
);
CREATE INDEX idx_entities_project_id
ON public.odk_entities USING btree (
entity_id, project_id
Expand Down Expand Up @@ -565,7 +562,7 @@ ADD CONSTRAINT fk_project_id FOREIGN KEY (

-- Triggers

CREATE OR REPLACE FUNCTION set_task_state()
CREATE OR REPLACE FUNCTION public.set_task_state()
RETURNS TRIGGER AS $$
BEGIN
CASE NEW.event
Expand Down Expand Up @@ -597,7 +594,7 @@ $$ LANGUAGE plpgsql;
CREATE OR REPLACE TRIGGER task_event_state_trigger
BEFORE INSERT ON public.task_events
FOR EACH ROW
EXECUTE FUNCTION set_task_state();
EXECUTE FUNCTION public.set_task_state();

-- Finalise

Expand Down

0 comments on commit 13ce03e

Please sign in to comment.