From 460c85adb1d4e5041048c9e0d4b6a6f324354a7c Mon Sep 17 00:00:00 2001 From: Vlad Date: Mon, 7 Sep 2020 18:37:57 +0300 Subject: [PATCH 1/3] add liquibase --- rest-api/build.gradle | 4 ++ .../changelog/liquibase-changelog.xml | 11 +++++ .../main/resources/db/db.changelog-1.0.xml | 43 +++++++++++++++++++ .../db/sql/202009071830_Create_Table_item.sql | 16 +++++++ .../sql/202009071831_Create_Table_receipt.sql | 27 ++++++++++++ .../sql/202009071832_Create_Table_place.sql | 11 +++++ ...202009071833_Create_Table_user_profile.sql | 21 +++++++++ .../202009071834_Create_Table_merchant.sql | 14 ++++++ 8 files changed, 147 insertions(+) create mode 100644 rest-api/src/main/resources/changelog/liquibase-changelog.xml create mode 100644 rest-api/src/main/resources/db/db.changelog-1.0.xml create mode 100644 rest-api/src/main/resources/db/sql/202009071830_Create_Table_item.sql create mode 100644 rest-api/src/main/resources/db/sql/202009071831_Create_Table_receipt.sql create mode 100644 rest-api/src/main/resources/db/sql/202009071832_Create_Table_place.sql create mode 100644 rest-api/src/main/resources/db/sql/202009071833_Create_Table_user_profile.sql create mode 100644 rest-api/src/main/resources/db/sql/202009071834_Create_Table_merchant.sql diff --git a/rest-api/build.gradle b/rest-api/build.gradle index 05a8ce9..603bcc8 100644 --- a/rest-api/build.gradle +++ b/rest-api/build.gradle @@ -1,6 +1,7 @@ plugins { id "io.freefair.lombok" id 'org.springframework.boot' + id "org.liquibase.gradle" version "2.0.4" } dependencies { @@ -8,6 +9,8 @@ dependencies { implementation project(':fns-sdk') implementation project(':rest-api-dto') + compile group: 'org.liquibase', name: 'liquibase-core', version: '4.0.0' + implementation 'com.google.code.findbugs:jsr305' implementation 'commons-codec:commons-codec' implementation 'org.apache.commons:commons-lang3' @@ -16,6 +19,7 @@ dependencies { implementation 'org.projectlombok:lombok' implementation 'org.springdoc:springdoc-openapi-ui' + implementation "org.liquibase:liquibase-gradle-plugin:2.0.4" testImplementation project(':test-util') testImplementation "com.h2database:h2" diff --git a/rest-api/src/main/resources/changelog/liquibase-changelog.xml b/rest-api/src/main/resources/changelog/liquibase-changelog.xml new file mode 100644 index 0000000..d10c75f --- /dev/null +++ b/rest-api/src/main/resources/changelog/liquibase-changelog.xml @@ -0,0 +1,11 @@ + + + + + + + \ No newline at end of file diff --git a/rest-api/src/main/resources/db/db.changelog-1.0.xml b/rest-api/src/main/resources/db/db.changelog-1.0.xml new file mode 100644 index 0000000..cc43ccb --- /dev/null +++ b/rest-api/src/main/resources/db/db.changelog-1.0.xml @@ -0,0 +1,43 @@ + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/rest-api/src/main/resources/db/sql/202009071830_Create_Table_item.sql b/rest-api/src/main/resources/db/sql/202009071830_Create_Table_item.sql new file mode 100644 index 0000000..08176fd --- /dev/null +++ b/rest-api/src/main/resources/db/sql/202009071830_Create_Table_item.sql @@ -0,0 +1,16 @@ +create table item +( + id bigserial not null + constraint item_pkey + primary key, + amount double precision not null, + price double precision not null, + text varchar(255) not null, + receipt_id bigint + constraint fk8s305nsnv4wi5iuh7kkr52gqt + references receipt +); + +alter table item + owner to receipt_dev; + diff --git a/rest-api/src/main/resources/db/sql/202009071831_Create_Table_receipt.sql b/rest-api/src/main/resources/db/sql/202009071831_Create_Table_receipt.sql new file mode 100644 index 0000000..dfc63b6 --- /dev/null +++ b/rest-api/src/main/resources/db/sql/202009071831_Create_Table_receipt.sql @@ -0,0 +1,27 @@ +create table receipt +( + id bigserial not null + constraint receipt_pkey + primary key, + date timestamp not null, + fd varchar(255) not null, + fn varchar(255) not null, + fp varchar(255) not null, + provider varchar(255), + status varchar(255) not null, + sum double precision not null, + place_id bigint + constraint fk2x2wkgo5re36vwpxctma1o4s6 + references place, + merchant_inn varchar(255), + merchant_name varchar(255), + merchant_place_address varchar(255), + user_profile_id varchar(255) + constraint fk7n4ubagih0n1tdwvx4h7qdn5d + references user_profile, + load_attempts bigint default 0 +); + +alter table receipt + owner to receipt_dev; + diff --git a/rest-api/src/main/resources/db/sql/202009071832_Create_Table_place.sql b/rest-api/src/main/resources/db/sql/202009071832_Create_Table_place.sql new file mode 100644 index 0000000..a64543c --- /dev/null +++ b/rest-api/src/main/resources/db/sql/202009071832_Create_Table_place.sql @@ -0,0 +1,11 @@ +create table place +( + id bigserial not null + constraint place_pkey + primary key, + text varchar(255) not null +); + +alter table place + owner to receipt_dev; + diff --git a/rest-api/src/main/resources/db/sql/202009071833_Create_Table_user_profile.sql b/rest-api/src/main/resources/db/sql/202009071833_Create_Table_user_profile.sql new file mode 100644 index 0000000..6ca6214 --- /dev/null +++ b/rest-api/src/main/resources/db/sql/202009071833_Create_Table_user_profile.sql @@ -0,0 +1,21 @@ +create table user_profile +( + id varchar(255) not null + constraint user_profile_pkey + primary key, + created_at timestamp not null, + updated_at timestamp, + access_token varchar(255), + fns_request_count integer, + password varchar(255) not null, + phone varchar(255) not null + constraint uk_1un6sdkbtaspkwmsiferm1dhm + unique, + load_count integer default 0 not null, + email varchar(255), + name varchar(255) +); + +alter table user_profile + owner to receipt_dev; + diff --git a/rest-api/src/main/resources/db/sql/202009071834_Create_Table_merchant.sql b/rest-api/src/main/resources/db/sql/202009071834_Create_Table_merchant.sql new file mode 100644 index 0000000..3b1d523 --- /dev/null +++ b/rest-api/src/main/resources/db/sql/202009071834_Create_Table_merchant.sql @@ -0,0 +1,14 @@ +create table merchant +( + id bigserial not null + constraint merchant_pkey + primary key, + address varchar(255) not null, + inn varchar(255) not null, + last_update_time timestamp not null, + name varchar(255) not null +); + +alter table merchant + owner to receipt_dev; + From 002f1f84f285b394ebac7722936538ccbe2c20d1 Mon Sep 17 00:00:00 2001 From: Vlad Date: Mon, 7 Sep 2020 18:39:52 +0300 Subject: [PATCH 2/3] add config for liquibase --- rest-api/src/main/resources/config/application.properties | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/rest-api/src/main/resources/config/application.properties b/rest-api/src/main/resources/config/application.properties index d883cd6..b6c8290 100644 --- a/rest-api/src/main/resources/config/application.properties +++ b/rest-api/src/main/resources/config/application.properties @@ -1,2 +1,6 @@ springdoc.api-docs.path=/documentation springdoc.swagger-ui.path=/documentation/view + +# Liquibase +spring.liquibase.enabled=false +spring.liquibase.change-log=classpath:/changelog/liquibase-changelog.xml From 3d32c8afcfae83f5a0db84fcfa4c812b9f9454be Mon Sep 17 00:00:00 2001 From: Vlad Date: Mon, 7 Sep 2020 18:47:02 +0300 Subject: [PATCH 3/3] add IF NOT EXISTS to liquibase.sql and amendments to application.properties --- .../resources/db/sql/202009071830_Create_Table_item.sql | 2 +- .../resources/db/sql/202009071831_Create_Table_receipt.sql | 2 +- .../resources/db/sql/202009071832_Create_Table_place.sql | 2 +- .../db/sql/202009071833_Create_Table_user_profile.sql | 2 +- .../resources/db/sql/202009071834_Create_Table_merchant.sql | 2 +- rest-api/src/test/resources/application.properties | 6 +++++- 6 files changed, 10 insertions(+), 6 deletions(-) diff --git a/rest-api/src/main/resources/db/sql/202009071830_Create_Table_item.sql b/rest-api/src/main/resources/db/sql/202009071830_Create_Table_item.sql index 08176fd..c7ba30b 100644 --- a/rest-api/src/main/resources/db/sql/202009071830_Create_Table_item.sql +++ b/rest-api/src/main/resources/db/sql/202009071830_Create_Table_item.sql @@ -1,4 +1,4 @@ -create table item +create table IF NOT EXISTS item ( id bigserial not null constraint item_pkey diff --git a/rest-api/src/main/resources/db/sql/202009071831_Create_Table_receipt.sql b/rest-api/src/main/resources/db/sql/202009071831_Create_Table_receipt.sql index dfc63b6..fe427b1 100644 --- a/rest-api/src/main/resources/db/sql/202009071831_Create_Table_receipt.sql +++ b/rest-api/src/main/resources/db/sql/202009071831_Create_Table_receipt.sql @@ -1,4 +1,4 @@ -create table receipt +create table IF NOT EXISTS receipt ( id bigserial not null constraint receipt_pkey diff --git a/rest-api/src/main/resources/db/sql/202009071832_Create_Table_place.sql b/rest-api/src/main/resources/db/sql/202009071832_Create_Table_place.sql index a64543c..3d33b0e 100644 --- a/rest-api/src/main/resources/db/sql/202009071832_Create_Table_place.sql +++ b/rest-api/src/main/resources/db/sql/202009071832_Create_Table_place.sql @@ -1,4 +1,4 @@ -create table place +create table IF NOT EXISTS place ( id bigserial not null constraint place_pkey diff --git a/rest-api/src/main/resources/db/sql/202009071833_Create_Table_user_profile.sql b/rest-api/src/main/resources/db/sql/202009071833_Create_Table_user_profile.sql index 6ca6214..9e41fec 100644 --- a/rest-api/src/main/resources/db/sql/202009071833_Create_Table_user_profile.sql +++ b/rest-api/src/main/resources/db/sql/202009071833_Create_Table_user_profile.sql @@ -1,4 +1,4 @@ -create table user_profile +create table IF NOT EXISTS user_profile ( id varchar(255) not null constraint user_profile_pkey diff --git a/rest-api/src/main/resources/db/sql/202009071834_Create_Table_merchant.sql b/rest-api/src/main/resources/db/sql/202009071834_Create_Table_merchant.sql index 3b1d523..731ee88 100644 --- a/rest-api/src/main/resources/db/sql/202009071834_Create_Table_merchant.sql +++ b/rest-api/src/main/resources/db/sql/202009071834_Create_Table_merchant.sql @@ -1,4 +1,4 @@ -create table merchant +create table IF NOT EXISTS merchant ( id bigserial not null constraint merchant_pkey diff --git a/rest-api/src/test/resources/application.properties b/rest-api/src/test/resources/application.properties index 1698366..bc6d818 100644 --- a/rest-api/src/test/resources/application.properties +++ b/rest-api/src/test/resources/application.properties @@ -13,4 +13,8 @@ spring.datasource.password= spring.jpa.database-platform=org.hibernate.dialect.H2Dialect # Hibernate ddl auto (create, create-drop, validate, update) -spring.jpa.hibernate.ddl-auto=create-drop \ No newline at end of file +spring.jpa.hibernate.ddl-auto=create-drop + +# Liquibase +spring.liquibase.enabled=false +spring.liquibase.change-log=classpath:/changelog/liquibase-changelog.xml