Skip to content

Commit

Permalink
Adjust Flyway versioning and rename tables to a common convention
Browse files Browse the repository at this point in the history
  • Loading branch information
semotpan committed Apr 20, 2024
1 parent 95c8b05 commit a1b1750
Show file tree
Hide file tree
Showing 24 changed files with 52 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* Defines the domain model representation of expense category
*/
@Entity
@Table(name = "expensecategory")
@Table(name = "expense_category")
@Getter
@ToString
@EqualsAndHashCode
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ public enum DefaultCategories {
CLOTHING("Clothing"),
FUN("Fun"),
PERSONAL("Personal"),
LOAN("Loan"),
BUSINESS("Business"),
OTHER("Other");

public final String text;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* Defines the domain model representation of income source
*/
@Entity
@Table(name = "incomesource")
@Table(name = "income_source")
@Getter
@ToString
@EqualsAndHashCode
Expand Down
4 changes: 2 additions & 2 deletions server/src/main/java/io/myfinbox/shared/PaymentType.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public enum PaymentType {

public static boolean containsValue(String value) {
for (var b : values()) {
if (b.value.equals(value))
if (b.value.equalsIgnoreCase(value))
return true;
}

Expand All @@ -22,7 +22,7 @@ public static boolean containsValue(String value) {

public static PaymentType fromValue(String value) {
for (var b : values()) {
if (b.value.equals(value))
if (b.value.equalsIgnoreCase(value))
return b;
}

Expand Down
6 changes: 4 additions & 2 deletions server/src/main/java/io/myfinbox/spendingplan/domain/Jar.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@
import javax.money.MonetaryAmount;
import java.io.Serializable;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.time.Instant;
import java.util.UUID;

import static io.myfinbox.shared.Guards.*;
import static lombok.AccessLevel.PRIVATE;

@Entity
@Table(name = "spendingjars")
@Table(name = "spending_jars")
@Getter
@ToString
@EqualsAndHashCode
Expand Down Expand Up @@ -75,7 +76,8 @@ private void setAmountToReach(MonetaryAmount amountToReach) {

@JsonIgnore
public BigDecimal getAmountToReachAsNumber() {
return amountToReach.getNumber().numberValue(BigDecimal.class);
return amountToReach.getNumber().numberValue(BigDecimal.class)
.setScale(2, RoundingMode.HALF_UP);
}

@JsonIgnore
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import static lombok.AccessLevel.PRIVATE;

@Entity
@Table(name = "spendingplans")
@Table(name = "spending_plans")
@Getter
@ToString
@EqualsAndHashCode(callSuper = false)
Expand Down
2 changes: 2 additions & 0 deletions server/src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ server.servlet.context-path=/api
spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.web.servlet.error.ErrorMvcAutoConfiguration
spring.jackson.default-property-inclusion=non_empty
spring.web.resources.add-mappings=false
#
# Database props
spring.datasource.url=jdbc:postgresql://${POSTGRES_HOST:localhost}:${POSTGRES_PORT:5432}/${POSTGRES_DB_NAME:myfinboxdb}?currentSchema=server
spring.datasource.username=${POSTGRES_DB_USER:application}
Expand All @@ -16,4 +17,5 @@ spring.jpa.properties.hibernate.order_inserts=true
spring.jpa.properties.hibernate.order_updates=true
spring.jpa.properties.hibernate.default_schema=server
#
#
spring.modulith.events.jdbc.schema-initialization.enabled=true
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
CREATE TABLE IF NOT EXISTS expensecategory
CREATE TABLE IF NOT EXISTS expense_category
(
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
account_id UUID NOT NULL,
name VARCHAR(100) NOT NULL,
creation_timestamp TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
);

CREATE INDEX expense_category_account_id_idx ON expensecategory (account_id);
CREATE UNIQUE INDEX unique_category_name_account_id_idx ON expensecategory (account_id, name);
CREATE INDEX expense_category_account_id_idx ON expense_category (account_id);
CREATE UNIQUE INDEX unique_category_name_account_id_idx ON expense_category (account_id, name);
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
CREATE TABLE IF NOT EXISTS incomesource
CREATE TABLE IF NOT EXISTS income_source
(
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
account_id UUID NOT NULL,
name VARCHAR(100) NOT NULL,
creation_timestamp TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
);

CREATE UNIQUE INDEX unique_source_name_account_id_idx ON incomesource (account_id, name);
CREATE UNIQUE INDEX unique_income_source_name_account_id_idx ON incomesource (account_id, name);
CREATE UNIQUE INDEX unique_source_name_account_id_idx ON income_source (account_id, name);
CREATE UNIQUE INDEX unique_income_source_name_account_id_idx ON income_source (account_id, name);
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ CREATE TABLE IF NOT EXISTS expenses
expense_date DATE NOT NULL,
description TEXT,
category_id UUID NOT NULL,
FOREIGN KEY (category_id) REFERENCES expensecategory (id)
FOREIGN KEY (category_id) REFERENCES expense_category (id)
);
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ CREATE TABLE IF NOT EXISTS incomes
income_date DATE NOT NULL,
description TEXT,
income_source_id UUID NOT NULL,
FOREIGN KEY (income_source_id) REFERENCES incomesource (id)
FOREIGN KEY (income_source_id) REFERENCES income_source (id)
);
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
CREATE TABLE IF NOT EXISTS spendingplans
CREATE TABLE IF NOT EXISTS spending_plans
(
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
creation_timestamp TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
Expand All @@ -10,4 +10,4 @@ CREATE TABLE IF NOT EXISTS spendingplans
)
;

CREATE UNIQUE INDEX unique_spending_plan_name_account_id_idx ON spendingplans (account_id, name);
CREATE UNIQUE INDEX unique_spending_plan_name_account_id_idx ON spending_plans (account_id, name);
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
CREATE TABLE IF NOT EXISTS spendingjars
CREATE TABLE IF NOT EXISTS spending_jars
(
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
creation_timestamp TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
Expand All @@ -8,10 +8,10 @@ CREATE TABLE IF NOT EXISTS spendingjars
percentage INTEGER NOT NULL,
description TEXT,
plan_id UUID NOT NULL,
FOREIGN KEY (plan_id) REFERENCES spendingplans (id)
FOREIGN KEY (plan_id) REFERENCES spending_plans (id)
)
;

CREATE UNIQUE INDEX unique_spending_jar_name_plan_id_idx ON spendingjars (name, plan_id);
CREATE UNIQUE INDEX unique_spending_jar_name_plan_id_idx ON spending_jars (name, plan_id);

CREATE INDEX search_spending_plan_id_idx ON spendingjars (plan_id);
CREATE INDEX search_spending_plan_id_idx ON spending_jars (plan_id);
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class ExpenseCategoryControllerSpec extends Specification {
TestRestTemplate restTemplate

def cleanup() {
JdbcTestUtils.deleteFromTables(jdbcTemplate, 'expenses', 'expensecategory')
JdbcTestUtils.deleteFromTables(jdbcTemplate, 'expenses', 'expense_category')
}

def "Should create a new category expense"() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class ExpenseControllerSpec extends Specification {
TestRestTemplate restTemplate

def cleanup() {
JdbcTestUtils.deleteFromTables(jdbcTemplate, 'expenses', 'expensecategory')
JdbcTestUtils.deleteFromTables(jdbcTemplate, 'expenses', 'expense_category')
}

@Sql('/expense/web/expensecategory-create.sql')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class IncomeControllerSpec extends Specification {
TestRestTemplate restTemplate

def cleanup() {
JdbcTestUtils.deleteFromTables(jdbcTemplate, 'incomes', 'incomesource')
JdbcTestUtils.deleteFromTables(jdbcTemplate, 'incomes', 'income_source')
}

@Sql('/income/web/incomesource-create.sql')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class IncomeSourceControllerSpec extends Specification {
TestRestTemplate restTemplate

def cleanup() {
JdbcTestUtils.deleteFromTables(jdbcTemplate, 'incomes', 'incomesource')
JdbcTestUtils.deleteFromTables(jdbcTemplate, 'incomes', 'income_source')
}

def "should create a new income source"() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class JarControllerSpec extends Specification {
TestRestTemplate restTemplate

def cleanup() {
JdbcTestUtils.deleteFromTables(jdbcTemplate, 'spendingjars', 'spendingplans')
JdbcTestUtils.deleteFromTables(jdbcTemplate, 'spending_jars', 'spending_plans')
}

@Sql('/spendingplan/web/plan-create.sql')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class PlanControllerSpec extends Specification {
TestRestTemplate restTemplate

def cleanup() {
JdbcTestUtils.deleteFromTables(jdbcTemplate, 'spendingjars', 'spendingplans')
JdbcTestUtils.deleteFromTables(jdbcTemplate, 'spending_jars', 'spending_plans')
}

def "should create a new spending plan"() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
INSERT INTO server.expensecategory (id,
account_id,
name)
INSERT INTO server.expense_category (id,
account_id,
name)
VALUES ('3b257779-a5db-4e87-9365-72c6f8d4977d',
'e2709aa2-7907-4f78-98b6-0f36a0c1b5ca',
'Bills'),
Expand Down
6 changes: 3 additions & 3 deletions server/src/test/resources/income/web/incomesource-create.sql
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
INSERT INTO server.incomesource (id,
account_id,
name)
INSERT INTO server.income_source (id,
account_id,
name)
VALUES ('3b257779-a5db-4e87-9365-72c6f8d4977d',
'e2709aa2-7907-4f78-98b6-0f36a0c1b5ca',
'Bills'),
Expand Down
16 changes: 8 additions & 8 deletions server/src/test/resources/spendingplan/web/jars-create.sql
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
INSERT INTO server.spendingjars(id,
creation_timestamp,
name,
amount_to_reach,
currency,
percentage,
description,
plan_id)
INSERT INTO server.spending_jars(id,
creation_timestamp,
name,
amount_to_reach,
currency,
percentage,
description,
plan_id)
VALUES ('e2709aa2-7907-4f78-98b6-0f36a0c1b5ca',
'2024-03-23T10:00:04.224870Z',
'Necessities',
Expand Down
14 changes: 7 additions & 7 deletions server/src/test/resources/spendingplan/web/plan-create.sql
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
INSERT INTO server.spendingplans(id,
creation_timestamp,
account_id,
name,
amount,
currency,
description)
INSERT INTO server.spending_plans(id,
creation_timestamp,
account_id,
name,
amount,
currency,
description)
VALUES ('3b257779-a5db-4e87-9365-72c6f8d4977d',
'2024-03-23T10:00:04.224870Z',
'e2709aa2-7907-4f78-98b6-0f36a0c1b5ca',
Expand Down

0 comments on commit a1b1750

Please sign in to comment.