-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
#118: DB cleanup and IT tests addition to CI #119
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
0b33532
#118: DB cleanup and IT tests addition to CI
lsulak f25f70f
#118: further cleanup
lsulak 1650f30
#118: moving database -> demo_database folder, and moving examples
lsulak 950947b
#118: removing the code in formerly known 'examples/' module - this i…
lsulak File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it adds to the global dependencies, doesn't it? I think flyway dependencies shouldn't be a generic dependency.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe this is what @salamonpavel was dealing with in the past and there was no way how to circumvent this (I know :( ) by extracting / moving elsewhere. Anyway, it's part of the build, i.e. general dependency: https://github.com/AbsaOSS/atum-service/blob/master/build.sbt#L53-L59
(remember, Flyway is temporary anyway)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with @benedeki
and then run it like
sbt modulNeedingFlyaway/flywayMigrate
Are we saying there is an issue with this @lsulak ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we redefine the
flywayMigrate
to behave likesbt modulNeedingFlyaway/flywayMigrate
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Like this
addCommandAlias("flywayMigrate", "modulNeedingFlyaway/flywayMigrate")
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let me try, thanks @Zejnilovic. To be fair I haven't been playing with this one as my primary objective here was to actually have an IT suite embedded in our CI & I borrowed what was done in Atum Service - but I agree that we can improve this mechanism in build.sbt
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's why it got approved, not blocking the whole thing 😉
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tested, it works very nicely, thank you Sasa! #124