Skip to content

Commit

Permalink
[TRAC-13] - Implement Flyway and create DDL scripts (V1,V2)
Browse files Browse the repository at this point in the history
  • Loading branch information
OleksandrRym committed Nov 26, 2024
1 parent 4fa754a commit c5888be
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 0 deletions.
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
<java.version>21</java.version>
<telegrambots-longpolling.version>7.10.0</telegrambots-longpolling.version>
<telegrambots-client.version>7.10.0</telegrambots-client.version>
<flyway.version>9.22.3</flyway.version>
</properties>

<dependencies>
Expand Down Expand Up @@ -50,6 +51,11 @@
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-core</artifactId>
<version>${flyway.version}</version>
</dependency>
</dependencies>

<build>
Expand Down
4 changes: 4 additions & 0 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ spring:
username: ${POSTGRESQL_USERNAME}
password: ${POSTGRESQL_PASSWORD}
driver-class-name: org.postgresql.Driver
flyway:
enabled: true
locations: classpath:db.migration
baseline-on-migrate: true
description:
start: "Welcome to TrackMyCoin 📈💰!
\n\nThis bot helps you track cryptocurrency prices
Expand Down
8 changes: 8 additions & 0 deletions src/main/resources/db.migration/V1__user-table-creating.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
CREATE TABLE users (
id BIGSERIAL PRIMARY KEY,
chat_id BIGINT NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL,
created_by VARCHAR(255),
updated_by VARCHAR(255)
);
13 changes: 13 additions & 0 deletions src/main/resources/db.migration/V2__monitoring-table-creating.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
CREATE TABLE monitorings (
id BIGSERIAL PRIMARY KEY,
ticker VARCHAR(100) NOT NULL,
target_price DECIMAL(18, 2) NOT NULL,
user_id BIGINT NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL,
created_by VARCHAR(255),
updated_by VARCHAR(255),
CONSTRAINT fk_monitorings_users FOREIGN KEY (user_id) REFERENCES users (id)
ON DELETE CASCADE
ON UPDATE CASCADE
);

0 comments on commit c5888be

Please sign in to comment.