mirror of
https://github.com/vran-dev/databasir.git
synced 2025-09-21 11:19:21 +08:00
Redesign document history model (#39)
* feat: jooq model generate * refactor: redesign document history model * fix: checkstyle * feat: add batch query table api * fix: checkstyle * feat: update frontend resources
This commit is contained in:
@@ -2,11 +2,17 @@ package com.databasir.dao.impl;
|
||||
|
||||
import com.databasir.dao.tables.pojos.DatabaseDocumentPojo;
|
||||
import com.databasir.dao.tables.records.DatabaseDocumentRecord;
|
||||
import com.databasir.dao.value.DatabaseDocumentVersionPojo;
|
||||
import lombok.Getter;
|
||||
import org.jooq.Condition;
|
||||
import org.jooq.DSLContext;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageImpl;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import static com.databasir.dao.Tables.DATABASE_DOCUMENT;
|
||||
@@ -29,10 +35,54 @@ public class DatabaseDocumentDao extends BaseDao<DatabaseDocumentPojo> {
|
||||
.fetchOptionalInto(DatabaseDocumentPojo.class);
|
||||
}
|
||||
|
||||
public Optional<DatabaseDocumentPojo> selectOptionalByProjectIdAndVersion(Integer projectId,
|
||||
Long version) {
|
||||
return getDslContext()
|
||||
.select(DATABASE_DOCUMENT.fields()).from(DATABASE_DOCUMENT)
|
||||
.where(DATABASE_DOCUMENT.PROJECT_ID.eq(projectId).and(DATABASE_DOCUMENT.VERSION.eq(version)))
|
||||
.fetchOptionalInto(DatabaseDocumentPojo.class);
|
||||
}
|
||||
|
||||
public void update(DatabaseDocumentPojo toPojo) {
|
||||
DatabaseDocumentRecord record = getDslContext().newRecord(DATABASE_DOCUMENT, toPojo);
|
||||
record.changed(DATABASE_DOCUMENT.ID, false);
|
||||
record.changed(DATABASE_DOCUMENT.CREATE_AT, false);
|
||||
record.update();
|
||||
}
|
||||
|
||||
public Optional<DatabaseDocumentPojo> selectNotArchivedByProjectId(Integer projectId) {
|
||||
return getDslContext()
|
||||
.select(DATABASE_DOCUMENT.fields()).from(DATABASE_DOCUMENT)
|
||||
.where(DATABASE_DOCUMENT.PROJECT_ID.eq(projectId).and(DATABASE_DOCUMENT.IS_ARCHIVE.eq(false)))
|
||||
.fetchOptionalInto(DatabaseDocumentPojo.class);
|
||||
}
|
||||
|
||||
public void updateIsArchiveById(Integer id, Boolean isArchive) {
|
||||
this.getDslContext()
|
||||
.update(DATABASE_DOCUMENT).set(DATABASE_DOCUMENT.IS_ARCHIVE, isArchive)
|
||||
.where(DATABASE_DOCUMENT.ID.eq(id).and(DATABASE_DOCUMENT.IS_ARCHIVE.eq(!isArchive)))
|
||||
.execute();
|
||||
}
|
||||
|
||||
public Page<DatabaseDocumentVersionPojo> selectVersionPageByProjectId(Pageable request,
|
||||
Integer projectId) {
|
||||
Condition condition = DATABASE_DOCUMENT.PROJECT_ID.eq(projectId);
|
||||
Integer count = getDslContext()
|
||||
.selectCount().from(DATABASE_DOCUMENT).where(condition)
|
||||
.fetchOne(0, int.class);
|
||||
int total = count == null ? 0 : count;
|
||||
List<DatabaseDocumentVersionPojo> data = getDslContext()
|
||||
.select(
|
||||
DATABASE_DOCUMENT.VERSION,
|
||||
DATABASE_DOCUMENT.ID,
|
||||
DATABASE_DOCUMENT.CREATE_AT
|
||||
)
|
||||
.from(DATABASE_DOCUMENT)
|
||||
.where(condition)
|
||||
.orderBy(getSortFields(request.getSort()))
|
||||
.offset(request.getOffset())
|
||||
.limit(request.getPageSize())
|
||||
.fetchInto(DatabaseDocumentVersionPojo.class);
|
||||
return new PageImpl<>(data, request, total);
|
||||
}
|
||||
}
|
||||
|
@@ -1,59 +0,0 @@
|
||||
package com.databasir.dao.impl;
|
||||
|
||||
import com.databasir.dao.tables.pojos.DatabaseDocumentHistoryPojo;
|
||||
import com.databasir.dao.value.DatabaseDocumentVersionPojo;
|
||||
import lombok.Getter;
|
||||
import org.jooq.Condition;
|
||||
import org.jooq.DSLContext;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageImpl;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import static com.databasir.dao.Tables.DATABASE_DOCUMENT_HISTORY;
|
||||
|
||||
@Repository
|
||||
public class DatabaseDocumentHistoryDao extends BaseDao<DatabaseDocumentHistoryPojo> {
|
||||
|
||||
@Autowired
|
||||
@Getter
|
||||
private DSLContext dslContext;
|
||||
|
||||
public DatabaseDocumentHistoryDao() {
|
||||
super(DATABASE_DOCUMENT_HISTORY, DatabaseDocumentHistoryPojo.class);
|
||||
}
|
||||
|
||||
public Optional<DatabaseDocumentHistoryPojo> selectOptionalByProjectIdAndVersion(Integer projectId, Long version) {
|
||||
return dslContext
|
||||
.selectFrom(DATABASE_DOCUMENT_HISTORY)
|
||||
.where(DATABASE_DOCUMENT_HISTORY.PROJECT_ID.eq(projectId)
|
||||
.and(DATABASE_DOCUMENT_HISTORY.VERSION.eq(version)))
|
||||
.fetchOptionalInto(DatabaseDocumentHistoryPojo.class);
|
||||
}
|
||||
|
||||
public Page<DatabaseDocumentVersionPojo> selectVersionPageByDatabaseDocumentId(Pageable request,
|
||||
Integer schemaDocumentId) {
|
||||
Condition condition = DATABASE_DOCUMENT_HISTORY.DATABASE_DOCUMENT_ID.eq(schemaDocumentId);
|
||||
Integer count = getDslContext()
|
||||
.selectCount().from(DATABASE_DOCUMENT_HISTORY).where(condition)
|
||||
.fetchOne(0, int.class);
|
||||
int total = count == null ? 0 : count;
|
||||
List<DatabaseDocumentVersionPojo> data = getDslContext()
|
||||
.select(
|
||||
DATABASE_DOCUMENT_HISTORY.VERSION,
|
||||
DATABASE_DOCUMENT_HISTORY.DATABASE_DOCUMENT_ID,
|
||||
DATABASE_DOCUMENT_HISTORY.CREATE_AT
|
||||
)
|
||||
.from(DATABASE_DOCUMENT_HISTORY)
|
||||
.where(condition)
|
||||
.orderBy(getSortFields(request.getSort()))
|
||||
.offset(request.getOffset())
|
||||
.limit(request.getPageSize())
|
||||
.fetchInto(DatabaseDocumentVersionPojo.class);
|
||||
return new PageImpl<>(data, request, total);
|
||||
}
|
||||
}
|
@@ -6,6 +6,7 @@ import org.jooq.DSLContext;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import static com.databasir.dao.Tables.TABLE_COLUMN_DOCUMENT;
|
||||
@@ -28,10 +29,15 @@ public class TableColumnDocumentDao extends BaseDao<TableColumnDocumentPojo> {
|
||||
.fetchInto(TableColumnDocumentPojo.class);
|
||||
}
|
||||
|
||||
public void deleteByDatabaseDocumentId(Integer schemaDocumentId) {
|
||||
getDslContext()
|
||||
.deleteFrom(TABLE_COLUMN_DOCUMENT)
|
||||
.where(TABLE_COLUMN_DOCUMENT.DATABASE_DOCUMENT_ID.eq(schemaDocumentId))
|
||||
.execute();
|
||||
public List<TableColumnDocumentPojo> selectByDatabaseDocumentIdAndTableIdIn(Integer schemaDocumentId,
|
||||
List<Integer> tableIdIn) {
|
||||
if (tableIdIn == null || tableIdIn.isEmpty()) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
return getDslContext()
|
||||
.select(TABLE_COLUMN_DOCUMENT.fields()).from(TABLE_COLUMN_DOCUMENT)
|
||||
.where(TABLE_COLUMN_DOCUMENT.DATABASE_DOCUMENT_ID.eq(schemaDocumentId)
|
||||
.and(TABLE_COLUMN_DOCUMENT.TABLE_DOCUMENT_ID.in(tableIdIn)))
|
||||
.fetchInto(TableColumnDocumentPojo.class);
|
||||
}
|
||||
}
|
||||
|
@@ -6,6 +6,7 @@ import org.jooq.DSLContext;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import static com.databasir.dao.Tables.TABLE_DOCUMENT;
|
||||
@@ -33,4 +34,16 @@ public class TableDocumentDao extends BaseDao<TableDocumentPojo> {
|
||||
.deleteFrom(TABLE_DOCUMENT).where(TABLE_DOCUMENT.DATABASE_DOCUMENT_ID.eq(schemaDocumentId))
|
||||
.execute();
|
||||
}
|
||||
|
||||
public List<TableDocumentPojo> selectByDatabaseDocumentIdAndIdIn(Integer databaseDocumentId,
|
||||
List<Integer> idList) {
|
||||
if (idList == null || idList.isEmpty()) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
return getDslContext()
|
||||
.selectFrom(TABLE_DOCUMENT)
|
||||
.where(TABLE_DOCUMENT.DATABASE_DOCUMENT_ID.eq(databaseDocumentId)
|
||||
.and(TABLE_DOCUMENT.ID.in(idList)))
|
||||
.fetchInto(TableDocumentPojo.class);
|
||||
}
|
||||
}
|
||||
|
@@ -6,6 +6,7 @@ import org.jooq.DSLContext;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import static com.databasir.dao.Tables.TABLE_INDEX_DOCUMENT;
|
||||
@@ -21,16 +22,22 @@ public class TableIndexDocumentDao extends BaseDao<TableIndexDocumentPojo> {
|
||||
super(TABLE_INDEX_DOCUMENT, TableIndexDocumentPojo.class);
|
||||
}
|
||||
|
||||
public List<TableIndexDocumentPojo> selectByDatabaseMetaId(Integer schemaMetaId) {
|
||||
public List<TableIndexDocumentPojo> selectByDatabaseMetaId(Integer documentId) {
|
||||
return getDslContext()
|
||||
.select(TABLE_INDEX_DOCUMENT.fields()).from(TABLE_INDEX_DOCUMENT)
|
||||
.where(TABLE_INDEX_DOCUMENT.DATABASE_DOCUMENT_ID.eq(schemaMetaId))
|
||||
.where(TABLE_INDEX_DOCUMENT.DATABASE_DOCUMENT_ID.eq(documentId))
|
||||
.fetchInto(TableIndexDocumentPojo.class);
|
||||
}
|
||||
|
||||
public void deleteByDatabaseMetaId(Integer schemaMetaId) {
|
||||
getDslContext()
|
||||
.deleteFrom(TABLE_INDEX_DOCUMENT).where(TABLE_INDEX_DOCUMENT.DATABASE_DOCUMENT_ID.eq(schemaMetaId))
|
||||
.execute();
|
||||
public List<TableIndexDocumentPojo> selectByDatabaseDocumentIdAndIdIn(Integer documentId,
|
||||
List<Integer> tableIdIn) {
|
||||
if (tableIdIn == null || tableIdIn.isEmpty()) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
return getDslContext()
|
||||
.select(TABLE_INDEX_DOCUMENT.fields()).from(TABLE_INDEX_DOCUMENT)
|
||||
.where(TABLE_INDEX_DOCUMENT.DATABASE_DOCUMENT_ID.eq(documentId)
|
||||
.and(TABLE_INDEX_DOCUMENT.TABLE_DOCUMENT_ID.in(tableIdIn)))
|
||||
.fetchInto(TableIndexDocumentPojo.class);
|
||||
}
|
||||
}
|
||||
|
@@ -6,6 +6,7 @@ import org.jooq.DSLContext;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import static com.databasir.dao.Tables.TABLE_TRIGGER_DOCUMENT;
|
||||
@@ -28,10 +29,15 @@ public class TableTriggerDocumentDao extends BaseDao<TableTriggerDocumentPojo> {
|
||||
.fetchInto(TableTriggerDocumentPojo.class);
|
||||
}
|
||||
|
||||
public void deleteByDatabaseDocumentId(Integer schemaDocumentId) {
|
||||
getDslContext()
|
||||
.deleteFrom(TABLE_TRIGGER_DOCUMENT)
|
||||
.where(TABLE_TRIGGER_DOCUMENT.DATABASE_DOCUMENT_ID.eq(schemaDocumentId))
|
||||
.execute();
|
||||
public List<TableTriggerDocumentPojo> selectByDatabaseDocumentIdAndIdIn(Integer documentId,
|
||||
List<Integer> tableIdIn) {
|
||||
if (tableIdIn == null || tableIdIn.isEmpty()) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
return getDslContext()
|
||||
.select(TABLE_TRIGGER_DOCUMENT.fields()).from(TABLE_TRIGGER_DOCUMENT)
|
||||
.where(TABLE_TRIGGER_DOCUMENT.DATABASE_DOCUMENT_ID.eq(documentId)
|
||||
.and(TABLE_TRIGGER_DOCUMENT.TABLE_DOCUMENT_ID.in(tableIdIn)))
|
||||
.fetchInto(TableTriggerDocumentPojo.class);
|
||||
}
|
||||
}
|
||||
|
@@ -7,7 +7,7 @@ import java.time.LocalDateTime;
|
||||
@Data
|
||||
public class DatabaseDocumentVersionPojo {
|
||||
|
||||
private Integer databaseDocumentId;
|
||||
private Integer id;
|
||||
|
||||
private Long version;
|
||||
|
||||
|
@@ -123,21 +123,9 @@ CREATE TABLE IF NOT EXISTS database_document
|
||||
product_name TEXT NOT NULL,
|
||||
product_version TEXT NOT NULL,
|
||||
version BIGINT NOT NULL DEFAULT 1,
|
||||
is_archive BOOLEAN NOT NULL DEFAULT FALSE,
|
||||
update_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
create_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
CONSTRAINT uk_project_id UNIQUE (project_id)
|
||||
) CHARSET utf8mb4
|
||||
COLLATE utf8mb4_unicode_ci;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS database_document_history
|
||||
(
|
||||
id INT PRIMARY KEY AUTO_INCREMENT,
|
||||
project_id INT NOT NULL,
|
||||
database_document_id INT NOT NULL,
|
||||
database_document_object JSON DEFAULT NULL,
|
||||
version BIGINT NOT NULL,
|
||||
create_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
CONSTRAINT uk_connection_id_version UNIQUE (database_document_id, version),
|
||||
INDEX idx_project_id (project_id)
|
||||
) CHARSET utf8mb4
|
||||
COLLATE utf8mb4_unicode_ci;
|
||||
|
Reference in New Issue
Block a user