diff --git a/docs/liquibase-changelog-policies.md b/docs/liquibase-changelog-policies.md new file mode 100644 index 0000000..6090023 --- /dev/null +++ b/docs/liquibase-changelog-policies.md @@ -0,0 +1,40 @@ +## Liquibase changelog policy + +For now this document describes how to name changelog files and changeset IDs. + +___ + +### Changelog files naming rule +The pattern for changelog file name is ```yyMMdd.taskID-branchname```. + +Where: +* ```yyMMdd``` date when you start (or end) to work on task. +It is needed to preserve chronological order of files during sorting. +* ```taskID``` Zenhub ID of the task +* ```branchname``` the same text as the name of the task branch, +just to have short description in history tables of liquibase(for example). + +#### Example +``` +220309.10-create_init_data_migration_set +``` +### Changeset IDs naming rule +The pattern for changeset ID name is +```taskID..[minor-sequential-number]``` + +Where: +* ```taskID``` Zenhub ID of the task +* ```major-sequential-number``` unique ID in scope of current task (major ID) +* ```text-descriptor``` short text descriptor unique in scope of current task (major ID) +* ```minor-sequential-number``` unique ID in scope of major ID (optional) + +#### Example: +``` +10.route.1 +11.2.3 +17.5 +``` + +--- +P.S. You may want to read +[best practices article](https://www.liquibase.org/get-started/best-practices) \ No newline at end of file diff --git a/pom.xml b/pom.xml index c6ad8e9..9decf08 100644 --- a/pom.xml +++ b/pom.xml @@ -36,6 +36,8 @@ 6.5.0 2.6.0 2.6.0 + 42.5.4 + 4.19.1 0.8.8 @@ -62,18 +64,41 @@ spring-boot-starter + + org.springframework.boot + spring-boot-starter-data-jpa + + org.springframework.boot spring-boot-starter-test test + + org.springframework.boot + spring-boot-starter-validation + + + com.google.guava guava ${guava.version} + + com.h2database + h2 + test + + + + org.liquibase + liquibase-core + ${liquibase.version} + + org.projectlombok lombok @@ -97,6 +122,12 @@ tinylog-impl ${tinylog-impl.version} + + + org.postgresql + postgresql + ${postgresql.version} + @@ -123,6 +154,7 @@ + com.google.cloud.tools jib-maven-plugin @@ -160,6 +192,19 @@ + + org.liquibase + liquibase-maven-plugin + ${liquibase.version} + + ${project.resourcesDirectory} + liquibase-changelog-root.yaml + ${env.DB_URL} + ${env.DB_LOGIN} + ${env.DB_PASSWORD} + + + org.apache.maven.plugins maven-checkstyle-plugin @@ -188,19 +233,6 @@ - - org.springframework.boot - spring-boot-maven-plugin - - - - org.projectlombok - lombok - - - - - org.sonarsource.scanner.maven sonar-maven-plugin @@ -214,6 +246,20 @@ + + + org.springframework.boot + spring-boot-maven-plugin + + + + org.projectlombok + lombok + + + + + diff --git a/src/main/resources/application-dev.properties b/src/main/resources/application-dev.properties new file mode 100644 index 0000000..76e4a80 --- /dev/null +++ b/src/main/resources/application-dev.properties @@ -0,0 +1,3 @@ +spring.liquibase.enabled=true +spring.liquibase.contexts=dev +spring.liquibase.change-log=classpath:liquibase-changelog-root.yaml diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index cfdcb7a..69a39f5 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -1,2 +1,8 @@ bot.token=${BOT_TOKEN} -bot.name=${BOT_NAME} \ No newline at end of file +bot.name=${BOT_NAME} + +spring.datasource.url=${DB_URL} +spring.datasource.username=${DB_LOGIN} +spring.datasource.password=${DB_PASSWORD} + +spring.liquibase.enabled=false diff --git a/src/main/resources/liquibase-changelog-root.yaml b/src/main/resources/liquibase-changelog-root.yaml new file mode 100644 index 0000000..91f71b0 --- /dev/null +++ b/src/main/resources/liquibase-changelog-root.yaml @@ -0,0 +1,4 @@ +databaseChangeLog: + - includeAll: + path: liquibase-changelog + relativeToChangelogFile: true diff --git a/src/main/resources/liquibase-changelog/220309.10-create_init_data_migration_set.yaml b/src/main/resources/liquibase-changelog/220309.10-create_init_data_migration_set.yaml new file mode 100644 index 0000000..b24fa0c --- /dev/null +++ b/src/main/resources/liquibase-changelog/220309.10-create_init_data_migration_set.yaml @@ -0,0 +1,341 @@ +databaseChangeLog: + - changeSet: + id: 10.user.1 + author: rain + changes: + - createTable: + tableName: users + columns: + - column: + name: id + type: bigint + constraints: + primaryKey: true + - column: + name: telegram_user_id + type: bigint + constraints: + nullable: false + - column: + name: enabled + type: boolean + defaultValue: true + constraints: + nullable: false + - changeSet: + id: 10.user.2 + author: rain + changes: + - createSequence: + dataType: bigint + sequenceName: users_seq + incrementBy: 50 + + - changeSet: + id: 10.user.3 + author: rain + changes: + - createTable: + tableName: authorities + columns: + - column: + name: user_id + type: bigint + constraints: + nullable: false + references: users(id) + foreignKeyName: authorities_fk + deleteCascade: true + unique: true + uniqueConstraintName: authorities_uniq + - column: + name: authority + type: varchar(128) + constraints: + nullable: false + unique: true + uniqueConstraintName: authorities_uniq + + - changeSet: + id: 10.loc.1 + author: rain + changes: + - createTable: + tableName: countries + columns: + - column: + name: code + remarks: iso2 code + type: char(2) + constraints: + primaryKey: true + - column: + name: name + type: varchar(128) + constraints: + nullable: false + unique: true + + - changeSet: + id: 10.loc.2 + author: rain + changes: + - createTable: + tableName: cities + columns: + - column: + name: id + type: bigint + constraints: + primaryKey: true + - column: + name: name + type: varchar(64) + constraints: + nullable: false + - column: + name: country_code + type: varchar(2) + constraints: + nullable: false + references: countries(code) + foreignKeyName: cities_fk + - changeSet: + id: 10.loc.3 + author: rain + changes: + - createSequence: + dataType: bigint + sequenceName: cities_seq + incrementBy: 50 + + - changeSet: + id: 10.loc.4 + author: rain + changes: + - createTable: + tableName: cities_3rdp_api_data + columns: + - column: + name: city_id + type: bigint + constraints: + primaryKey: true + references: cities(id) + foreignKeyName: cities_3rdp_api_data_fk + deleteCascade: true + - column: + name: api_name + type: varchar(128) + constraints: + nullable: false + unique: true + uniqueConstraintName: cities_3rdp_api_data_uniq + - column: + name: api_city_id + type: varchar(64) + constraints: + nullable: false + unique: true + uniqueConstraintName: cities_3rdp_api_data_uniq + - column: + name: data + type: clob #json + constraints: + nullable: false + + - changeSet: + id: 10.route.1 + author: rain + changes: + - createTable: + tableName: stops + columns: + - column: + name: id + type: bigint + constraints: + primaryKey: true + - column: + name: name + type: varchar(128) + constraints: + nullable: false + unique: true + - column: + name: address + type: varchar(256) + constraints: + nullable: false + - column: + name: geolocation + type: varchar(128) + constraints: + nullable: false + unique: true + - column: + name: city_id + type: bigint + constraints: + nullable: false + references: cities(id) + foreignKeyName: stops_fk + - changeSet: + id: 10.route.2 + author: rain + changes: + - createSequence: + dataType: bigint + sequenceName: stops_seq + incrementBy: 50 + + - changeSet: + id: 10.route.3 + author: rain + changes: + - createTable: + tableName: routes + columns: + - column: + name: id + type: bigint + constraints: + primaryKey: true + - column: + name: enabled + type: boolean + constraints: + nullable: false + - column: + name: name + type: varchar(128) + constraints: + nullable: false + unique: true + - column: + name: description + type: text + constraints: + nullable: true + - changeSet: + id: 10.route.4 + author: rain + changes: + - createSequence: + dataType: bigint + sequenceName: routes_seq + incrementBy: 50 + + - changeSet: + id: 10.route.5 + author: rain + changes: + - createTable: + tableName: route_segments + columns: + - column: + name: id + type: bigint + constraints: + primaryKey: true + - column: + name: route_id + type: bigint + constraints: + nullable: false + references: routes(id) + foreignKeyName: route_segments_route_fk + deleteCascade: true + - column: + name: departure_stop_id + type: bigint + constraints: + nullable: false + references: stops(id) + foreignKeyName: route_segments_depart_fk + - column: + name: arrival_stop_id + type: bigint + constraints: + nullable: false + references: stops(id) + foreignKeyName: route_segments_arrive_fk + - changeSet: + id: 10.route.6 + author: rain + changes: + - createSequence: + dataType: bigint + sequenceName: route_segments_seq + incrementBy: 50 + + - changeSet: + id: 10.voyage.1 + author: rain + changes: + - createTable: + tableName: voyages + columns: + - column: + name: id + type: bigint + constraints: + primaryKey: true + - column: + name: route_id + type: bigint + constraints: + nullable: false + references: routes(id) + foreignKeyName: voyages_fk + - column: + name: datetime + type: timestamp + constraints: + nullable: false + - changeSet: + id: 10.voyage.2 + author: rain + changes: + - createSequence: + dataType: bigint + sequenceName: voyages_seq + incrementBy: 50 + + - changeSet: + id: 10.voyage.3 + author: rain + changes: + - createTable: + tableName: seats + columns: + - column: + name: id + type: bigint + constraints: + primaryKey: true + - column: + name: voyage_id + type: bigint + constraints: + nullable: false + references: voyages(id) + foreignKeyName: seats_fk + deleteCascade: true + unique: true + uniqueConstraintName: voyages_uniq + - column: + name: seat_number + type: int + constraints: + nullable: true + unique: true + uniqueConstraintName: voyages_uniq + - changeSet: + id: 10.voyage.4 + author: rain + changes: + - createSequence: + dataType: bigint + sequenceName: seats_seq + incrementBy: 50 diff --git a/src/test/resources/application.properties b/src/test/resources/application.properties new file mode 100644 index 0000000..fad708c --- /dev/null +++ b/src/test/resources/application.properties @@ -0,0 +1,5 @@ +bot.token=${BOT_TOKEN} +bot.name=${BOT_NAME} + +spring.liquibase.enabled=true +spring.liquibase.change-log=liquibase-changelog-root.yaml