!110 feat: 支持各源数据库导出sql,数据库迁移部分bug修复

* feat: 各源数据库导出
* fix: 数据库迁移 bug修复
This commit is contained in:
zongyangleo
2024-03-26 09:05:28 +00:00
committed by Coder慌
parent 4b3ed1310d
commit 2acc295259
31 changed files with 821 additions and 424 deletions

View File

@@ -25,6 +25,9 @@ type MetaData interface {
// 获取指定表名的所有列元信息
GetColumns(tableNames ...string) ([]Column, error)
// 根据数据库类型修复字段长度、精度等
FixColumn(column *Column)
// 获取表主键字段名,没有主键标识则默认第一个字段
GetPrimaryKey(tableName string) (string, error)
@@ -32,7 +35,7 @@ type MetaData interface {
GetTableIndex(tableName string) ([]Index, error)
// 获取建表ddl
GetTableDDL(tableName string) (string, error)
GetTableDDL(tableName string, dropBeforeCreate bool) (string, error)
GenerateTableDDL(columns []Column, tableInfo Table, dropBeforeCreate bool) []string
@@ -44,6 +47,9 @@ type MetaData interface {
GetDataConverter() DataConverter
}
// GenerateSQLStepFunc 生成insert sql的step函数用于生成insert sql时每生成100条sql时调用
type GenerateSQLStepFunc func(sqlArr []string)
// 数据库服务实例信息
type DbServer struct {
Version string `json:"version"` // 版本信息
@@ -100,6 +106,7 @@ type Index struct {
IndexComment string `json:"indexComment"` // 备注
SeqInIndex int `json:"seqInIndex"`
IsUnique bool `json:"isUnique"`
IsPrimaryKey bool `json:"isPrimaryKey"` // 是否是主键索引,某些情况需要判断并过滤掉主键索引
}
type ColumnDataType string
@@ -152,6 +159,13 @@ type DataConverter interface {
// 根据数据类型解析数据为符合要求的指定类型等
ParseData(dbColumnValue any, dataType DataType) any
// WrapValue 根据数据类型包装value
// 1.数字型:不需要引号,
// 2.文本型:需要用引号包裹,单引号需要转义,换行符转义,
// 3.date型需要格式化成对应的字符串timehh:mm:ss.SSS date: yyyy-mm-dd datetime:
// 4.特殊oracle date型需要用函数包裹to_timestamp('%s', 'yyyy-mm-dd hh24:mi:ss')
WrapValue(dbColumnValue any, dataType DataType) string
}
// ------------------------- 元数据sql操作 -------------------------