Skip to content

Commit

Permalink
Merge pull request #839 from bcgov/ricander
Browse files Browse the repository at this point in the history
Master script for test to deploy empty DB, schema, and data seeding
  • Loading branch information
larsenle authored Dec 4, 2024
2 parents b77cdbe + 019ec08 commit fe94d99
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
39 changes: 39 additions & 0 deletions database/utility/STR_DSS_Database_Create.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
-- Check if DB exists and drop if it does
DO
$$
DECLARE
db_name TEXT := 'strdssdev';
BEGIN
-- Check if the database exists
IF EXISTS (
SELECT 1 FROM pg_database
WHERE datname = db_name
) THEN
-- Terminate active connections to the database
PERFORM pg_terminate_backend(pid)
FROM pg_stat_activity
WHERE datname = db_name;
END IF;
END;
$$;

DROP DATABASE IF EXISTS strdssdev;

-- Check if strdss role exists and drop if it does
DO
$$
BEGIN
IF EXISTS (
SELECT 1 FROM pg_roles
WHERE rolname = 'strdssdev'
) THEN
EXECUTE format('DROP ROLE %I', 'strdssdev');
END IF;
END
$$;

CREATE ROLE strdssdev WITH LOGIN PASSWORD 'postgres';
CREATE DATABASE strdssdev;
ALTER DATABASE strdssdev OWNER TO strdssdev;
\c strdssdev
CREATE EXTENSION postgis;
8 changes: 8 additions & 0 deletions database/utility/STR_DSS_Master.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
rem This script must be run from the House-Policy-STRDSS/database/utility folder
rem by replacing 'rem' with '#', this file will run with /bin/sh under Linux
docker cp ../database/utility house-policy-strdss-strdss-db-1:/utility
docker cp ../database/ddl house-policy-strdss-strdss-db-1:/ddl
docker cp ../database/seeding house-policy-strdss-strdss-db-1:/seeding
docker exec -i house-policy-strdss-strdss-db-1 psql -U postgres -f utility/STR_DSS_Database_Create.sql
rem The SQL script below must be the correct sprint migration script for the current sprint (i.e. STR_DSS_Migration_Sprint_<SprintNumber>.sql)
docker exec -i house-policy-strdss-strdss-db-1 psql -U postgres -d strdssdev -f utility/STR_DSS_Migration_Sprint_18.sql

0 comments on commit fe94d99

Please sign in to comment.