feat: add Liquibase migrations

This commit is contained in:
2026-02-22 18:37:32 +03:00
parent f4b01cfefa
commit afc773815f
5 changed files with 102 additions and 0 deletions

View File

@@ -6,6 +6,9 @@ spring:
jpa: jpa:
hibernate: hibernate:
ddl-auto: validate ddl-auto: validate
show-sql: false
liquibase:
change-log: classpath:db/migration/changelog-master.xml
server: server:
port: 8080 port: 8080

View File

@@ -0,0 +1,28 @@
<?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.20.xsd"
>
<changeSet id="001" author="bank">
<createTable tableName="users">
<column name="id" type="BIGSERIAL" autoIncrement="true">
<constraints primaryKey="true" nullable="false" />
</column>
<column name="username" type="VARCHAR(50)">
<constraints nullable="false" unique="true" />
</column>
<column name="password" type="VARCHAR(255)">
<constraints nullable="false" />
</column>
<column name="email" type="VARCHAR(100)">
<constraints nullable="false" unique="true" />
</column>
<column name="role" type="VARCHAR(20)">
<constraints nullable="false" />
</column>
</createTable>
</changeSet>
</databaseChangeLog>

View File

@@ -0,0 +1,38 @@
<?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.20.xsd"
>
<changeSet id="002" author="bank">
<createTable tableName="cards">
<column name="id" type="BIGSERIAL" autoIncrement="true">
<constraints primaryKey="true" nullable="false" />
</column>
<column name="card_number_encrypted" type="TEXT">
<constraints nullable="false" />
</column>
<column name="owner_id" type="BIGINT">
<constraints nullable="false" />
</column>
<column name="expiry_date" type="DATE">
<constraints nullable="false" />
</column>
<column name="status" type="VARCHAR(20)">
<constraints nullable="false" />
</column>
<column name="balance" type="DECIMAL(19,2)">
<constraints nullable="false" />
</column>
</createTable>
<addForeignKeyConstraint
baseTableName="cards"
baseColumnNames="owner_id"
referencedTableName="users"
referencedColumnNames="id"
constraintName="fk_cards_owner"
/>
</changeSet>
</databaseChangeLog>

View File

@@ -0,0 +1,21 @@
<?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.20.xsd"
>
<changeSet id="003" author="bank">
<!-- Default admin: admin / admin123 -->
<insert tableName="users">
<column name="username" value="admin" />
<column name="email" value="admin@bank.com" />
<column
name="password"
value="$2a$10$N.zmdr9k7uOCQb376NoUnuTJ8iAt6Z5EHsM8lE9lBpwTTyDrPbVJW"
/>
<column name="role" value="ROLE_ADMIN" />
</insert>
</changeSet>
</databaseChangeLog>

View File

@@ -0,0 +1,12 @@
<?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.20.xsd"
>
<include file="classpath:db/migration/001-create-users.xml" />
<include file="classpath:db/migration/002-create-cards.xml" />
<include file="classpath:db/migration/003-insert-admin.xml" />
</databaseChangeLog>