feat: created xml databaseChangeLog for init schema of database, add fk, and add index

This commit is contained in:
vilar 2025-12-17 18:28:17 +05:00
parent 74e61e53c9
commit 27fd977297
3 changed files with 169 additions and 0 deletions

View file

@ -0,0 +1,88 @@
<?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
https://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.20.xsd">
<changeSet id="001-init-vets-schema" author="vilar">
<createTable tableName="vets">
<column name="id" type="INT" autoIncrement="true">
<constraints primaryKey="true" nullable="false"/>
</column>
<column name="first_name" type="VARCHAR(50)"/>
<column name="last_name" type="VARCHAR(50)"/>
</createTable>
</changeSet>
<changeSet id="002-init-specialties-schema" author="vilar">
<createTable tableName="specialties">
<column name="id" type="INT" autoIncrement="true">
<constraints primaryKey="true" nullable="false"/>
</column>
<column name="name" type="VARCHAR(50)"/>
</createTable>
</changeSet>
<changeSet id="003-init-types-schema" author="vilar">
<createTable tableName="types">
<column name="id" type="INT" autoIncrement="true">
<constraints primaryKey="true" nullable="false"/>
</column>
<column name="name" type="VARCHAR(30)"/>
</createTable>
</changeSet>
<changeSet id="004-init-owners-schema" author="vilar">
<createTable tableName="owners">
<column name="id" type="INT" autoIncrement="true">
<constraints primaryKey="true" nullable="false"/>
</column>
<column name="first_name" type="VARCHAR(30)"/>
<column name="last_name" type="VARCHAR(30)"/>
<column name="address" type="VARCHAR(50)"/>
<column name="city" type="VARCHAR(40)"/>
<column name="telephone" type="VARCHAR(10)"/>
</createTable>
</changeSet>
<changeSet id="005-init-vet-specialties-schema" author="vilar">
<createTable tableName="vet_specialties">
<column name="vet_id" type="int">
<constraints nullable="false"/>
</column>
<column name="specialty_id" type="int">
<constraints nullable="false"/>
</column>
</createTable>
</changeSet>
<changeSet id="006-init-pets-schema" author="vilar">
<createTable tableName="pets">
<column name="id" type="INT" autoIncrement="true">
<constraints primaryKey="true" nullable="false"/>
</column>
<column name="name" type="varchar"/>
<column name="birth_date" type="date"/>
<column name="type_id" type="int">
<constraints nullable="false" />
</column>
<column name="owner_id" type="int"/>
</createTable>
</changeSet>
<changeSet id="007-init-visits-schema" author="vilar">
<createTable tableName="visits">
<column name="id" type="INT" autoIncrement="true">
<constraints primaryKey="true" nullable="false"/>
</column>
<column name="pet_id" type="int">
<constraints nullable="true" />
</column>
<column name="visit_date" type="date"/>
<column name="description" type="varchar(50)"/>
</createTable>
</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
https://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.20.xsd">
<changeSet id="001-add-vets_specialties-fk" author="vilar">
<addForeignKeyConstraint baseTableName="vet_specialties" baseColumnNames="vet_id" constraintName="fk_vets_specialties_vet"
referencedTableName="vets"
referencedColumnNames="id"/>
<addForeignKeyConstraint baseTableName="vet_specialties" baseColumnNames="specialty_id" constraintName="fk_vets_specialties_specialty"
referencedTableName="specialties"
referencedColumnNames="id"/>
</changeSet>
<changeSet id="002-add-pets-fk" author="vilar">
<addForeignKeyConstraint baseTableName="pets" baseColumnNames="type_id" constraintName="fk_pets_types"
referencedTableName="types"
referencedColumnNames="id"/>
<addForeignKeyConstraint baseTableName="pets" baseColumnNames="owner_id" constraintName="fk_pets_owner"
referencedTableName="owners"
referencedColumnNames="id"/>
</changeSet>
<changeSet id="003-add-visits-fk" author="vilar">
<addForeignKeyConstraint baseTableName="visits" baseColumnNames="pet_id" constraintName="fk_visits_pet"
referencedTableName="pets"
referencedColumnNames="id"/>
</changeSet>
</databaseChangeLog>

View file

@ -0,0 +1,48 @@
<?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.9.xsd">
<changeSet id="001-add-index-vets-last-name" author="vilar">
<createIndex tableName="vets" indexName="idx_vets_last_name">
<column name="last_name"/>
</createIndex>
</changeSet>
<changeSet id="002-add-index-specialties-name" author="vilar">
<createIndex tableName="specialties" indexName="idx_specialties_name">
<column name="name"/>
</createIndex>
</changeSet>
<changeSet id="003-add-index-types-schema" author="vilar">
<createIndex tableName="types" indexName="idx_types_name">
<column name="name"/>
</createIndex>
</changeSet>
<changeSet id="004-add-index-owners-schema" author="vilar">
<createIndex tableName="owners" indexName="idx_owners_last_name">
<column name="last_name"/>
</createIndex>
</changeSet>
<changeSet id="005-add-index-pets-schema.yaml" author="vilar">
<createIndex tableName="pets" indexName="idx_pets_name">
<column name="name"/>
</createIndex>
<createIndex tableName="pets" indexName="idx_pets_owner_id">
<column name="owner_id"/>
</createIndex>
</changeSet>
<changeSet id="006-add-index-visits-schema" author="vilar">
<createIndex tableName="visits" indexName="idx_visits_pet_id">
<column name="pet_id"/>
</createIndex>
</changeSet>
</databaseChangeLog>