Skip to content

Commit

Permalink
Fix issues with H2 and reserved keywords
Browse files Browse the repository at this point in the history
  • Loading branch information
mmwinther committed Dec 15, 2023
1 parent 859efce commit d7d9a98
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# custom properties used when "h2-inmemory" Profile is used
spring.datasource.url=jdbc:h2:mem:testdb;DB_CLOSE_ON_EXIT=FALSE;MODE=MySQL
spring.datasource.url=jdbc:h2:mem:testdb;DB_CLOSE_ON_EXIT=FALSE;MODE=MySQL;NON_KEYWORDS=user
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import jakarta.persistence.Column;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.MappedSuperclass;
import jakarta.persistence.PreUpdate;
Expand All @@ -15,7 +16,7 @@
@MappedSuperclass
public abstract class BaseEntity {
@Id
@GeneratedValue
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Column(nullable = false)
private final String uuid;
Expand Down Expand Up @@ -71,7 +72,8 @@ public boolean equals(Object other) {
}

/**
* Any initialisation needed after Hibernate has recreated instance. Typically initialise any transient fields.
* Any initialisation needed after Hibernate has recreated instance. Typically
* initialise any transient fields.
*/
public void init() {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,27 @@
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;

@Entity
public class SearchWords {
@Id
@GeneratedValue
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@Column(nullable = false)
Date timeStamp;

@Column(nullable = false)
boolean hit;

@Column(nullable = false)
String searchString;

public SearchWords() {
}

public SearchWords(String searchString, boolean hit) {
this.timeStamp = new Date();
this.searchString = searchString;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# custom properties used when "h2-inmemory" Profile is used
spring.datasource.url=jdbc:h2:mem:testdb;DB_CLOSE_ON_EXIT=FALSE;MODE=MySQL;NON_KEYWORDS=user
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
ALTER TABLE "user" ADD email VARCHAR(255) NULL;
ALTER TABLE "user" ADD phone VARCHAR(255) NULL;
ALTER TABLE "USER" ADD email VARCHAR(255) NULL;
ALTER TABLE "USER" ADD phone VARCHAR(255) NULL;
12 changes: 6 additions & 6 deletions klass-shared/src/main/resources/db/migration/V1__init.sql
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ CREATE TABLE subscription
PRIMARY KEY (id)
);

CREATE TABLE "user"
CREATE TABLE "USER"
(
id BIGINT NOT NULL auto_increment,
deleted BIT NOT NULL,
Expand Down Expand Up @@ -205,10 +205,10 @@ CREATE INDEX ct_target_idx ON correspondence_table (target_id);
ALTER TABLE subscriber
ADD CONSTRAINT subscriber_email_idx UNIQUE (email);

ALTER TABLE "user"
ALTER TABLE "USER"
ADD CONSTRAINT user_username_idx UNIQUE (username);

CREATE INDEX user_fullname_idx ON "user" (fullname);
CREATE INDEX user_fullname_idx ON "USER" (fullname);

ALTER TABLE user_favorites
ADD CONSTRAINT uk_dk8ngwbk9dgeuegrx1nuktdv1 UNIQUE (favorites_id);
Expand All @@ -231,7 +231,7 @@ ALTER TABLE classification_series

ALTER TABLE classification_series
ADD CONSTRAINT fk_jefvdo01kn4kq98m64ajli6y5 FOREIGN KEY (contact_person_id)
REFERENCES "user" (id);
REFERENCES "USER" (id);

ALTER TABLE classification_series_statistical_units
ADD CONSTRAINT fk_rfx4t7rjg3hykfr39xi8dvrdu FOREIGN KEY (statistical_units_id)
Expand Down Expand Up @@ -283,7 +283,7 @@ ALTER TABLE statistical_classification

ALTER TABLE statistical_classification
ADD CONSTRAINT fk_12hsnu91tsf1c8b4697tv1bts FOREIGN KEY (contact_person_id)
REFERENCES "user" (id);
REFERENCES "USER" (id);

ALTER TABLE statistical_classification
ADD CONSTRAINT fk_ie31cb245vkf1vhswws053s29 FOREIGN KEY (classification_id)
Expand Down Expand Up @@ -311,4 +311,4 @@ ALTER TABLE user_favorites

ALTER TABLE user_favorites
ADD CONSTRAINT fk_dx271ymxhckcafibaqijpda8h FOREIGN KEY (user_id) REFERENCES
"user" (id);
"USER" (id);
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ CREATE TABLE user_favorites
PRIMARY KEY (id)
);
ALTER TABLE user_favorites ADD CONSTRAINT fk_favorite_id FOREIGN KEY (favorites_id) REFERENCES classification_series (id);
ALTER TABLE user_favorites ADD CONSTRAINT fk_user_id FOREIGN KEY (user_id) REFERENCES "user" (id);
ALTER TABLE user_favorites ADD CONSTRAINT fk_user_id FOREIGN KEY (user_id) REFERENCES "USER" (id);
INSERT INTO user_favorites (user_id, favorites_id) SELECT
user_id,
favorites_id
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
-- Only classes(tables) implementing SoftDeletable shall have deleted column

ALTER TABLE classification_family DROP COLUMN deleted;
ALTER TABLE classification_item DROP COLUMN deleted;
ALTER TABLE correspondence_map DROP COLUMN deleted;
ALTER TABLE level DROP COLUMN deleted;
ALTER TABLE statistical_unit DROP COLUMN deleted;
ALTER TABLE subscriber DROP COLUMN deleted;
ALTER TABLE subscription DROP COLUMN deleted;
ALTER TABLE "user" DROP COLUMN deleted;
ALTER TABLE "USER" DROP COLUMN deleted;

0 comments on commit d7d9a98

Please sign in to comment.