Skip to content

Commit

Permalink
Merge branch 'RSN-14' into RSN-38
Browse files Browse the repository at this point in the history
  • Loading branch information
mkoper02 authored May 6, 2024
2 parents 034e2cb + a01b96f commit 34c24f4
Show file tree
Hide file tree
Showing 11 changed files with 650 additions and 591 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
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
112 changes: 56 additions & 56 deletions Database/init-db.sql
Original file line number Diff line number Diff line change
Expand Up @@ -4,148 +4,148 @@ CREATE SCHEMA common;

CREATE TABLE IF NOT EXISTS events.event (
"id" SERIAL PRIMARY KEY,
"name" varchar NOT NULL,
"name" text NOT NULL CONSTRAINT events_event_name_maxlength CHECK (LENGTH("name") <= 64),
"address_id" integer NOT NULL,
"description" text NOT NULL,
"description" text NOT NULL CONSTRAINT events_event_description_maxlength CHECK (LENGTH("description") <= 4048),
"organizer_id" integer NOT NULL,
"start_at" timestamptz NOT NULL,
"end_at" timestamptz NOT NULL,
"created_at" timestamptz NOT NULL,
"updated_at" timestamptz NOT NULL,
"slug" varchar NOT NULL,
"slug" text NOT NULL CONSTRAINT events_event_slug_maxlength CHECK (LENGTH("slug") <= 128),
"status_id" integer NOT NULL
);

CREATE TABLE IF NOT EXISTS events.participant (
"id" SERIAL PRIMARY KEY,
"event_id" integer NOT NULL,
"user_id" integer NOT NULL,
"status_id" integer NOT NULL
);

CREATE TABLE IF NOT EXISTS common.status (
"id" SERIAL PRIMARY KEY,
"name" varchar(255) NOT NULL,
"name" text NOT NULL CONSTRAINT common_status_name_maxlength CHECK (LENGTH("name") <= 32),
"object_type_id" integer NOT NULL
);

CREATE TABLE IF NOT EXISTS events.tag (
"id" SERIAL PRIMARY KEY,
"name" varchar(255) NOT NULL
"name" text NOT NULL CONSTRAINT events_tag_name_maxlength CHECK (LENGTH("name") <= 64)
);

CREATE TABLE IF NOT EXISTS events.event_tag (
"event_id" integer NOT NULL,
"tag_id" integer NOT NULL
);

CREATE TABLE IF NOT EXISTS users.user (
"id" SERIAL PRIMARY KEY,
"name" varchar(255) NOT NULL,
"surname" varchar(255) NOT NULL,
"username" varchar(255) NOT NULL,
"password" varchar(255) NOT NULL,
"name" text NOT NULL CONSTRAINT users_user_name_maxlength CHECK (LENGTH(name) <= 64),
"surname" text NOT NULL CONSTRAINT users_user_surname_maxlength CHECK (LENGTH("surname") <= 64),
"username" text NOT NULL CONSTRAINT users_user_username_maxlength CHECK (LENGTH("username") <= 64),
"password" text NOT NULL,
"created_at" timestamptz NOT NULL,
"updated_at" timestamptz NOT NULL,
"role_id" integer NOT NULL,
"email" varchar(255) NOT NULL,
"email" text NOT NULL CONSTRAINT users_user_email_maxlength CHECK (LENGTH("email") <= 255),
"is_active" boolean NOT NULL,
"address_id" integer NOT NULL,
"phone" varchar(255)
"phone" text CONSTRAINT users_user_phone_maxlength CHECK (LENGTH("phone") <= 16)
);

CREATE TABLE IF NOT EXISTS events.parameter (
"id" SERIAL PRIMARY KEY,
"key" varchar(255) NOT NULL,
"value" varchar(255) NOT NULL
"key" text NOT NULL CONSTRAINT events_patameter_key_maxlength CHECK (LENGTH("key") <= 32),
"value" text NOT NULL CONSTRAINT events_patameter_value_maxlength CHECK (LENGTH("value") <= 64)
);

CREATE TABLE IF NOT EXISTS events.event_parameter (
"parameter_id" integer NOT NULL,
"event_id" integer NOT NULL
);

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

CREATE TABLE IF NOT EXISTS events.comment (
"id" SERIAL PRIMARY KEY,
"event_id" integer NOT NULL,
"content" varchar(255) NOT NULL,
"content" text NOT NULL CONSTRAINT events_comment_content_maxlength CHECK (LENGTH("content") <= 1024),
"created_at" timestamptz NOT NULL,
"user_id" integer NOT NULL
);

CREATE TABLE IF NOT EXISTS common.address (
"id" SERIAL PRIMARY KEY,
"city" varchar(255) NOT NULL,
"country" varchar(255) NOT NULL,
"street" varchar(255) NOT NULL,
"state" varchar(255) NOT NULL,
"zip_code" varchar(255)
"city" text NOT NULL CONSTRAINT common_address_city_maxlength CHECK (LENGTH("city") <= 64),
"country" text NOT NULL CONSTRAINT common_address_country_maxlength CHECK (LENGTH("country") <= 64),
"street" text NOT NULL CONSTRAINT common_address_street_maxlength CHECK (LENGTH("street") <= 64),
"state" text NOT NULL CONSTRAINT common_address_state_maxlength CHECK (LENGTH("state") <= 64),
"zip_code" text CONSTRAINT common_address_zip_code_maxlength CHECK (LENGTH("zip_code") <= 8)
);

CREATE TABLE IF NOT EXISTS common.image (
"id" SERIAL PRIMARY KEY,
"image_data" bytea NOT NULL,
"object_type_id" integer NOT NULL,
"object_id" integer NOT NULL
);

CREATE TABLE IF NOT EXISTS common.object_type (
"id" SERIAL PRIMARY KEY,
"name" varchar(255) NOT NULL
"name" text NOT NULL CONSTRAINT common_object_type_name_maxlength CHECK (LENGTH("name") <= 32)
);

CREATE TABLE IF NOT EXISTS users.user_interest (
"user_id" integer NOT NULL,
"interest_id" integer NOT NULL,
"level" integer NOT NULL
);

CREATE TABLE IF NOT EXISTS users.interest (
"id" SERIAL PRIMARY KEY,
"name" varchar(255) NOT NULL
"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");

ALTER TABLE events.event ADD FOREIGN KEY ("address_id") REFERENCES common.address ("id");

ALTER TABLE events.comment ADD FOREIGN KEY ("event_id") REFERENCES events.event ("id");

ALTER TABLE events.event ADD FOREIGN KEY ("organizer_id") REFERENCES users.user ("id");

ALTER TABLE events.participant ADD FOREIGN KEY ("event_id") REFERENCES events.event ("id");

ALTER TABLE events.participant ADD FOREIGN KEY ("user_id") REFERENCES users.user ("id");

ALTER TABLE events.comment ADD FOREIGN KEY ("user_id") REFERENCES users.user ("id");

ALTER TABLE common.image ADD FOREIGN KEY ("object_type_id") REFERENCES common.object_type ("id");

ALTER TABLE users.user_interest ADD FOREIGN KEY ("user_id") REFERENCES users.user ("id");

ALTER TABLE users.user ADD FOREIGN KEY ("address_id") REFERENCES common.address ("id");

ALTER TABLE events.participant ADD FOREIGN KEY ("status_id") REFERENCES common.status ("id");

ALTER TABLE events.event_parameter ADD FOREIGN KEY ("parameter_id") REFERENCES events.parameter ("id");

ALTER TABLE events.event_parameter ADD FOREIGN KEY ("event_id") REFERENCES events.event ("id");

ALTER TABLE events.event_tag ADD FOREIGN KEY ("tag_id") REFERENCES events.tag ("id");

ALTER TABLE events.event_tag ADD FOREIGN KEY ("event_id") REFERENCES events.event ("id");

ALTER TABLE common.status ADD FOREIGN KEY ("object_type_id") REFERENCES common.object_type ("id");

ALTER TABLE events.event ADD FOREIGN KEY ("status_id") REFERENCES common.status ("id");

ALTER TABLE users.user_interest ADD FOREIGN KEY ("interest_id") REFERENCES users.interest ("id");

INSERT INTO users.role ("id", "name") VALUES
(1, 'User'),
(2, 'Organiser'),
Expand All @@ -159,7 +159,7 @@ INSERT INTO common.status ("id", "name", "object_type_id") VALUES
(2, 'Wezmę udział', 2),
(3, 'Zrealizowano', 1),
(4, 'W trakcie realizacji', 1);

INSERT INTO events.tag ("id", "name") VALUES
(1, 'Technologia'),
(2, 'Sport'),
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
Loading

0 comments on commit 34c24f4

Please sign in to comment.