Skip to content

Commit

Permalink
Merge branch 'main' into RSN-46
Browse files Browse the repository at this point in the history
  • Loading branch information
bilimig committed May 7, 2024
2 parents 2f0117d + fdbbc18 commit 5e68fd5
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 21 deletions.
3 changes: 2 additions & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
*.sh text eol=lf
* text=auto eol=lf
*.cs -text
2 changes: 0 additions & 2 deletions .gitattributes.txt

This file was deleted.

59 changes: 59 additions & 0 deletions .github/workflows/postgres-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: postgres tests

on:
pull_request:
types: [opened, synchronize, reopened]
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: reasn
POSTGRES_HOST: localhost

jobs:
postgres-tests:
runs-on: ubuntu-latest
defaults:
run:
working-directory: Database
services:
postgres:
image: postgres:16
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432
env:
POSTGRES_PASSWORD: ${{ env.POSTGRES_PASSWORD }}
POSTGRES_DB: ${{ env.POSTGRES_DB }}
steps:
- uses: actions/checkout@v4

- name: Initialize database
run: |
psql -h ${{ env.POSTGRES_HOST }} -U ${{ env.POSTGRES_USER }} -d ${{ env.POSTGRES_DB }} -f init-db.sql
psql -h ${{ env.POSTGRES_HOST }} -U ${{ env.POSTGRES_USER }} -d ${{ env.POSTGRES_DB }} -f init-constraints.sql
env:
PGPASSWORD: ${{ env.POSTGRES_PASSWORD }}

- name: Initialize development data
run: |
psql -h ${{ env.POSTGRES_HOST }} -U ${{ env.POSTGRES_USER }} -d ${{ env.POSTGRES_DB }} -f init-dev-data.sql
env:
PGPASSWORD: ${{ env.POSTGRES_PASSWORD }}

- name: Verify data initialization correctness
run: |
docker logs "${{ job.services.postgres.id }}" 2>&1 | tee "postgres-logs-commit-${{ github.sha }}.log"
if grep -q -i error postgres-logs-commit-${{ github.sha }}.log; then exit 1; fi
- name: Upload captured logs
uses: actions/upload-artifact@v4
if: ${{ failure() }}
with:
name: postgres-logs-commit-${{ github.sha }}
path: Database/postgres-logs-commit-${{ github.sha }}.log
retention-days: 14

6 changes: 3 additions & 3 deletions .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
runs-on: ${{ matrix.os }}
defaults:
run:
working-directory: ./Server/ReasnAPI
working-directory: Server/ReasnAPI
steps:
- uses: actions/checkout@v4

Expand Down Expand Up @@ -50,7 +50,7 @@ jobs:
if: ${{ failure() }}
with:
name: dotnet-results-${{ matrix.os }}-commit-${{ github.sha }}
path: TestResults-${{ matrix.os }}-commit-${{ github.sha }}
path: Server/ReasnAPI/TestResults-${{ matrix.os }}-commit-${{ github.sha }}
retention-days: 14

client-tests:
Expand All @@ -60,7 +60,7 @@ jobs:
runs-on: ${{ matrix.os }}
defaults:
run:
working-directory: ./Client/reasn-client
working-directory: Client/reasn-client
steps:
- uses: actions/checkout@v4

Expand Down
2 changes: 1 addition & 1 deletion Database/init-db.sql
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ CREATE TABLE IF NOT EXISTS users.user_interest (

CREATE TABLE IF NOT EXISTS users.interest (
"id" SERIAL PRIMARY KEY,
"name" text NOT NULL CONSTRAINT users_interest_name_maxlength CHECK (LENGTH("name") <= 32),
"name" text NOT NULL CONSTRAINT users_interest_name_maxlength CHECK (LENGTH("name") <= 32)
);

ALTER TABLE users.user ADD FOREIGN KEY ("role_id") REFERENCES users.role ("id");
Expand Down
27 changes: 13 additions & 14 deletions Database/init-users.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,20 @@
set -e

psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" <<-EOSQL
CREATE USER "$POSTGRES_ADMIN_USER" WITH LOGIN PASSWORD '$POSTGRES_ADMIN_PASSWORD';
GRANT CONNECT ON DATABASE $POSTGRES_DB TO $POSTGRES_ADMIN_USER;
GRANT INSERT, SELECT, UPDATE, DELETE ON ALL TABLES IN SCHEMA events TO $POSTGRES_ADMIN_USER;
GRANT INSERT, SELECT, UPDATE, DELETE ON ALL TABLES IN SCHEMA users TO $POSTGRES_ADMIN_USER;
GRANT INSERT, SELECT, UPDATE, DELETE ON ALL TABLES IN SCHEMA common TO $POSTGRES_ADMIN_USER;
GRANT CREATE ON SCHEMA events TO $POSTGRES_ADMIN_USER;
GRANT CREATE ON SCHEMA users TO $POSTGRES_ADMIN_USER;
GRANT CREATE ON SCHEMA common TO $POSTGRES_ADMIN_USER;
CREATE USER "$POSTGRES_CLIENT_USER" WITH LOGIN PASSWORD '$POSTGRES_CLIENT_PASSWORD';
CREATE USER "$POSTGRES_ADMIN_USER" WITH LOGIN PASSWORD '$POSTGRES_ADMIN_PASSWORD';
GRANT CONNECT ON DATABASE $POSTGRES_DB TO $POSTGRES_ADMIN_USER;
GRANT INSERT, SELECT, UPDATE, DELETE ON ALL TABLES IN SCHEMA events TO $POSTGRES_ADMIN_USER;
GRANT INSERT, SELECT, UPDATE, DELETE ON ALL TABLES IN SCHEMA users TO $POSTGRES_ADMIN_USER;
GRANT INSERT, SELECT, UPDATE, DELETE ON ALL TABLES IN SCHEMA common TO $POSTGRES_ADMIN_USER;
GRANT CREATE ON SCHEMA events TO $POSTGRES_ADMIN_USER;
GRANT CREATE ON SCHEMA users TO $POSTGRES_ADMIN_USER;
GRANT CREATE ON SCHEMA common TO $POSTGRES_ADMIN_USER;
CREATE USER "$POSTGRES_CLIENT_USER" WITH LOGIN PASSWORD '$POSTGRES_CLIENT_PASSWORD';
GRANT CONNECT ON DATABASE $POSTGRES_DB TO $POSTGRES_CLIENT_USER;
GRANT SELECT ON ALL TABLES IN SCHEMA events TO $POSTGRES_CLIENT_USER;
GRANT SELECT ON ALL TABLES IN SCHEMA common TO $POSTGRES_CLIENT_USER;
GRANT SELECT ON ALL TABLES IN SCHEMA common TO $POSTGRES_CLIENT_USER;
GRANT SELECT, UPDATE, INSERT, DELETE ON ALL TABLES IN SCHEMA users TO $POSTGRES_CLIENT_USER;
GRANT UPDATE, INSERT ON events.event, events.tag, events.parameter, common.status, common.image TO $POSTGRES_CLIENT_USER;
GRANT UPDATE, INSERT ON events.event, events.tag, events.parameter, common.status, common.image TO $POSTGRES_CLIENT_USER;
EOSQL

0 comments on commit 5e68fd5

Please sign in to comment.