Skip to content

Commit

Permalink
Spring upgrade, property cleanup & Flyway reset (#510)
Browse files Browse the repository at this point in the history
* Upgrade Spring and move to pure flyway migration strategy

* Enable Flyway clean() for dev profile and clean up properties with default values

* Fix missing mail property in production profile

* Change some columns to TEXT type

* Update postgres Docker readme for easier default setup

* Remove leftover clearAll method
  • Loading branch information
skamoen authored and martijnjanssen committed Dec 9, 2019
1 parent d54ba89 commit eb9840b
Show file tree
Hide file tree
Showing 14 changed files with 131 additions and 79 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ The API is a Spring based application to suit the needs of a LAN-party.

### Docker
The postgres install can be quite a hassle, docker can also be used for this.
After docker is installed, create a postgres container: `docker run --name lancie_postgres -p 5432:5432 -d postgres`.
Connect to the running container with `docker exec -tiu postgres lancie_postgres psql` and create a new database with `CREATE DATABASE lancie-dev;`.
After docker is installed, create a postgres container: `docker run --name lancie_postgres -e POSTGRES_DB=areafiftylan -p 5432:5432 -d postgres`.
This creates a new database called "areafiftylan".
You can connect to this database on localhost:5432 with user `postgres` and blank password.
This is everything you need to initially start the LANcie-API, if, at any later point, you need to connect to the database, you can enter `docker exec -tiu postgres lancie_postgres psql -d lancie-dev`.
The next time you want to start developing, a `docker start lancie_postgres` is enough. To stop the container again, `docker stop lancie_postgres` will do.

Expand Down
9 changes: 3 additions & 6 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
plugins {
id 'org.springframework.boot' version '2.1.9.RELEASE'
id 'org.springframework.boot' version '2.2.2.RELEASE'
id 'io.spring.dependency-management' version '1.0.8.RELEASE'
id 'java'
id 'idea'
id 'eclipse'
id 'jacoco'
id "io.freefair.lombok" version "4.1.6"
}

jar {
Expand Down Expand Up @@ -35,13 +36,9 @@ dependencies {
compile("org.springframework.boot:spring-boot-starter-json")
compile("org.flywaydb:flyway-core")

compile("com.google.guava:guava:23.5-jre")
compile("com.google.guava:guava:28.1-jre")
compile("nl.stil4m:mollie-api:2.7.0")
compile("net.logstash.logback:logstash-logback-encoder:4.11")
compile("javax.xml.bind:jaxb-api:2.3.0")

compileOnly("org.projectlombok:lombok:1.18.2")
annotationProcessor("org.projectlombok:lombok:1.18.2")

runtime("org.hsqldb:hsqldb")
runtime("org.postgresql:postgresql")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

@Entity
@Getter
@Table(name = "orders")
public class Order {

@Id
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/ch/wisv/areafiftylan/users/model/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
@Data
@RequiredArgsConstructor
@NoArgsConstructor
@Table(uniqueConstraints = { @UniqueConstraint(name = "email", columnNames = { "email" }) })
@Table(name = "users", uniqueConstraints = { @UniqueConstraint(name = "email", columnNames = { "email" }) })
public class User implements Serializable, UserDetails {

@NonNull
Expand Down
22 changes: 22 additions & 0 deletions src/main/java/ch/wisv/areafiftylan/utils/TestDataCleaner.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package ch.wisv.areafiftylan.utils;

import lombok.extern.slf4j.Slf4j;
import org.flywaydb.core.Flyway;
import org.springframework.boot.autoconfigure.flyway.FlywayMigrationStrategy;
import org.springframework.context.annotation.Profile;
import org.springframework.stereotype.Component;

@Component
@Slf4j
@Profile("dev")
public class TestDataCleaner implements FlywayMigrationStrategy {

@Override
public void migrate(Flyway flyway) {
log.debug("Cleaning data");
flyway.clean();
log.debug("Initalizing migrations");
flyway.migrate();
}

}
9 changes: 5 additions & 4 deletions src/main/java/ch/wisv/areafiftylan/utils/TestDataRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,9 @@
import ch.wisv.areafiftylan.web.tournament.model.TournamentType;
import ch.wisv.areafiftylan.web.tournament.service.TournamentRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.context.event.ApplicationStartedEvent;
import org.springframework.context.annotation.Profile;
import org.springframework.context.event.EventListener;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Component;

Expand All @@ -63,7 +64,7 @@

@Component
@Profile("dev")
public class TestDataRunner implements CommandLineRunner {
public class TestDataRunner {
private final UserRepository accountRepository;
private final TicketRepository ticketRepository;
private final SeatService seatService;
Expand Down Expand Up @@ -104,8 +105,8 @@ public TestDataRunner(UserRepository accountRepository, TicketRepository ticketR
this.tournamentRepository = tournamentRepository;
}

@Override
public void run(String... evt) throws Exception {
@EventListener(ApplicationStartedEvent.class)
public void insertTestData() {
//region Users
LocalDate localDate = LocalDate.of(2000, 1, 2);

Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

12 changes: 12 additions & 0 deletions src/main/resources/config/application-createsql.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
spring:
flyway:
enabled: false
jpa:
properties:
javax:
persistence:
schema-generation:
create-source: metadata
scripts:
action: create
create-target: src/main/resources/ddl_jpa_creation.sql
12 changes: 9 additions & 3 deletions src/main/resources/config/application-dev.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
spring.flyway.enabled: false
spring.jpa.hibernate.ddl-auto: create

## AREA FIFTYLAN SETTINGS
a5l:
paymentReturnUrl: https://localhost:5100/order-check
Expand All @@ -19,3 +16,12 @@ a5l:
orderKeepAlive: 15
ratelimit:
enabled: false

logging:
level:
ch.wisv.areafiftylan: DEBUG

management:
health:
mail:
enabled: false
11 changes: 3 additions & 8 deletions src/main/resources/config/application-production.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
spring.jpa.hibernate.ddl-auto: validate
spring.jpa.properties.hibernate.hbm2ddl.auto: none

logging:
file: /tmp/logs/lancie-api.log
file:
name: /tmp/logs/lancie-api.log

## AREA FIFTYLAN SETTINGS
a5l:
Expand All @@ -15,6 +13,7 @@ a5l:
sender: LANcie <[email protected]>
contact: LANcie <[email protected]>
confirmUrl: https://areafiftylan.nl/register-confirm
year: 2020
ratelimit:
enabled: true
minute: 10
Expand All @@ -23,7 +22,3 @@ a5l:
ticketLimit: 220
orderKeepAlive: 15
year: 2019
spring:
flyway:
enabled: true
locations: ch/wisv/areafiftylan/utils/db/migration
23 changes: 6 additions & 17 deletions src/main/resources/config/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,14 @@ spring:
main:
allow-bean-definition-overriding: true
thymeleaf:
check-template-location: true
prefix: classpath:/templates/
suffix: .html
mode: HTML5
encoding: UTF-8
servlet:
content-type: text/html

datasource.driverClassName: org.postgresql.Driver
data.jpa.repositories.enabled: true

jpa:
show-sql: false
database-platform: org.hibernate.dialect.PostgreSQLDialect
generate-ddl: true
properties:
hibernate.default_schema: public

jackson:
date-format: com.fasterxml.jackson.databind.util.ISO8601DateFormat
hibernate:
ddl-auto: validate
open-in-view: true

logging:
level:
Expand All @@ -31,7 +19,8 @@ logging:
org.hibernate.SQL: ERROR
pattern:
console: "%d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36} - %msg%n"
file: logs/lancie-api.log
file:
name: logs/lancie-api.log

server:
port: 9000
Expand All @@ -45,4 +34,4 @@ management:
base-path: /management
endpoint:
logfile:
enabled: true
enabled: true
66 changes: 66 additions & 0 deletions src/main/resources/db/migration/V1_0__init.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
create sequence hibernate_sequence start 1 increment 1;
create table authentication_token (id int8 not null, primary key (id));
create table banner (id int8 not null, end_date date, start_date date, text text, primary key (id));
create table committee_member (position int8 not null, function varchar(255), icon varchar(255), name varchar(255), primary key (position));
create table consumption (id int8 not null, name varchar(255), primary key (id));
create table consumption_map (id int8 not null, ticket_id int8, primary key (id));
create table consumption_map_consumptions_made (consumption_map_id int8 not null, consumptions_made_id int8 not null);
create table expired_order (id int8 not null, created_at varchar(255), created_by varchar(255), expired_at varchar(255), number_of_tickets int4 not null, primary key (id));
create table faq_pair (id int8 not null, answer text, question varchar(255), primary key (id));
create table orders (id int8 not null, creation_date_time timestamp, reference varchar(255), status int4, user_id int8, primary key (id));
create table orders_tickets (order_id int8 not null, tickets_id int8 not null, primary key (order_id, tickets_id));
create table password_reset_token (id int8 not null, primary key (id));
create table profile (id int8 not null, address varchar(255), birthday date, city varchar(255), display_name varchar(255), first_name varchar(255), gender int4, last_name varchar(255), notes varchar(255), phone_number varchar(255), zipcode varchar(255), primary key (id));
create table rfidlink (id int8 not null, rfid varchar(255), ticket_id int8, primary key (id));
create table seat (id int8 not null, locked boolean not null, seat_group varchar(255), seat_number int4 not null, ticket_id int8, primary key (id));
create table sponsor (id int8 not null, image_name varchar(255), name varchar(255), type int4, website varchar(255), primary key (id));
create table subscription (id int8 not null, email varchar(255), primary key (id));
create table team (id int8 not null, size int4 not null, team_name varchar(255) not null, captain_id int8 not null, primary key (id));
create table team_members (team_id int8 not null, members_id int8 not null, primary key (team_id, members_id));
create table team_invite_token (id int8 not null, team_id int8 not null, primary key (id));
create table ticket (id int8 not null, valid boolean not null, owner_id int8, type_id int8, primary key (id));
create table ticket_enabled_options (ticket_id int8 not null, enabled_options_id int8 not null, primary key (ticket_id, enabled_options_id));
create table ticket_option (id int8 not null, name varchar(255), price float4 not null, primary key (id));
create table ticket_transfer_token (id int8 not null, ticket_id int8 not null, primary key (id));
create table ticket_type (id int8 not null, buyable boolean not null, deadline timestamp, name varchar(255), number_available int4 not null, price float4 not null, text varchar(255), primary key (id));
create table ticket_type_possible_options (ticket_type_id int8 not null, possible_options_id int8 not null, primary key (ticket_type_id, possible_options_id));
create table token (id int8 not null, expirable BOOLEAN DEFAULT TRUE not null, expiry_date timestamp, revoked BOOLEAN DEFAULT FALSE not null, token varchar(255), used BOOLEAN DEFAULT FALSE not null, user_id int8 not null, primary key (id));
create table tournament (id int8 not null, button_image_path varchar(255), button_title varchar(255), description text, format varchar(255), header_title varchar(255), type int4, sponsor_id int8, primary key (id));
create table tournament_prize (tournament_id int8 not null, prizes varchar(255));
create table user_role (user_id int8 not null, roles varchar(255));
create table users (id int8 not null, account_non_expired boolean not null, account_non_locked boolean not null, credentials_non_expired boolean not null, email varchar(255) not null, enabled boolean not null, password_hash varchar(255) not null, profile_id int8, primary key (id));
create table verification_token (id int8 not null, primary key (id));
alter table if exists orders_tickets add constraint UK_lxwrvh4y2ons9ohgu50msfbly unique (tickets_id);
alter table if exists seat add constraint seatConstraint unique (seat_group, seat_number);
alter table if exists subscription add constraint UK_r9kv3a5fkv7vnvu8bbpulavmk unique (email);
alter table if exists team add constraint teamName unique (team_name);
alter table if exists users add constraint email unique (email);
alter table if exists authentication_token add constraint FKdbv62go71ree32qv0bm6gqam2 foreign key (id) references token;
alter table if exists consumption_map add constraint FKsrrxfhrofqjjcsb860h16dpop foreign key (ticket_id) references ticket;
alter table if exists consumption_map_consumptions_made add constraint FKag9n6oxcuocwnc1yc9tr1w3cw foreign key (consumptions_made_id) references consumption;
alter table if exists consumption_map_consumptions_made add constraint FKqrs02quftjk84a7uojo36wokd foreign key (consumption_map_id) references consumption_map;
alter table if exists orders add constraint FK32ql8ubntj5uh44ph9659tiih foreign key (user_id) references users;
alter table if exists orders_tickets add constraint FK4fqm8urjjqfiwct4oj14xkfrl foreign key (tickets_id) references ticket;
alter table if exists orders_tickets add constraint FKjoggp5iyq5fqbtxi5r1m2wlty foreign key (order_id) references orders;
alter table if exists password_reset_token add constraint FKri9g6njpisvtpqe430bynv4lq foreign key (id) references token;
alter table if exists rfidlink add constraint FK2f30uyki11lmtg56q0cbqw6pk foreign key (ticket_id) references ticket;
alter table if exists seat add constraint FK8ngrgsadp7q1lcakg3kkdmvqj foreign key (ticket_id) references ticket;
alter table if exists team add constraint FKb1pjk4pg0yi1qvw0i7pvfy3us foreign key (captain_id) references users;
alter table if exists team_members add constraint FK4rl09ugxbntgyfhogal3s67ji foreign key (members_id) references users;
alter table if exists team_members add constraint FKb3toat7ors5scfmd3n69dhmr1 foreign key (team_id) references team;
alter table if exists team_invite_token add constraint FKa5gxt5guatw99qkswjf6pkbl3 foreign key (team_id) references team;
alter table if exists team_invite_token add constraint FK3597euynm1cuvaltyyprwjm4e foreign key (id) references token;
alter table if exists ticket add constraint FKjgquudbb9q93fl5odb28lmscj foreign key (owner_id) references users;
alter table if exists ticket add constraint FKnk40xmmqnx78naomux703i9vs foreign key (type_id) references ticket_type;
alter table if exists ticket_enabled_options add constraint FKmyjy3uibhokscu0a12b0kciwr foreign key (enabled_options_id) references ticket_option;
alter table if exists ticket_enabled_options add constraint FKdi94eaxwrpnpightqkyg3okse foreign key (ticket_id) references ticket;
alter table if exists ticket_transfer_token add constraint FKf2oeyewgv1csjxaag5c0weoa1 foreign key (ticket_id) references ticket;
alter table if exists ticket_transfer_token add constraint FK6b9awma746y1u2kc25hifqs0s foreign key (id) references token;
alter table if exists ticket_type_possible_options add constraint FKc0rw0dtfj7duebxsni3l6u084 foreign key (possible_options_id) references ticket_option;
alter table if exists ticket_type_possible_options add constraint FKgihp1b7p36hygc2ar4ilodgef foreign key (ticket_type_id) references ticket_type;
alter table if exists token add constraint FKj8rfw4x0wjjyibfqq566j4qng foreign key (user_id) references users;
alter table if exists tournament add constraint FK3yc1a3c3e0cvydcrgl4ih0rne foreign key (sponsor_id) references sponsor;
alter table if exists tournament_prize add constraint FKex38yydummrcremcnmlff60su foreign key (tournament_id) references tournament;
alter table if exists user_role add constraint FKj345gk1bovqvfame88rcx7yyx foreign key (user_id) references users;
alter table if exists users add constraint FK5q3e9303ap1wvtia6sft7ht1s foreign key (profile_id) references profile;
alter table if exists verification_token add constraint FK92nvkrl137qsd36ryx66f1mfe foreign key (id) references token;

0 comments on commit eb9840b

Please sign in to comment.