databaseChangeLog: - changeSet: id: 014-create-chats author: krylov comment: > Таблица чатов. Раньше создавалась Hibernate (ddl-auto: update), поэтому changeset идемпотентен: если таблица уже есть — MARK_RAN. preConditions: onFail: MARK_RAN not: tableExists: tableName: chats changes: - createTable: tableName: chats columns: - column: { name: id, type: BIGSERIAL, constraints: { primaryKey: true } } - column: { name: user_one_id, type: BIGINT, constraints: { nullable: false } } - column: { name: user_two_id, type: BIGINT, constraints: { nullable: false } } - column: { name: post_id, type: BIGINT } - column: { name: created_at, type: TIMESTAMP, constraints: { nullable: false } } - addUniqueConstraint: tableName: chats columnNames: user_one_id, user_two_id constraintName: uq_chat_users - changeSet: id: 014-chats-idx-participants author: krylov comment: > findAllByUserId ищет по (user_one_id = ? OR user_two_id = ?), без индексов это full scan по всем чатам. preConditions: onFail: MARK_RAN tableExists: tableName: chats not: indexExists: tableName: chats indexName: idx_chats_user_one changes: - createIndex: tableName: chats indexName: idx_chats_user_one columns: - column: { name: user_one_id } - changeSet: id: 014-chats-idx-participants-two author: krylov preConditions: onFail: MARK_RAN tableExists: tableName: chats not: indexExists: tableName: chats indexName: idx_chats_user_two changes: - createIndex: tableName: chats indexName: idx_chats_user_two columns: - column: { name: user_two_id }