This repository has been archived by the owner on May 7, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
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 #1 from javaBin/db/setup-db
Setup db
- Loading branch information
Showing
5 changed files
with
87 additions
and
0 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
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,26 @@ | ||
package backend | ||
|
||
import com.zaxxer.hikari.HikariConfig | ||
import com.zaxxer.hikari.HikariDataSource | ||
import org.flywaydb.core.Flyway | ||
import org.postgresql.ds.PGSimpleDataSource | ||
|
||
fun runMigration() { | ||
val dataSource = HikariDataSource(HikariConfig().apply { | ||
username = "postgres" | ||
password = "example" | ||
dataSourceClassName = PGSimpleDataSource::class.qualifiedName | ||
addDataSourceProperty("databaseName", "workshop") | ||
addDataSourceProperty("serverName", "localhost") | ||
addDataSourceProperty("portNumber", "5432") | ||
maximumPoolSize = 10 | ||
minimumIdle = 1 | ||
idleTimeout = 10001 | ||
connectionTimeout = 1000 | ||
maxLifetime = 30001 | ||
}) | ||
Flyway | ||
.configure() | ||
.dataSource(dataSource) | ||
.load().migrate() | ||
} |
30 changes: 30 additions & 0 deletions
30
backend/app/src/main/resources/db/migration/V1__initial.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,30 @@ | ||
create table users | ||
( | ||
id int GENERATED ALWAYS AS IDENTITY primary key, | ||
first_name varchar, | ||
last_name varchar, | ||
email varchar, | ||
is_admin boolean | ||
); | ||
|
||
create table workshop | ||
( | ||
id int GENERATED ALWAYS AS IDENTITY primary key, | ||
title varchar not null, | ||
description varchar, | ||
start_time timestamp with time zone not null, | ||
end_time timestamp with time zone not null, | ||
capacity int not null | ||
); | ||
|
||
create table workshop_registration | ||
( | ||
id int GENERATED ALWAYS AS IDENTITY primary key, | ||
user_id int, | ||
workshop_id int, | ||
state int not null default 0, | ||
created_at timestamp with time zone not null default current_timestamp, | ||
updated_at timestamp with time zone not null default current_timestamp, | ||
constraint fk_workshop foreign key (workshop_id) references workshop (id), | ||
constraint fk_user foreign key (user_id) references users (id) | ||
); |
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,15 @@ | ||
services: | ||
database: | ||
container_name: database | ||
image: postgres:16.0 | ||
restart: on-failure | ||
ports: | ||
- "5432:5432" | ||
environment: | ||
POSTGRES_PASSWORD: example | ||
POSTGRES_DB: workshop | ||
volumes: | ||
- pgdata:/var/lib/postgres/data | ||
|
||
volumes: | ||
pgdata: |