Skip to content

Commit

Permalink
Init update
Browse files Browse the repository at this point in the history
  • Loading branch information
TheBoatyMcBoatFace committed Sep 2, 2023
1 parent abbe68f commit fcfebbf
Showing 1 changed file with 44 additions and 1 deletion.
45 changes: 44 additions & 1 deletion startup/init.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
-- Create a new database named "hasura"
CREATE DATABASE hasura;

-- Create a new user named "hasura" with the password "SecretsOfHasura"
-- Create Hasura user
CREATE USER hasura WITH PASSWORD 'SecretsOfHasura';

-- Grant all privileges on the "hasura" database to the user "hasura"
Expand All @@ -14,4 +14,47 @@ CREATE DATABASE gova11y;

GRANT ALL PRIVILEGES ON DATABASE gova11y TO hasura;

-- Toolbox
CREATE SCHEMA toolbox;

-- Toolbox Functions
-- Auto updated_at
CREATE OR REPLACE FUNCTION toolbox.update_updated_at()
RETURNS trigger
LANGUAGE plpgsql
AS $function$
BEGIN
NEW.updated_at = NOW();
RETURN NEW;
END;
$function$
;



-- Create Targets
CREATE SCHEMA targets;

-- targets.orgs
CREATE TABLE targets.orgs (
id serial4 NOT NULL,
created_at timestamptz NOT NULL DEFAULT now(),
updated_at timestamptz NOT NULL DEFAULT now(),
name varchar NULL,
"type" varchar NULL,
acronym varchar NULL,
description varchar NULL,
active bool NOT NULL DEFAULT false,
CONSTRAINT orgs_un UNIQUE (name),
CONSTRAINT orgs_pk_id PRIMARY KEY (id)
);
CREATE INDEX orgs_acronym_idx ON targets.orgs USING btree (acronym);
CREATE INDEX orgs_name_idx ON targets.orgs USING btree (name);

create trigger orgs_update_trigger before
update
on
targets.orgs for each row execute function toolbox.update_updated_at();



0 comments on commit fcfebbf

Please sign in to comment.