Skip to content

Commit 06c826e

Browse files
authored
Fix an issue in a fresh MySQL / Mariadb install with the migrations. (#79)
1 parent ace4a0b commit 06c826e

File tree

12 files changed

+39
-26
lines changed

12 files changed

+39
-26
lines changed

fintrack-api/src/main/resources/application-mysql.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ datasources:
66
password: ${DATABASE_PASSWORD:fintrack}
77
dialect: mysql
88

9+
jpa:
10+
default:
11+
properties:
12+
hibernate:
13+
dialect: org.hibernate.dialect.MySQLDialect
914
flyway:
1015
datasources:
1116
default:

jpa-repository/src/main/java/com/jongsoft/finance/jpa/core/entity/SettingJpa.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
package com.jongsoft.finance.jpa.core.entity;
22

3-
import jakarta.persistence.*;
4-
53
import com.jongsoft.finance.core.SettingType;
6-
4+
import jakarta.persistence.*;
75
import lombok.Builder;
86
import lombok.Getter;
97

@@ -17,7 +15,7 @@ public class SettingJpa extends EntityJpa {
1715
@Enumerated(EnumType.STRING)
1816
private SettingType type;
1917

20-
@Column(name = "`value`")
18+
@Column(name = "setting_val")
2119
private String value;
2220

2321
public SettingJpa() {

jpa-repository/src/main/java/com/jongsoft/finance/jpa/query/expression/FieldCondition.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import com.jongsoft.finance.jpa.query.BooleanExpression;
44
import jakarta.persistence.Query;
55

6+
import java.util.function.Supplier;
7+
68
record FieldCondition(String tableAlias, String fieldId, String field, FieldEquation equation, Object value) implements BooleanExpression {
79
@Override
810
public String hqlExpression() {
@@ -16,14 +18,19 @@ public String hqlExpression() {
1618
case LIKE -> "LIKE";
1719
};
1820

21+
Supplier<String> fieldFunc = () -> "%s%s".formatted(actualAlias, field);
22+
if (value instanceof String && equation == FieldEquation.LIKE) {
23+
fieldFunc = () -> "lower(%s%s)".formatted(actualAlias, field);
24+
}
25+
1926
if (equation == FieldEquation.IN) {
20-
return " %s%s IN(:%s) ".formatted(actualAlias, field, fieldId);
27+
return " %s IN(:%s) ".formatted(fieldFunc.get(), fieldId);
2128
} else if (equation == FieldEquation.NIN) {
22-
return " %s%s NOT IN(:%s) ".formatted(actualAlias, field, fieldId);
29+
return " %s NOT IN(:%s) ".formatted(fieldFunc.get(), fieldId);
2330

2431
}
2532

26-
return " %s%s %s :%s ".formatted(actualAlias, field, comparator, fieldId);
33+
return " %s %s :%s ".formatted(fieldFunc.get(), comparator, fieldId);
2734
}
2835

2936
@Override

jpa-repository/src/main/java/com/jongsoft/finance/jpa/rule/RuleChangeJpa.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
package com.jongsoft.finance.jpa.rule;
22

3-
import jakarta.persistence.*;
4-
53
import com.jongsoft.finance.core.RuleColumn;
64
import com.jongsoft.finance.jpa.core.entity.EntityJpa;
7-
5+
import jakarta.persistence.*;
86
import lombok.Builder;
97
import lombok.Getter;
108

@@ -16,7 +14,7 @@ public class RuleChangeJpa extends EntityJpa {
1614
@Enumerated(value = EnumType.STRING)
1715
private RuleColumn field;
1816

19-
@Column(name = "`value`")
17+
@Column(name = "change_val")
2018
private String value;
2119

2220
@ManyToOne

jpa-repository/src/main/java/com/jongsoft/finance/jpa/transaction/TransactionFilterCommand.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public TransactionProvider.FilterCommand categories(Sequence<EntityRef> value) {
4949

5050
@Override
5151
public TransactionProvider.FilterCommand contracts(Sequence<EntityRef> value) {
52-
query().fieldEqOneOf("contracts.id", ID_REDUCER.apply(value).toArray());
52+
query().fieldEqOneOf("contract.id", ID_REDUCER.apply(value).toArray());
5353
return this;
5454
}
5555

@@ -65,9 +65,9 @@ public TransactionProvider.FilterCommand name(String value, boolean exact) {
6565
subQuery.fieldNull("deleted")
6666
.from("transactions");
6767
if (exact) {
68-
subQuery.fieldEq("name", value);
68+
subQuery.fieldEq("account.name", value);
6969
} else {
70-
subQuery.fieldLike("name", value);
70+
subQuery.fieldLike("account.name", value.toLowerCase());
7171
}
7272
});
7373
return this;
@@ -77,8 +77,8 @@ public TransactionProvider.FilterCommand name(String value, boolean exact) {
7777
public TransactionProvider.FilterCommand description(String value, boolean exact) {
7878
query().condition(
7979
Expressions.or(
80-
Expressions.fieldLike("e", "description", value),
81-
Expressions.fieldLike("t", "description", value))
80+
Expressions.fieldLike("e", "description", value.toLowerCase()),
81+
Expressions.fieldLike("t", "description", value.toLowerCase()))
8282
);
8383

8484
return this;

jpa-repository/src/main/resources/db/migration/V20190306074220__add_rule_structures.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ create table rule_change
2626
(
2727
id bigint not null auto_increment,
2828
field int not null,
29-
"value" varchar(255) not null,
29+
`value` varchar(255) not null,
3030
rule_id bigint not null,
3131

3232
constraint pk_rule_change primary key (id),

jpa-repository/src/main/resources/db/migration/V20190814085724__add_application_settings.sql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ create table setting
33
id bigint not null auto_increment,
44
name varchar(255) not null,
55
type varchar(255) not null,
6-
"value" varchar(255) not null,
6+
`value` varchar(255) not null,
77

88
constraint pk_setting primary key (id),
99
constraint uq_setting unique (name)
1010
);
1111

12-
insert into setting (id, name, type, "value")
12+
insert into setting (id, name, type, `value`)
1313
values (null, 'RegistrationOpen', 'FLAG', '1'),
1414
(null, 'ImportOutdated', 'FLAG', '1'),
1515
(null, 'AnalysisBudgetMonths', 'NUMBER', '3');
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
insert into setting (id, name, type, "value") values
1+
insert into setting (id, name, type, `value`) values
22
(null, 'AnalysisBudgetDeviation', 'NUMBER', '0.25'),
33
(null, 'AutocompleteLimit', 'NUMBER', '10'),
44
(null, 'RecordSetPageSize', 'NUMBER', '20');
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
update setting
2-
set "value" = 'true'
3-
where "value" = '1'
2+
set `value` = 'true'
3+
where `value` = '1'
44
and type = 'FLAG';
55

66
update setting
7-
set "value" = 'false'
8-
where "value" = '0'
7+
set `value` = 'false'
8+
where `value` = '0'
99
and type = 'FLAG';
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
alter table rule_change
2+
change `value` change_val varchar(255);
3+
4+
alter table setting
5+
change `value` setting_val varchar(255);

0 commit comments

Comments
 (0)