Skip to content

Commit

Permalink
added DB
Browse files Browse the repository at this point in the history
  • Loading branch information
Szer committed Sep 27, 2023
1 parent 74a7854 commit f44898f
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 1 deletion.
17 changes: 16 additions & 1 deletion .github/workflows/deploy-azure-acr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,29 @@ on:
permissions:
contents: read

env:
SQLFLUFF_DIALECT: postgres
DOCKER_IMAGE: redgate/flyway
SCHEMAS: public

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v2


- name: Apply migrations
run: >-
docker run --rm
--volume ${{ github.workspace }}/migrations:/src/migrations:ro
"${{ env.DOCKER_IMAGE }}"
-url="${{ secrets.DB_PROD_URL }}"
-user="${{ secrets.DB_PROD_USERNAME }}"
-password="${{ secrets.DB_PROD_PASSWORD }}"
migrate -schemas="${{ env.SCHEMAS }}"
- name: 'Docker Login'
uses: azure/docker-login@v1
with:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
**/bin
.idea
.env
flyway.conf
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
Database setup

```postgresql
CREATE ROLE vahter_bot_ban_service WITH LOGIN PASSWORD 'vahter_bot_ban_service';
GRANT vahter_bot_ban_service TO postgres;
CREATE DATABASE vahter_bot_ban OWNER vahter_bot_ban_service ENCODING 'UTF8';
GRANT ALL ON DATABASE vahter_bot_ban TO vahter_bot_ban_service;
GRANT USAGE, CREATE ON SCHEMA public TO vahter_bot_ban_service;
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
```

Run migrations

```
flyway -configFiles=flyway.local.conf migrate
```
7 changes: 7 additions & 0 deletions flyway.conf.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
flyway.locations=filesystem:./src/migrations
flyway.url=jdbc:postgresql://localhost:5433/vahter_bot_ban
flyway.schemas=public
flyway.user=vahter_bot_ban_service
flyway.password=vahter_bot_ban_service
flyway.baselineOnMigrate=true
flyway.baselineVersion=0
2 changes: 2 additions & 0 deletions src/VahterBanBot/VahterBanBot.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Dapper" Version="2.0.151" />
<PackageReference Include="Giraffe" Version="6.2.0" />
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.21.0" />
<PackageReference Include="Microsoft.ApplicationInsights.PerfCounterCollector" Version="2.21.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="7.0.11" />
<PackageReference Include="Microsoft.Extensions.Logging.ApplicationInsights" Version="2.21.0" />
<PackageReference Include="Npgsql" Version="7.0.6" />
<PackageReference Include="Telegram.Bot" Version="19.0.0" />
</ItemGroup>

Expand Down
35 changes: 35 additions & 0 deletions src/migrations/V1__initial.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
CREATE TABLE "user"
(
id BIGINT NOT NULL
PRIMARY KEY,
username TEXT NULL,

banned_by BIGINT NULL
CONSTRAINT user_banned_by_fkey
REFERENCES "user" (id),
banned_at TIMESTAMPTZ NULL,
ban_reason TEXT NULL,

created_at TIMESTAMPTZ NOT NULL DEFAULT timezone('utc'::TEXT, NOW()),
updated_at TIMESTAMPTZ NOT NULL DEFAULT timezone('utc'::TEXT, NOW())
);

CREATE UNIQUE INDEX "user_username_uindex"
ON "user" (username);

CREATE INDEX "user_banned_by_index"
ON "user" (banned_by);

CREATE TABLE "message"
(
id INT NOT NULL PRIMARY KEY,
user_id BIGINT NOT NULL
CONSTRAINT message_user_id_fkey
REFERENCES "user" (id)
ON DELETE CASCADE,

created_at TIMESTAMPTZ NOT NULL DEFAULT timezone('utc'::TEXT, NOW())
);

CREATE INDEX "message_user_id_index"
ON "message" (user_id);

0 comments on commit f44898f

Please sign in to comment.