mirror of
https://github.com/CarmJos/EasySQL.git
synced 2026-06-04 07:18:23 +08:00
feat(migrate): 添加对表迁移的操作 (#69)
* DELETE语句缺少AND关键词连接 * feat(migrate): 添加对表迁移的操作 * Update SQLMigrate.java Co-authored-by: sonatype-lift[bot] <37194012+sonatype-lift[bot]@users.noreply.github.com> * feat(migrate): 添加对表迁移的操作 --------- Co-authored-by: sonatype-lift[bot] <37194012+sonatype-lift[bot]@users.noreply.github.com>
This commit is contained in:
@@ -9,6 +9,7 @@ import cc.carm.lib.easysql.api.function.SQLBiFunction;
|
||||
import cc.carm.lib.easysql.api.function.SQLDebugHandler;
|
||||
import cc.carm.lib.easysql.api.function.SQLExceptionHandler;
|
||||
import cc.carm.lib.easysql.api.function.SQLFunction;
|
||||
import cc.carm.lib.easysql.api.migrate.SQLMigrate;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.slf4j.Logger;
|
||||
@@ -265,6 +266,13 @@ public interface SQLManager {
|
||||
*/
|
||||
QueryBuilder createQuery();
|
||||
|
||||
/**
|
||||
* 新建一个迁移操作。
|
||||
*
|
||||
* @return {@link SQLMigrate}
|
||||
*/
|
||||
SQLMigrate createMigrate();
|
||||
|
||||
/**
|
||||
* 创建一条插入操作。
|
||||
*
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
package cc.carm.lib.easysql.api.enums;
|
||||
|
||||
/**
|
||||
* 2022/11/28<br>
|
||||
* EasySQL<br>
|
||||
*
|
||||
* @author huanmeng_qwq
|
||||
*/
|
||||
public class MigrateResult {
|
||||
/**
|
||||
* 旧表不存在
|
||||
*/
|
||||
public static final MigrateResult OLD_TABLE_NOT_EXIST = new MigrateResult(true);
|
||||
|
||||
/**
|
||||
* 新表已存在
|
||||
*/
|
||||
public static final MigrateResult NEW_TABLE_EXIST = new MigrateResult(false);
|
||||
|
||||
/**
|
||||
* 新表字段为空
|
||||
*/
|
||||
public static final MigrateResult NEW_COLUMN_EMPTY = new MigrateResult(false);
|
||||
|
||||
/**
|
||||
* 旧表字段为在新表这设置对应的字段名
|
||||
*/
|
||||
public static final MigrateResult COLUMN_NOT_SET = new MigrateResult(false);
|
||||
|
||||
/**
|
||||
* 迁移成功
|
||||
*/
|
||||
public static final MigrateResult SUCCESS = new MigrateResult(true);
|
||||
|
||||
private final boolean success;
|
||||
private Throwable error;
|
||||
|
||||
MigrateResult(boolean success) {
|
||||
this.success = success;
|
||||
}
|
||||
|
||||
public MigrateResult(boolean success, Throwable error) {
|
||||
this.success = success;
|
||||
this.error = error;
|
||||
}
|
||||
|
||||
public static MigrateResult from(MigrateResult migrateResult, Throwable error) {
|
||||
return new MigrateResult(migrateResult.success, error);
|
||||
}
|
||||
|
||||
public boolean success() {
|
||||
return success;
|
||||
}
|
||||
|
||||
public Throwable error() {
|
||||
return error;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
package cc.carm.lib.easysql.api.migrate;
|
||||
|
||||
import cc.carm.lib.easysql.api.enums.IndexType;
|
||||
import cc.carm.lib.easysql.api.enums.MigrateResult;
|
||||
import org.jetbrains.annotations.Contract;
|
||||
|
||||
import java.sql.SQLException;
|
||||
|
||||
/**
|
||||
* 将现有的表结构与数据迁移之新的表中
|
||||
*
|
||||
* @author huanmeng_qwq
|
||||
* @since 0.4.7
|
||||
*/
|
||||
public interface SQLMigrate {
|
||||
|
||||
/**
|
||||
* 为迁移工作定义前后的表名信息
|
||||
*
|
||||
* @param oldTableName 旧表名
|
||||
* @param newTableName 新表名
|
||||
* @param newTableSettings 新表的设置
|
||||
* @return {@link SQLMigrate}
|
||||
*/
|
||||
@Contract("null,_,_ -> fail;!null,_,_ -> this")
|
||||
SQLMigrate tableName(String oldTableName, String newTableName, String newTableSettings);
|
||||
|
||||
/**
|
||||
* 为迁移工作定义前后的列名信息
|
||||
*
|
||||
* @param oldColumnName 旧列名
|
||||
* @param newColumnName 新列名
|
||||
* @param newColumnSettings 新列的设置
|
||||
* @return {@link SQLMigrate}
|
||||
*/
|
||||
@Contract("null,_,_ -> fail;!null,_,_ -> this")
|
||||
default SQLMigrate column(String oldColumnName, String newColumnName, String newColumnSettings) {
|
||||
return column(oldColumnName, newColumnName, newColumnSettings, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 为迁移工作定义前后的列名信息
|
||||
*
|
||||
* @param oldColumnName 旧列名
|
||||
* @param newColumnName 新列名
|
||||
* @param newColumnSettings 新列的设置
|
||||
* @param indexType 索引类型
|
||||
* @return {@link SQLMigrate}
|
||||
*/
|
||||
@Contract("null,_,_,_ -> fail;!null,_,_,_ -> this")
|
||||
SQLMigrate column(String oldColumnName, String newColumnName, String newColumnSettings, IndexType indexType);
|
||||
|
||||
/**
|
||||
* 为迁移工作定义前后的自增列名信息
|
||||
*
|
||||
* @param oldColumnName 旧列名
|
||||
* @param newColumnName 新列名
|
||||
* @return {@link SQLMigrate}
|
||||
*/
|
||||
@Contract("null,_->fail;!null,_ -> this")
|
||||
SQLMigrate autoIncrementColumn(String oldColumnName, String newColumnName);
|
||||
|
||||
/**
|
||||
* 迁移数据
|
||||
*
|
||||
* @return {@link MigrateResult}
|
||||
*/
|
||||
MigrateResult migrate() throws SQLException;
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user