Skip to content

Commit

Permalink
Added the ability to run liquibase locally as well as initial changes…
Browse files Browse the repository at this point in the history
…ets for the DB

Co-authored-by: Dylan <[email protected]>
Co-authored-by: Chris Preston <[email protected]>
Co-authored-by: hsaldyga <[email protected]>
  • Loading branch information
4 people authored Nov 21, 2024
1 parent 272192c commit 9d5e424
Show file tree
Hide file tree
Showing 22 changed files with 1,307 additions and 6 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@
/.vscode
/.idea
/.mvn
/.sonarlint
/.sonarlint
**/.env
**/.env.*
30 changes: 27 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,38 @@ You can create a database instance via

```
docker pull postgis/postgis:16-3.4
docker run --name wfprev-postgres -e POSTGRES_USER=wfprev -e POSTGRES_PASSWORD=password -p 5432:5432 -d postgis/postgis:16-3.4
docker run --name wfprev-postgres \
--env-file .env.local \
-e POSTGRES_USER=wfprev \
-p 5432:5432 \
-d postgis/postgis:16-3.4
```

Note: Mac users will get the following error, jsut ignore for now ```WARNING: The requested image's platform (linux/amd64) does not match the detected host platform (linux/arm64/v8) and no specific platform was requested
f0de92debad131b48e2d72a9d211bafaa2b8bcb800e5077bb59f3225e5729086```

And build the database model with Liquibase:

```
docker build -t liquibase -f Dockerfile.liquibase.local .
docker run --rm liquibase --url=jdbc:postgresql://172.17.0.2:5432/wfprev --changelog-file=main-changelog.json --username=wfprev --password=password update
cd db
docker build -t liquibase -f Dockerfile.liquibase.local .
docker run --rm \
--env-file .env.local \
liquibase \
/bin/bash -c 'liquibase \
--url=jdbc:postgresql://host.docker.internal:5432/wfprev \
--changelog-file=main-changelog.json \
--username=wfprev \
--password=$WFPREV_DB_PASSWORD \
update'
```

The db/.env.local file should have the following content:

```
WFPREV_DB_PASSWORD=***
POSTGRES_PASSWORD=***
```

[![Lifecycle:Experimental](https://img.shields.io/badge/Lifecycle-Experimental-339999)](<Redirect-URL>)
2 changes: 1 addition & 1 deletion db/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ COPY ./scripts ./scripts
COPY ./main-changelog*.json .
COPY ./liquibase.properties .

ENTRYPOINT [ "sh", "-c", "liquibase $COMMAND $TARGET_LIQUIBASE_TAG --changelog-file=$CHANGELOG_FILE -Dschemaname=$SCHEMA_NAME"]
ENTRYPOINT [ "sh", "-c", "liquibase $COMMAND $TARGET_LIQUIBASE_TAG --changelog-file=$CHANGELOG_FILE -Dschemaname=wfprev"]
4 changes: 4 additions & 0 deletions db/Dockerfile.liquibase.local
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
FROM liquibase/liquibase
ADD . /liquibase
EXPOSE 8080
USER root
130 changes: 129 additions & 1 deletion db/main-changelog.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"changeSet": {
"id": "01_00_00_00",
"author": "dhemsworth",
"tagDatabase": { "tag" : "version_01_00_00_00" },
"changes": [
{
"sqlFile": {
Expand Down Expand Up @@ -42,6 +43,133 @@
}
]
}
},
{
"changeSet": {
"id": "01_00_00_01",
"author": "cpreston",
"tagDatabase": { "tag" : "version_01_00_00_01" },
"changes": [
{
"sqlFile": {
"dbms": "postgresql",
"endDelimiter": ";",
"path": "scripts/01_00_00/01/ddl/extension/wfprev.ddl.add_trigram.sql"
}
}
]
}
},
{
"changeSet": {
"id": "01_00_01_00",
"author": "hsaldyga",
"tagDatabase": { "tag" : "version_01_00_01_00" },
"changes": [
{
"sqlFile": {
"dbms": "postgresql",
"endDelimiter": ";",
"path": "scripts/01_00_01/00/ddl/tables/WFPREV.project_type_code.sql"
}
},
{
"sqlFile": {
"dbms": "postgresql",
"endDelimiter": ";",
"path": "scripts/01_00_01/00/ddl/tables/WFPREV.forest_area_code.sql"
}
},
{
"sqlFile": {
"dbms": "postgresql",
"endDelimiter": ";",
"path": "scripts/01_00_01/00/ddl/tables/WFPREV.general_scope_code.sql"
}
},
{
"sqlFile": {
"dbms": "postgresql",
"endDelimiter": ";",
"path": "scripts/01_00_01/00/ddl/tables/WFPREV.program_area.sql"
}
},
{
"sqlFile": {
"dbms": "postgresql",
"endDelimiter": ";",
"path": "scripts/01_00_01/00/ddl/tables/WFPREV.project.sql"
}
},
{
"sqlFile": {
"dbms": "postgresql",
"endDelimiter": ";",
"path": "scripts/01_00_01/00/ddl/tables/WFPREV.project_audit.sql"
}
},
{
"sqlFile": {
"dbms": "postgresql",
"endDelimiter": ";",
"path": "scripts/01_00_01/00/ddl/tables/WFPREV.project_boundary.sql"
}
},
{
"sqlFile": {
"dbms": "postgresql",
"endDelimiter": ";",
"path": "scripts/01_00_01/00/ddl/tables/WFPREV.project_boundary_audit.sql"
}
},
{
"sqlFile": {
"dbms": "postgresql",
"endDelimiter": ";",
"path": "scripts/01_00_01/00/ddl/sequences/PREV.prev_audit_table_seq.sql"
}
},
{
"sqlFile": {
"dbms": "postgresql",
"endDelimiter": ";",
"path": "scripts/01_00_01/00/dml/app_wf1_prev.dml.forest_area_code.sql"
}
},
{
"sqlFile": {
"dbms": "postgresql",
"endDelimiter": ";",
"path": "scripts/01_00_01/00/dml/app_wf1_prev.dml.general_scope_code.sql"
}
},
{
"sqlFile": {
"dbms": "postgresql",
"endDelimiter": ";",
"path": "scripts/01_00_01/00/dml/app_wf1_prev.dml.program_area.sql"
}
},
{
"sqlFile": {
"dbms": "postgresql",
"endDelimiter": ";",
"path": "scripts/01_00_01/00/dml/app_wf1_prev.dml.project_type_code.sql"
}
}
],
"rollback": [
{ "sql": "DROP SEQUENCE wfprev.prev_audit_table_seq" },
{ "sql": "DROP TABLE wfprev.project_boundary_audit" },
{ "sql": "DROP TABLE wfprev.project_boundary" },
{ "sql": "DROP TABLE wfprev.project_audit" },
{ "sql": "DROP TABLE wfprev.project" },
{ "sql": "DROP TABLE wfprev.program_area" },
{ "sql": "DROP TABLE wfprev.general_scope_code" },
{ "sql": "DROP TABLE wfprev.forest_area_code" },
{ "sql": "DROP TABLE wfprev.project_type_code" },
]
}
}
]
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@ CREATE SCHEMA "wfprev";

GRANT ALL ON SCHEMA "wfprev" TO "app_wf1_prev";

GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA public TO "app_wf1_prev";

GRANT USAGE ON SCHEMA "wfprev" TO "app_wf1_prev_rest_proxy";
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CREATE EXTENSION IF NOT EXISTS pg_trgm;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CREATE SEQUENCE "wfprev"."prev_audit_table_seq" INCREMENT BY 1 START WITH 1 MAXVALUE 9999999999 MINVALUE 1 NO CYCLE;
75 changes: 75 additions & 0 deletions db/scripts/01_00_01/00/ddl/tables/WFPREV.forest_area_code.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/* ---------------------------------------------------- */
/* Generated by Enterprise Architect Version 12.0 */
/* Created On : 12-Nov-2024 4:34:03 PM */
/* DBMS : PostgreSQL */
/* ---------------------------------------------------- */

/* Create Tables */

CREATE TABLE "wfprev"."forest_area_code"
(
"forest_area_code" varchar(10) NOT NULL, -- forest_area_code: Forest Area Code is a list of Ministry Forest Areas Values are: - Coast - North - West
"description" varchar(200) NOT NULL, -- DESCRIPTION is the display quality description of the code value.
"display_order" decimal(3) NULL, -- DISPLAY ORDER is to allow non alphabetic sorting e.g. M T W Th F S S.
"effective_date" DATE NOT NULL DEFAULT CURRENT_DATE, -- EFFECTIVE_DATE is the date code value becomes effective.
"expiry_date" DATE NOT NULL DEFAULT '9999-12-31', -- EXPIRY_DATE is the date code value expires.
"revision_count" decimal(10) NOT NULL DEFAULT 0, -- REVISION_COUNT is the number of times that the row of data has been changed. The column is used for optimistic locking via application code.
"create_user" varchar(64) NOT NULL, -- CREATE_USER is an audit column that indicates the user that created the record.
"create_date" DATE NOT NULL DEFAULT CURRENT_TIMESTAMP, -- CREATE_DATE is the date and time the row of data was created.
"update_user" varchar(64) NOT NULL, -- UPDATE_USER is an audit column that indicates the user that updated the record.
"update_date" DATE NOT NULL DEFAULT CURRENT_TIMESTAMP -- UPDATE_DATE is the date and time the row of data was updated.
)
TABLESPACE PG_DEFAULT
;

/* Create Table Comments, Sequences for Autonumber Columns */

COMMENT ON TABLE "wfprev"."forest_area_code"
IS 'Forest Area Code is a list of Ministry Forest Areas Values are: - Coast - North - West'
;

COMMENT ON COLUMN "wfprev"."forest_area_code"."forest_area_code"
IS 'forest_area_code: Forest Area Code is a list of Ministry Forest Areas Values are: - Coast - North - West'
;

COMMENT ON COLUMN "wfprev"."forest_area_code"."description"
IS 'DESCRIPTION is the display quality description of the code value.'
;

COMMENT ON COLUMN "wfprev"."forest_area_code"."display_order"
IS 'DISPLAY ORDER is to allow non alphabetic sorting e.g. M T W Th F S S.'
;

COMMENT ON COLUMN "wfprev"."forest_area_code"."effective_date"
IS 'EFFECTIVE_DATE is the date code value becomes effective.'
;

COMMENT ON COLUMN "wfprev"."forest_area_code"."expiry_date"
IS 'EXPIRY_DATE is the date code value expires.'
;

COMMENT ON COLUMN "wfprev"."forest_area_code"."revision_count"
IS 'REVISION_COUNT is the number of times that the row of data has been changed. The column is used for optimistic locking via application code.'
;

COMMENT ON COLUMN "wfprev"."forest_area_code"."create_user"
IS 'CREATE_USER is an audit column that indicates the user that created the record.'
;

COMMENT ON COLUMN "wfprev"."forest_area_code"."create_date"
IS 'CREATE_DATE is the date and time the row of data was created.'
;

COMMENT ON COLUMN "wfprev"."forest_area_code"."update_user"
IS 'UPDATE_USER is an audit column that indicates the user that updated the record.'
;

COMMENT ON COLUMN "wfprev"."forest_area_code"."update_date"
IS 'UPDATE_DATE is the date and time the row of data was updated.'
;

/* Create Primary Keys, Indexes, Uniques, Checks */

ALTER TABLE "wfprev"."forest_area_code" ADD CONSTRAINT "facd_pk"
PRIMARY KEY ("forest_area_code")
;
75 changes: 75 additions & 0 deletions db/scripts/01_00_01/00/ddl/tables/WFPREV.general_scope_code.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/* ---------------------------------------------------- */
/* Generated by Enterprise Architect Version 12.0 */
/* Created On : 12-Nov-2024 4:35:05 PM */
/* DBMS : PostgreSQL */
/* ---------------------------------------------------- */

/* Create Tables */

CREATE TABLE "wfprev"."general_scope_code"
(
"general_scope_code" varchar(10) NOT NULL, -- general_scope_code: General Scope Code is the set of high level scopes a project may have. Values are: - Landscape Level Activities - Site Level Activities - Non-Spatial Activities
"description" varchar(200) NOT NULL, -- DESCRIPTION is the display quality description of the code value.
"display_order" decimal(3) NULL, -- DISPLAY ORDER is to allow non alphabetic sorting e.g. M T W Th F S S.
"effective_date" DATE NOT NULL DEFAULT CURRENT_DATE, -- EFFECTIVE_DATE is the date code value becomes effective.
"expiry_date" DATE NOT NULL DEFAULT '9999-12-31', -- EXPIRY_DATE is the date code value expires.
"revision_count" decimal(10) NOT NULL DEFAULT 0, -- REVISION_COUNT is the number of times that the row of data has been changed. The column is used for optimistic locking via application code.
"create_user" varchar(64) NOT NULL, -- CREATE_USER is an audit column that indicates the user that created the record.
"create_date" DATE NOT NULL DEFAULT CURRENT_TIMESTAMP, -- CREATE_DATE is the date and time the row of data was created.
"update_user" varchar(64) NOT NULL, -- UPDATE_USER is an audit column that indicates the user that updated the record.
"update_date" DATE NOT NULL DEFAULT CURRENT_TIMESTAMP -- UPDATE_DATE is the date and time the row of data was updated.
)
TABLESPACE PG_DEFAULT
;

/* Create Table Comments, Sequences for Autonumber Columns */

COMMENT ON TABLE "wfprev"."general_scope_code"
IS 'General Scope Code is the set of high level scopes a project may have. Values are: - Landscape Level Activities - Site Level Activities - Non-Spatial Activities'
;

COMMENT ON COLUMN "wfprev"."general_scope_code"."general_scope_code"
IS 'general_scope_code: General Scope Code is the set of high level scopes a project may have. Values are: - Landscape Level Activities - Site Level Activities - Non-Spatial Activities'
;

COMMENT ON COLUMN "wfprev"."general_scope_code"."description"
IS 'DESCRIPTION is the display quality description of the code value.'
;

COMMENT ON COLUMN "wfprev"."general_scope_code"."display_order"
IS 'DISPLAY ORDER is to allow non alphabetic sorting e.g. M T W Th F S S.'
;

COMMENT ON COLUMN "wfprev"."general_scope_code"."effective_date"
IS 'EFFECTIVE_DATE is the date code value becomes effective.'
;

COMMENT ON COLUMN "wfprev"."general_scope_code"."expiry_date"
IS 'EXPIRY_DATE is the date code value expires.'
;

COMMENT ON COLUMN "wfprev"."general_scope_code"."revision_count"
IS 'REVISION_COUNT is the number of times that the row of data has been changed. The column is used for optimistic locking via application code.'
;

COMMENT ON COLUMN "wfprev"."general_scope_code"."create_user"
IS 'CREATE_USER is an audit column that indicates the user that created the record.'
;

COMMENT ON COLUMN "wfprev"."general_scope_code"."create_date"
IS 'CREATE_DATE is the date and time the row of data was created.'
;

COMMENT ON COLUMN "wfprev"."general_scope_code"."update_user"
IS 'UPDATE_USER is an audit column that indicates the user that updated the record.'
;

COMMENT ON COLUMN "wfprev"."general_scope_code"."update_date"
IS 'UPDATE_DATE is the date and time the row of data was updated.'
;

/* Create Primary Keys, Indexes, Uniques, Checks */

ALTER TABLE "wfprev"."general_scope_code" ADD CONSTRAINT "prjcd_pk"
PRIMARY KEY ("general_scope_code")
;
Loading

0 comments on commit 9d5e424

Please sign in to comment.