Skip to content

Commit

Permalink
[TRAC - 13] - Implement Flyway and add DDL(V1, V2) (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
OleksandrRym authored Dec 5, 2024
1 parent d6ef3c0 commit c3cbc9d
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 1 deletion.
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
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class TelegramBotConsumer implements LongPollingSingleThreadUpdateConsume
public void consume(Update update) {
if (update.hasMessage() && update.getMessage().hasText()) {
logUpdateMessage(update.getMessage());
commandProcessorRegistry.get(update.getMessage().getText()).process(update);
commandProcessorRegistry.get(update.getMessage().getText()).process(update);
}
}

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
9 changes: 9 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,9 @@
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)
);
14 changes: 14 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,14 @@
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 c3cbc9d

Please sign in to comment.