Skip to content

Add liquibase #97

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions rest-api/build.gradle
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
plugins {
id "io.freefair.lombok"
id 'org.springframework.boot'
id "org.liquibase.gradle" version "2.0.4"
}

dependencies {
implementation project(':core')
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'
Expand All @@ -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"
Expand Down
11 changes: 11 additions & 0 deletions rest-api/src/main/resources/changelog/liquibase-changelog.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

давай лучше в yaml?


<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-3.1.xsd">

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

</databaseChangeLog>
4 changes: 4 additions & 0 deletions rest-api/src/main/resources/config/application.properties
Original file line number Diff line number Diff line change
@@ -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
43 changes: 43 additions & 0 deletions rest-api/src/main/resources/db/db.changelog-1.0.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?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-3.8.xsd">

<changeSet author="vlad" id="202009071830_Create_Table_item">
<sqlFile path="/sql/202009071830_Create_Table_item.sql"
relativeToChangelogFile="true"
splitStatements="true"
stripComments="true"/>
</changeSet>

<changeSet author="vlad" id="202009071831_Create_Table_receipt">
<sqlFile path="/sql/202009071831_Create_Table_receipt.sql"
relativeToChangelogFile="true"
splitStatements="true"
stripComments="true"/>
</changeSet>

<changeSet author="vlad" id="202009071832_Create_Table_place">
<sqlFile path="/sql/202009071832_Create_Table_place.sql"
relativeToChangelogFile="true"
splitStatements="true"
stripComments="true"/>
</changeSet>

<changeSet author="vlad" id="202009071833_Create_Table_user_profile">
<sqlFile path="/sql/202009071833_Create_Table_user_profile.sql"
relativeToChangelogFile="true"
splitStatements="true"
stripComments="true"/>
</changeSet>

<changeSet author="vlad" id="202009071834_Create_Table_merchant">
<sqlFile path="/sql/202009071834_Create_Table_merchant.sql"
relativeToChangelogFile="true"
splitStatements="true"
stripComments="true"/>
</changeSet>

</databaseChangeLog>
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
create table IF NOT EXISTS 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;

Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
create table IF NOT EXISTS 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;

Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
create table IF NOT EXISTS place
(
id bigserial not null
constraint place_pkey
primary key,
text varchar(255) not null
);

alter table place
owner to receipt_dev;

Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
create table IF NOT EXISTS 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;

Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
create table IF NOT EXISTS 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;

6 changes: 5 additions & 1 deletion rest-api/src/test/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
spring.jpa.hibernate.ddl-auto=create-drop

# Liquibase
spring.liquibase.enabled=false
spring.liquibase.change-log=classpath:/changelog/liquibase-changelog.xml