EVERGREEN-5499: add liquibase

Signed-off-by: Колмакова Марина <m.kolmakova@mail.astondevs.ru>
This commit is contained in:
Колмакова Марина 2025-12-03 23:26:22 +03:00
parent 3e1ce239f4
commit 3b8eb4aed8
12 changed files with 254 additions and 0 deletions

View file

@ -36,8 +36,10 @@ dependencies {
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
implementation 'org.springframework.boot:spring-boot-starter-webmvc'
implementation 'org.springframework.boot:spring-boot-starter-validation'
implementation 'org.springframework.boot:spring-boot-h2console'
implementation 'javax.cache:cache-api'
implementation 'jakarta.xml.bind:jakarta.xml.bind-api'
implementation 'org.liquibase:liquibase-core'
runtimeOnly 'org.springframework.boot:spring-boot-starter-actuator'
runtimeOnly "org.webjars:webjars-locator-lite:${webjarsLocatorLiteVersion}"
runtimeOnly "org.webjars.npm:bootstrap:${webjarsBootstrapVersion}"

View file

@ -0,0 +1,21 @@
package org.springframework.samples.petclinic.system;
import liquibase.integration.spring.SpringLiquibase;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import javax.sql.DataSource;
@Configuration
public class DatabaseConfiguration {
@Bean
@Profile("dev")
public SpringLiquibase liquibase(DataSource dataSource) {
SpringLiquibase liquibase = new SpringLiquibase();
liquibase.setDataSource(dataSource);
liquibase.setChangeLog("classpath:db/changelog/db.changelog-master.xml");
return liquibase;
}
}

View file

@ -0,0 +1 @@
spring.sql.init.mode=never

View file

@ -2,6 +2,10 @@
database=h2
spring.sql.init.schema-locations=classpath*:db/${database}/schema.sql
spring.sql.init.data-locations=classpath*:db/${database}/data.sql
spring.h2.console.enabled=true
#Liquibase
spring.liquibase.contexts=${spring.profiles.active}
# Web
spring.thymeleaf.mode=HTML

View file

@ -0,0 +1,19 @@
<?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.11.xsd">
<include file="db/changelog/tables/001-create-vets-table.xml"/>
<include file="db/changelog/tables/002-create-specialties-table.xml"/>
<include file="db/changelog/tables/003-create-vet-specialties-table.xml"/>
<include file="db/changelog/tables/004-create-types-table.xml"/>
<include file="db/changelog/tables/005-create-owners-table.xml"/>
<include file="db/changelog/tables/006-create-pets-table.xml"/>
<include file="db/changelog/tables/007-create-visits-table.xml"/>
<changeSet id="load-initial-data" author="Marina" context="dev">
<sqlFile path="db/h2/data.sql" relativeToChangelogFile="false"/>
</changeSet>
</databaseChangeLog>

View file

@ -0,0 +1,24 @@
<?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.11.xsd">
<changeSet id="001-create-vets-table" author="Marina">
<createTable tableName="vets">
<column name="id" type="INTEGER" autoIncrement="true">
<constraints primaryKey="true" nullable="false"/>
</column>
<column name="first_name" type="VARCHAR(30)">
</column>
<column name="last_name" type="VARCHAR(30)">
</column>
</createTable>
<createIndex tableName="vets" indexName="vets_last_name">
<column name="last_name"/>
</createIndex>
</changeSet>
</databaseChangeLog>

View file

@ -0,0 +1,22 @@
<?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.11.xsd">
<changeSet id="002-create-specialties-table" author="Marina">
<createTable tableName="specialties">
<column name="id" type="INTEGER" autoIncrement="true">
<constraints primaryKey="true" nullable="false"/>
</column>
<column name="name" type="VARCHAR(80)">
</column>
</createTable>
<createIndex tableName="specialties" indexName="specialties_name">
<column name="name"/>
</createIndex>
</changeSet>
</databaseChangeLog>

View file

@ -0,0 +1,33 @@
<?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.11.xsd">
<changeSet id="003-create-vet-specialties-table" author="Marina">
<createTable tableName="vet_specialties">
<column name="vet_id" type="INTEGER">
<constraints nullable="false"/>
</column>
<column name="specialty_id" type="INTEGER">
<constraints nullable="false"/>
</column>
</createTable>
<addForeignKeyConstraint
baseTableName="vet_specialties"
baseColumnNames="vet_id"
constraintName="fk_vet_specialties_vets"
referencedTableName="vets"
referencedColumnNames="id"/>
<addForeignKeyConstraint
baseTableName="vet_specialties"
baseColumnNames="specialty_id"
constraintName="fk_vet_specialties_specialties"
referencedTableName="specialties"
referencedColumnNames="id"/>
</changeSet>
</databaseChangeLog>

View file

@ -0,0 +1,22 @@
<?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.11.xsd">
<changeSet id="004-create-types-table" author="Marina">
<createTable tableName="types">
<column name="id" type="INTEGER" autoIncrement="true">
<constraints primaryKey="true" nullable="false"/>
</column>
<column name="name" type="VARCHAR(80)">
</column>
</createTable>
<createIndex tableName="types" indexName="types_name">
<column name="name"/>
</createIndex>
</changeSet>
</databaseChangeLog>

View file

@ -0,0 +1,30 @@
<?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.11.xsd">
<changeSet id="005-create-owners-table" author="Marina">
<createTable tableName="owners">
<column name="id" type="INTEGER" autoIncrement="true">
<constraints primaryKey="true" nullable="false"/>
</column>
<column name="first_name" type="VARCHAR(30)">
</column>
<column name="last_name" type="VARCHAR_IGNORECASE(30)">
</column>
<column name="address" type="VARCHAR(255)">
</column>
<column name="city" type="VARCHAR(80)">
</column>
<column name="telephone" type="VARCHAR(20)">
</column>
</createTable>
<createIndex tableName="owners" indexName="owners_last_name">
<column name="last_name"/>
</createIndex>
</changeSet>
</databaseChangeLog>

View file

@ -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-4.11.xsd">
<changeSet id="006-create-pets-table" author="Marina">
<createTable tableName="pets">
<column name="id" type="INTEGER" autoIncrement="true">
<constraints primaryKey="true" nullable="false"/>
</column>
<column name="name" type="VARCHAR(30)">
</column>
<column name="birth_date" type="DATE">
</column>
<column name="type_id" type="INTEGER">
<constraints nullable="false"/>
</column>
<column name="owner_id" type="INTEGER">
</column>
</createTable>
<addForeignKeyConstraint
baseTableName="pets"
baseColumnNames="type_id"
constraintName="fk_pets_types"
referencedTableName="types"
referencedColumnNames="id"/>
<addForeignKeyConstraint
baseTableName="pets"
baseColumnNames="owner_id"
constraintName="fk_pets_owners"
referencedTableName="owners"
referencedColumnNames="id"/>
<createIndex tableName="pets" indexName="pets_name">
<column name="name"/>
</createIndex>
</changeSet>
</databaseChangeLog>

View file

@ -0,0 +1,33 @@
<?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.11.xsd">
<changeSet id="007-create-visits-table" author="Marina">
<createTable tableName="visits">
<column name="id" type="INTEGER" autoIncrement="true">
<constraints primaryKey="true" nullable="false"/>
</column>
<column name="pet_id" type="INTEGER">
</column>
<column name="visit_date" type="DATE">
</column>
<column name="description" type="VARCHAR(255)">
</column>
</createTable>
<addForeignKeyConstraint
baseTableName="visits"
baseColumnNames="pet_id"
constraintName="fk_visits_pets"
referencedTableName="pets"
referencedColumnNames="id"/>
<createIndex tableName="visits" indexName="visits_pet_id">
<column name="pet_id"/>
</createIndex>
</changeSet>
</databaseChangeLog>