Skip to content

Commit ea1cc38

Browse files
author
Lars Grahmann
committed
add flyway
1 parent 16ce036 commit ea1cc38

File tree

5 files changed

+67
-0
lines changed

5 files changed

+67
-0
lines changed

backend/build.gradle

+2
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ dependencies {
3131
implementation group: 'org.xerial', name: 'sqlite-jdbc', version: '3.46.1.3'
3232
implementation 'org.hibernate.orm:hibernate-core:6.4.1.Final'
3333
implementation 'org.hibernate.orm:hibernate-community-dialects:6.4.1.Final'
34+
implementation 'org.flywaydb:flyway-core:9.16.0'
35+
3436
// excel
3537
implementation 'org.apache.poi:poi:5.2.+'
3638
implementation 'org.apache.poi:poi-ooxml:5.2.+'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package org.eventplanner.config;
2+
3+
import org.flywaydb.core.Flyway;
4+
import org.springframework.context.annotation.Bean;
5+
import org.springframework.context.annotation.Configuration;
6+
7+
@Configuration
8+
public class FlywayConfig {
9+
10+
@Bean(initMethod = "migrate")
11+
public Flyway flyway() {
12+
return Flyway.configure()
13+
.dataSource("jdbc:sqlite:data/eventplanner.db", null, null)
14+
.load();
15+
}
16+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package org.eventplanner.events.adapter;
2+
3+
import java.util.List;
4+
import java.util.Optional;
5+
6+
import org.eventplanner.events.entities.Event;
7+
import org.eventplanner.events.values.EventKey;
8+
import org.springframework.lang.NonNull;
9+
10+
public interface EventJpaRepository {
11+
@NonNull
12+
Optional<Event> findByKey(EventKey key);
13+
14+
@NonNull
15+
List<Event> findAllByYear(int year);
16+
17+
@NonNull
18+
Event create(@NonNull Event event);
19+
20+
@NonNull
21+
Event update(@NonNull Event event);
22+
23+
void deleteByKey(EventKey key);
24+
25+
void deleteAllByYear(int year);
26+
}

backend/src/main/resources/application.yml

+5
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ security:
2727
spring:
2828
jpa:
2929
database-platform: org.hibernate.community.dialect.SQLiteDialect
30+
flyway:
31+
enabled: true
32+
locations: classpath:db/migration
33+
baseline-on-migrate: true
34+
url: jdbc:sqlite:data/eventplanner.db
3035
security:
3136
oauth2:
3237
client:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
-- Create Event table with JSON columns for nested entities
2+
CREATE TABLE events (
3+
key TEXT PRIMARY KEY,
4+
name TEXT NOT NULL,
5+
state TEXT,
6+
note TEXT,
7+
description TEXT,
8+
start TEXT NOT NULL,
9+
end TEXT NOT NULL,
10+
locations JSON,
11+
slots JSON,
12+
registrations JSON
13+
);
14+
15+
-- Create index for better query performance on frequently used columns
16+
CREATE INDEX idx_events_start ON events(start);
17+
CREATE INDEX idx_events_end ON events(end);
18+
CREATE INDEX idx_events_state ON events(state);

0 commit comments

Comments
 (0)