-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #119 from AbsaOSS/feature/118-db-function-cleanup-…
…pre-118 #118: DB cleanup and IT tests addition to CI
- Loading branch information
Showing
45 changed files
with
556 additions
and
526 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
# | ||
# Copyright 2022 ABSA Group Limited | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
|
||
name: Run Integration Tests | ||
|
||
on: | ||
pull_request: | ||
branches: | ||
- '**' | ||
types: [ opened, synchronize, reopened ] | ||
|
||
jobs: | ||
run-it: | ||
runs-on: ubuntu-latest | ||
services: | ||
postgres: | ||
image: postgres:15 | ||
env: | ||
POSTGRES_PASSWORD: postgres | ||
POSTGRES_DB: movies | ||
options: >- | ||
--health-cmd pg_isready | ||
--health-interval 10s | ||
--health-timeout 5s | ||
--health-retries 5 | ||
ports: | ||
- 5432:5432 | ||
strategy: | ||
matrix: | ||
scala: [ 2.12.17, 2.13.12 ] | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v2 | ||
- uses: coursier/cache-action@v5 | ||
|
||
- name: Setup Scala | ||
uses: olafurpg/setup-scala@v14 | ||
with: | ||
java-version: "[email protected]" | ||
|
||
- name: Prepare testing database | ||
run: sbt flywayMigrate | ||
|
||
- name: Build and run IT tests for Doobie | ||
run: sbt "project faDBDoobie" ++${{matrix.scala}} it:test | ||
|
||
- name: Build and run IT tests for Slick | ||
run: sbt "project faDBSlick" ++${{matrix.scala}} it:test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
## About | ||
|
||
This module implements a simple database with many types of objects (tables, functions, data insertions, and more) | ||
that will be used in integration tests in these modules: | ||
* `doobie/src/it/` | ||
* `slick/src/it/` | ||
|
||
## Deployment | ||
|
||
How to set up database for local testing | ||
|
||
### Using Docker | ||
|
||
```zsh | ||
# start up postgres docker container (optional; instead you can create movies on your local postgres instance) | ||
docker run --name=movies -e POSTGRES_PASSWORD=postgres -e POSTGRES_DB=movies -p 5432:5432 -d postgres:16 | ||
|
||
# migrate scripts | ||
sbt flywayMigrate | ||
|
||
# kill & remove docker container (optional; only if using dockerized postgres instance) | ||
docker kill aul_db | ||
docker rm aul_db | ||
``` | ||
|
||
### Using local postgres instance | ||
|
||
```zsh | ||
# migrate scripts | ||
sbt flywayMigrate | ||
``` | ||
|
||
In case some structures are already present in the database, you can use | ||
```zsh | ||
sbt flywayClean | ||
``` | ||
to remove them or | ||
```zsh | ||
sbt flywayBaseline | ||
``` | ||
to set the current state as the baseline. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/* | ||
* Copyright 2021 ABSA Group Limited | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
CREATE DATABASE movies | ||
WITH | ||
ENCODING = 'UTF8' | ||
CONNECTION LIMIT = -1; |
18 changes: 18 additions & 0 deletions
18
demo_database/src/main/postgres/V1.1.1__01_add_extensions.ddl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/* | ||
* Copyright 2021 ABSA Group Limited | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
CREATE EXTENSION IF NOT EXISTS hstore; | ||
CREATE EXTENSION IF NOT EXISTS ltree; | ||
CREATE EXTENSION IF NOT EXISTS "uuid-ossp"; -- for function `uuid_generate_v4` |
44 changes: 44 additions & 0 deletions
44
demo_database/src/main/postgres/integration/V1.2.10__get_all_date_time_types.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* Copyright 2022 ABSA Group Limited | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
CREATE OR REPLACE FUNCTION integration.get_all_date_time_types(p_id INT) | ||
RETURNS TABLE( | ||
offset_date_time TIMESTAMPTZ, | ||
instant TIMESTAMPTZ, | ||
zoned_date_time TIMESTAMPTZ, | ||
local_date_time TIMESTAMP, | ||
local_date DATE, | ||
local_time TIME, | ||
sql_date DATE, | ||
sql_time TIME, | ||
sql_timestamp TIMESTAMP, | ||
util_date TIMESTAMP | ||
) AS $$ | ||
BEGIN | ||
RETURN QUERY SELECT | ||
T.offset_date_time, | ||
T.instant, | ||
T.zoned_date_time, | ||
T.local_date_time, | ||
T.local_date, | ||
T.local_time, | ||
T.sql_date, | ||
T.sql_time, | ||
T.sql_timestamp, | ||
T.util_date | ||
FROM integration.date_time_types T limit p_id; | ||
END; | ||
$$ LANGUAGE plpgsql; |
62 changes: 62 additions & 0 deletions
62
demo_database/src/main/postgres/integration/V1.2.11__insert_dates_times.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* | ||
* Copyright 2022 ABSA Group Limited | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
CREATE OR REPLACE FUNCTION integration.insert_dates_times( | ||
IN p_offset_date_time TIMESTAMPTZ, | ||
IN p_instant TIMESTAMPTZ, | ||
IN p_zoned_date_time TIMESTAMPTZ, | ||
IN p_local_date_time TIMESTAMP, | ||
IN p_local_date DATE, | ||
IN p_local_time TIME, | ||
IN p_sql_date DATE, | ||
IN p_sql_time TIME, | ||
IN p_sql_timestamp TIMESTAMP, | ||
IN p_util_date DATE, | ||
OUT status INTEGER, | ||
OUT status_text TEXT, | ||
OUT o_id INTEGER | ||
) RETURNS record AS $$ | ||
BEGIN | ||
INSERT INTO integration.date_time_types ( | ||
offset_date_time, | ||
instant, | ||
zoned_date_time, | ||
local_date_time, | ||
local_date, | ||
local_time, | ||
sql_date, | ||
sql_time, | ||
sql_timestamp, | ||
util_date | ||
) VALUES ( | ||
p_offset_date_time, | ||
p_instant, | ||
p_zoned_date_time, | ||
p_local_date_time, | ||
p_local_date, | ||
p_local_time, | ||
p_sql_date, | ||
p_sql_time, | ||
p_sql_timestamp, | ||
p_util_date | ||
) RETURNING id INTO o_id; | ||
|
||
status := 11; | ||
status_text := 'OK'; | ||
|
||
RETURN; | ||
END; | ||
$$ LANGUAGE plpgsql; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.