Skip to content

Commit

Permalink
[#10] Convert Liquibase scripts to XML format
Browse files Browse the repository at this point in the history
  • Loading branch information
isbel8ai committed Oct 7, 2024
1 parent eab6015 commit b946856
Show file tree
Hide file tree
Showing 25 changed files with 152 additions and 134 deletions.
38 changes: 0 additions & 38 deletions database/product-store-api_create.sql

This file was deleted.

10 changes: 0 additions & 10 deletions database/product-store-api_drop.sql

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.i8ai.training.store.api;
package com.i8ai.training.store.rest;

import com.i8ai.training.store.service.BalanceService;
import com.i8ai.training.store.service.data.Balance;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.i8ai.training.store.api;
package com.i8ai.training.store.rest;

import com.i8ai.training.store.service.ExistenceService;
import com.i8ai.training.store.service.data.Existence;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.i8ai.training.store.api;
package com.i8ai.training.store.rest;

import com.i8ai.training.store.model.Lot;
import com.i8ai.training.store.service.LotService;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.i8ai.training.store.api;
package com.i8ai.training.store.rest;

import com.i8ai.training.store.model.Pack;
import com.i8ai.training.store.service.PackService;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.i8ai.training.store.api;
package com.i8ai.training.store.rest;

import com.i8ai.training.store.model.Product;
import com.i8ai.training.store.service.ProductService;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.i8ai.training.store.api;
package com.i8ai.training.store.rest;

import com.i8ai.training.store.model.Sale;
import com.i8ai.training.store.service.SaleService;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.i8ai.training.store.api;
package com.i8ai.training.store.rest;


import com.i8ai.training.store.model.Shop;
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/com/i8ai/training/store/util/DateTimeUtils.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
package com.i8ai.training.store.util;

import lombok.experimental.UtilityClass;

import java.util.Date;

@UtilityClass
public class DateTimeUtils {

private DateTimeUtils() {
}

public static Date dateOrMin(Date start) {
public Date dateOrMin(Date start) {
return start != null ? start : new Date(0);
}

public static Date dateOrMax(Date end) {
public Date dateOrMax(Date end) {
return end != null ? end : new Date();
}
}
2 changes: 1 addition & 1 deletion src/main/resources/application-dev.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
spring:
datasource:
url: jdbc:h2:mem:dev;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE;AUTO_RECONNECT=TRUE;MODE=PostgreSQL;
url: jdbc:h2:./${spring.application.name};MODE=PostgreSQL;
username: sa
password:

Expand Down
11 changes: 8 additions & 3 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
spring:
profiles:
active: prod
application:
name: product-store-api

liquibase:
change-log: classpath:/db/changelog/db.changelog-master.yml
change-log: classpath:/db/changelog-master.xml
user: ${spring.datasource.username}
password: ${spring.datasource.password}

profiles:
active: prod
10 changes: 10 additions & 0 deletions src/main/resources/db/changelog-master.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.27.xsd">

<include file="db/init-changelog.xml"/>

</databaseChangeLog>
3 changes: 0 additions & 3 deletions src/main/resources/db/changelog/db.changelog-master.yml

This file was deleted.

58 changes: 0 additions & 58 deletions src/main/resources/db/changelog/init-changelog.sql

This file was deleted.

107 changes: 107 additions & 0 deletions src/main/resources/db/init-changelog.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.27.xsd"
objectQuotingStrategy="QUOTE_ONLY_RESERVED_WORDS">
<changeSet id="init" author="Isbel">
<createTable tableName="lot">
<column autoIncrement="true" name="id" type="BIGINT">
<constraints nullable="false" primaryKey="true" primaryKeyName="pk_lot"/>
</column>
<column name="received" type="DATETIME">
<constraints nullable="false"/>
</column>
<column name="amount" type="DOUBLE">
<constraints nullable="false"/>
</column>
<column name="cost" type="DOUBLE">
<constraints nullable="false"/>
</column>
<column name="product_id" type="BIGINT">
<constraints nullable="false"/>
</column>
</createTable>

<createTable tableName="pack">
<column autoIncrement="true" name="id" type="BIGINT">
<constraints nullable="false" primaryKey="true" primaryKeyName="pk_pack"/>
</column>
<column name="delivered" type="DATETIME">
<constraints nullable="false"/>
</column>
<column name="amount" type="DOUBLE">
<constraints nullable="false"/>
</column>
<column name="lot_id" type="BIGINT">
<constraints nullable="false"/>
</column>
<column name="shop_id" type="BIGINT">
<constraints nullable="false"/>
</column>
</createTable>

<createTable tableName="product">
<column autoIncrement="true" name="id" type="BIGINT">
<constraints nullable="false" primaryKey="true" primaryKeyName="pk_product"/>
</column>
<column name="code" type="VARCHAR(255)">
<constraints nullable="false"/>
</column>
<column name="name" type="VARCHAR(255)">
<constraints nullable="false"/>
</column>
<column name="measure" type="VARCHAR(255)">
<constraints nullable="false"/>
</column>
<column name="description" type="VARCHAR(255)"/>
</createTable>

<createTable tableName="sale">
<column autoIncrement="true" name="id" type="BIGINT">
<constraints nullable="false" primaryKey="true" primaryKeyName="pk_sale"/>
</column>
<column name="registered" type="DATETIME">
<constraints nullable="false"/>
</column>
<column name="amount" type="DOUBLE">
<constraints nullable="false"/>
</column>
<column name="price" type="DOUBLE">
<constraints nullable="false"/>
</column>
<column name="pack_id" type="BIGINT">
<constraints nullable="false"/>
</column>
</createTable>

<createTable tableName="shop">
<column autoIncrement="true" name="id" type="BIGINT">
<constraints nullable="false" primaryKey="true" primaryKeyName="pk_shop"/>
</column>
<column name="name" type="VARCHAR(255)">
<constraints nullable="false"/>
</column>
<column name="address" type="VARCHAR(255)">
<constraints nullable="false"/>
</column>
<column name="description" type="VARCHAR(255)"/>
</createTable>

<addUniqueConstraint columnNames="code" constraintName="uc_product_code" tableName="product"/>

<addForeignKeyConstraint baseColumnNames="product_id" baseTableName="lot" constraintName="FK_LOT_ON_PRODUCT"
referencedColumnNames="id" referencedTableName="product"/>

<addForeignKeyConstraint baseColumnNames="lot_id" baseTableName="pack" constraintName="FK_PACK_ON_LOT"
referencedColumnNames="id" referencedTableName="lot"/>

<addForeignKeyConstraint baseColumnNames="shop_id" baseTableName="pack" constraintName="FK_PACK_ON_SHOP"
referencedColumnNames="id" referencedTableName="shop"/>

<addForeignKeyConstraint baseColumnNames="pack_id" baseTableName="sale" constraintName="FK_SALE_ON_PACK"
referencedColumnNames="id" referencedTableName="pack"/>
</changeSet>

</databaseChangeLog>
2 changes: 2 additions & 0 deletions src/test/java/com/i8ai/training/store/ApplicationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ContextConfiguration;

import static org.junit.jupiter.api.Assertions.assertTrue;

@SpringBootTest
@ContextConfiguration(classes = Application.class)
class ApplicationTest {
@Test
void contextLoads() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.i8ai.training.store.api;
package com.i8ai.training.store.rest;

import com.i8ai.training.store.service.BalanceService;
import com.i8ai.training.store.service.data.Balance;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.i8ai.training.store.api;
package com.i8ai.training.store.rest;

import com.i8ai.training.store.service.ExistenceService;
import com.i8ai.training.store.service.data.Existence;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.i8ai.training.store.api;
package com.i8ai.training.store.rest;

import com.i8ai.training.store.model.Lot;
import com.i8ai.training.store.service.LotService;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.i8ai.training.store.api;
package com.i8ai.training.store.rest;

import com.i8ai.training.store.model.Pack;
import com.i8ai.training.store.service.PackService;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.i8ai.training.store.api;
package com.i8ai.training.store.rest;

import com.i8ai.training.store.model.Product;
import com.i8ai.training.store.service.ProductService;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.i8ai.training.store.api;
package com.i8ai.training.store.rest;

import com.i8ai.training.store.model.Sale;
import com.i8ai.training.store.service.SaleService;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.i8ai.training.store.api;
package com.i8ai.training.store.rest;

import com.i8ai.training.store.model.Shop;
import com.i8ai.training.store.service.ShopService;
Expand Down
7 changes: 5 additions & 2 deletions src/test/resources/application.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
spring:
datasource:
url: jdbc:h2:mem:dev;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE;AUTO_RECONNECT=TRUE;MODE=PostgreSQL;
url: jdbc:h2:mem:test;MODE=PostgreSQL;

liquibase:
enabled: false
enabled: false

profiles:
active: test

0 comments on commit b946856

Please sign in to comment.