added liquibase db
This commit is contained in:
@@ -1,57 +0,0 @@
|
||||
databaseChangeLog:
|
||||
- changeSet:
|
||||
id: 001-create-users
|
||||
author: you
|
||||
changes:
|
||||
- createTable:
|
||||
tableName: users
|
||||
columns:
|
||||
- column: { name: id, type: BIGSERIAL, constraints: { primaryKey: true } }
|
||||
- column: { name: email, type: VARCHAR(255), constraints: { nullable: false, unique: true } }
|
||||
- column: { name: password, type: VARCHAR(255), constraints: { nullable: false } }
|
||||
- column: { name: created_at, type: TIMESTAMP }
|
||||
|
||||
- changeSet:
|
||||
id: 002-create-posts
|
||||
author: you
|
||||
changes:
|
||||
- createTable:
|
||||
tableName: posts
|
||||
columns:
|
||||
- column: { name: id, type: BIGSERIAL, constraints: { primaryKey: true } }
|
||||
- column: { name: type, type: VARCHAR(20) }
|
||||
- column: { name: title, type: VARCHAR(255) }
|
||||
- column: { name: description, type: TEXT }
|
||||
- column: { name: category, type: VARCHAR(100) }
|
||||
- column: { name: city, type: VARCHAR(100) }
|
||||
- column: { name: district, type: VARCHAR(100) }
|
||||
- column: { name: latitude, type: DOUBLE }
|
||||
- column: { name: longitude, type: DOUBLE }
|
||||
- column: { name: status, type: VARCHAR(20) }
|
||||
- column: { name: created_at, type: TIMESTAMP }
|
||||
- column: { name: user_id, type: BIGINT }
|
||||
|
||||
- addForeignKeyConstraint:
|
||||
baseTableName: posts
|
||||
baseColumnNames: user_id
|
||||
referencedTableName: users
|
||||
referencedColumnNames: id
|
||||
constraintName: fk_posts_user # ✅ ДОБАВИТЬ
|
||||
|
||||
- changeSet:
|
||||
id: 003-create-images
|
||||
author: you
|
||||
changes:
|
||||
- createTable:
|
||||
tableName: images
|
||||
columns:
|
||||
- column: { name: id, type: BIGSERIAL, constraints: { primaryKey: true } }
|
||||
- column: { name: url, type: VARCHAR(500) }
|
||||
- column: { name: post_id, type: BIGINT }
|
||||
|
||||
- addForeignKeyConstraint:
|
||||
baseTableName: images
|
||||
baseColumnNames: post_id
|
||||
referencedTableName: posts
|
||||
referencedColumnNames: id
|
||||
constraintName: fk_images_post # ✅
|
||||
@@ -0,0 +1,11 @@
|
||||
databaseChangeLog:
|
||||
- changeSet:
|
||||
id: 007-constraint-images
|
||||
author: alexandr krylov
|
||||
changes:
|
||||
- addForeignKeyConstraint:
|
||||
baseTableName: images
|
||||
baseColumnNames: post_id
|
||||
referencedTableName: posts
|
||||
referencedColumnNames: id
|
||||
constraintName: fk_images_post
|
||||
@@ -0,0 +1,11 @@
|
||||
databaseChangeLog:
|
||||
- changeSet:
|
||||
id: 006-constraint-post
|
||||
author: alexandr krylov
|
||||
changes:
|
||||
- addForeignKeyConstraint:
|
||||
baseTableName: posts
|
||||
baseColumnNames: user_id
|
||||
referencedTableName: users
|
||||
referencedColumnNames: id
|
||||
constraintName: fk_posts_user
|
||||
@@ -1,31 +1,21 @@
|
||||
databaseChangeLog:
|
||||
- changeSet:
|
||||
id: 004-create-messages
|
||||
author: you
|
||||
id: 008-constraint-message
|
||||
author: alexandr krylov
|
||||
changes:
|
||||
- createTable:
|
||||
tableName: messages
|
||||
columns:
|
||||
- column: { name: id, type: BIGSERIAL, constraints: { primaryKey: true } }
|
||||
- column: { name: sender_id, type: BIGINT }
|
||||
- column: { name: receiver_id, type: BIGINT }
|
||||
- column: { name: content, type: TEXT }
|
||||
- column: { name: created_at, type: TIMESTAMP }
|
||||
- column: { name: is_read, type: BOOLEAN }
|
||||
|
||||
- addForeignKeyConstraint:
|
||||
baseTableName: messages
|
||||
baseColumnNames: sender_id
|
||||
referencedTableName: users
|
||||
referencedColumnNames: id
|
||||
constraintName: fk_messages_sender # ✅
|
||||
constraintName: fk_messages_sender
|
||||
|
||||
- addForeignKeyConstraint:
|
||||
baseTableName: messages
|
||||
baseColumnNames: receiver_id
|
||||
referencedTableName: users
|
||||
referencedColumnNames: id
|
||||
constraintName: fk_messages_receiver # ✅
|
||||
constraintName: fk_messages_receiver
|
||||
|
||||
# 🔥 индекс для чата
|
||||
- createIndex:
|
||||
@@ -1,28 +1,21 @@
|
||||
databaseChangeLog:
|
||||
- changeSet:
|
||||
id: 005-create-favorites
|
||||
author: you
|
||||
id: 009-fk-favorite-user
|
||||
author: alexandr krylov
|
||||
changes:
|
||||
- createTable:
|
||||
tableName: favorites
|
||||
columns:
|
||||
- column: { name: id, type: BIGSERIAL, constraints: { primaryKey: true } }
|
||||
- column: { name: user_id, type: BIGINT }
|
||||
- column: { name: post_id, type: BIGINT }
|
||||
|
||||
- addForeignKeyConstraint:
|
||||
baseTableName: favorites
|
||||
baseColumnNames: user_id
|
||||
referencedTableName: users
|
||||
referencedColumnNames: id
|
||||
constraintName: fk_favorites_user # ✅
|
||||
constraintName: fk_favorites_user
|
||||
|
||||
- addForeignKeyConstraint:
|
||||
baseTableName: favorites
|
||||
baseColumnNames: post_id
|
||||
referencedTableName: posts
|
||||
referencedColumnNames: id
|
||||
constraintName: fk_favorites_post # ✅
|
||||
constraintName: fk_favorites_post
|
||||
|
||||
# 🔥 защита от дублей
|
||||
- addUniqueConstraint:
|
||||
12
src/main/resources/db/changelog/create/001-create-users.yaml
Normal file
12
src/main/resources/db/changelog/create/001-create-users.yaml
Normal file
@@ -0,0 +1,12 @@
|
||||
databaseChangeLog:
|
||||
- changeSet:
|
||||
id: 001-create-users
|
||||
author: you
|
||||
changes:
|
||||
- createTable:
|
||||
tableName: users
|
||||
columns:
|
||||
- column: { name: id, type: BIGSERIAL, constraints: { primaryKey: true } }
|
||||
- column: { name: email, type: VARCHAR(255), constraints: { nullable: false, unique: true } }
|
||||
- column: { name: password, type: VARCHAR(255), constraints: { nullable: false } }
|
||||
- column: { name: created_at, type: TIMESTAMP }
|
||||
20
src/main/resources/db/changelog/create/002-create-posts.yaml
Normal file
20
src/main/resources/db/changelog/create/002-create-posts.yaml
Normal file
@@ -0,0 +1,20 @@
|
||||
databaseChangeLog:
|
||||
- changeSet:
|
||||
id: 005-create-posts
|
||||
author: you
|
||||
changes:
|
||||
- createTable:
|
||||
tableName: posts
|
||||
columns:
|
||||
- column: { name: id, type: BIGSERIAL, constraints: { primaryKey: true } }
|
||||
- column: { name: type, type: VARCHAR(20) }
|
||||
- column: { name: title, type: VARCHAR(255) }
|
||||
- column: { name: description, type: TEXT }
|
||||
- column: { name: category, type: VARCHAR(100) }
|
||||
- column: { name: city, type: VARCHAR(100) }
|
||||
- column: { name: district, type: VARCHAR(100) }
|
||||
- column: { name: latitude, type: DOUBLE }
|
||||
- column: { name: longitude, type: DOUBLE }
|
||||
- column: { name: status, type: VARCHAR(20) }
|
||||
- column: { name: created_at, type: TIMESTAMP }
|
||||
- column: { name: user_id, type: BIGINT }
|
||||
@@ -0,0 +1,11 @@
|
||||
databaseChangeLog:
|
||||
- changeSet:
|
||||
id: 003-create-images
|
||||
author: you
|
||||
changes:
|
||||
- createTable:
|
||||
tableName: images
|
||||
columns:
|
||||
- column: { name: id, type: BIGSERIAL, constraints: { primaryKey: true } }
|
||||
- column: { name: url, type: VARCHAR(500) }
|
||||
- column: { name: post_id, type: BIGINT }
|
||||
@@ -0,0 +1,14 @@
|
||||
databaseChangeLog:
|
||||
- changeSet:
|
||||
id: 004-create-messages
|
||||
author: you
|
||||
changes:
|
||||
- createTable:
|
||||
tableName: messages
|
||||
columns:
|
||||
- column: { name: id, type: BIGSERIAL, constraints: { primaryKey: true } }
|
||||
- column: { name: sender_id, type: BIGINT }
|
||||
- column: { name: receiver_id, type: BIGINT }
|
||||
- column: { name: content, type: TEXT }
|
||||
- column: { name: created_at, type: TIMESTAMP }
|
||||
- column: { name: is_read, type: BOOLEAN }
|
||||
@@ -0,0 +1,11 @@
|
||||
databaseChangeLog:
|
||||
- changeSet:
|
||||
id: 005-create-favorites
|
||||
author: you
|
||||
changes:
|
||||
- createTable:
|
||||
tableName: favorites
|
||||
columns:
|
||||
- column: { name: id, type: BIGSERIAL, constraints: { primaryKey: true } }
|
||||
- column: { name: user_id, type: BIGINT }
|
||||
- column: { name: post_id, type: BIGINT }
|
||||
@@ -1,9 +1,10 @@
|
||||
databaseChangeLog:
|
||||
- include:
|
||||
file: db/changelog/001-init.yaml
|
||||
|
||||
- include:
|
||||
file: db/changelog/002-message.yaml
|
||||
|
||||
- include:
|
||||
file: db/changelog/003-favorite.yaml
|
||||
- include: { file: db/changelog/create/001-create-users.yaml }
|
||||
- include: { file: db/changelog/create/002-create-posts.yaml }
|
||||
- include: { file: db/changelog/create/003-create-images.yaml }
|
||||
- include: { file: db/changelog/create/004-create-message.yaml }
|
||||
- include: { file: db/changelog/create/005-create-favorite.yaml }
|
||||
- include: { file: db/changelog/constraint/006-fk-images-post-constraint.yaml }
|
||||
- include: { file: db/changelog/constraint/007-fk-post-user-constraint.yaml }
|
||||
- include: { file: db/changelog/constraint/008-fk-message-user.yaml }
|
||||
- include: { file: db/changelog/constraint/009-fk-favorite-user.yaml }
|
||||
Reference in New Issue
Block a user