签入脚本
This commit is contained in:
@@ -0,0 +1,112 @@
|
||||
// Package migrate 整库迁移
|
||||
//
|
||||
// 处理流程:源库内省 → 中间表示 → 目标方言 DDL → 分批搬运数据 → 序列修复。
|
||||
// 独立于业务基座(不依赖 dao 与 logic),经 gdb 动态连接源库与目标库进行裸读裸写,
|
||||
// 全程不触发全局钩子(租户隔离、软删除、审计盖章),保证数据原样落库。
|
||||
package migrate
|
||||
|
||||
// ============================== 中间类型常量 ==============================
|
||||
|
||||
// 中间类型常量
|
||||
//
|
||||
// 源方言类型归一后的规范形态,各方言渲染器再翻译为目标方言
|
||||
const (
|
||||
TypeBool = "bool"
|
||||
TypeTinyint = "tinyint"
|
||||
TypeSmallint = "smallint"
|
||||
TypeInt = "int"
|
||||
TypeBigint = "bigint"
|
||||
TypeFloat = "float"
|
||||
TypeDouble = "double"
|
||||
TypeDecimal = "decimal"
|
||||
TypeVarchar = "varchar"
|
||||
TypeChar = "char"
|
||||
TypeText = "text"
|
||||
TypeTinytext = "tinytext"
|
||||
TypeMediumText = "mediumtext"
|
||||
TypeLongText = "longtext"
|
||||
TypeDate = "date"
|
||||
TypeTime = "time"
|
||||
TypeDateTime = "datetime"
|
||||
TypeBlob = "blob"
|
||||
TypeJson = "json"
|
||||
TypeEnum = "enum"
|
||||
TypeSet = "set"
|
||||
TypeOther = "other"
|
||||
)
|
||||
|
||||
// ============================== 迁移任务参数 ==============================
|
||||
|
||||
// Options 迁移任务参数
|
||||
type Options struct {
|
||||
Src DSN // 源库连接
|
||||
Dst DSN // 目标库连接
|
||||
|
||||
DropTargetFirst bool // 迁移前清空目标库全部表
|
||||
Tables []string // 表白名单(空=全部)
|
||||
BatchSize int // 数据搬运批大小(默认 500)
|
||||
}
|
||||
|
||||
// DSN 数据库连接要素
|
||||
//
|
||||
// SQLite 仅使用 Database 作为文件路径,Host 与 Port 忽略
|
||||
type DSN struct {
|
||||
Type string // 驱动名:mysql/pgsql/sqlite/mssql/oracle
|
||||
Host string // 主机
|
||||
Port string // 端口
|
||||
Database string // 数据库名或文件路径
|
||||
Username string // 用户名
|
||||
Password string // 密码
|
||||
}
|
||||
|
||||
// ============================== 元数据中间表示 ==============================
|
||||
|
||||
// TableMeta 源库表元数据
|
||||
type TableMeta struct {
|
||||
Name string // 表名
|
||||
Comment string // 表注释
|
||||
Columns []ColumnMeta // 列集合
|
||||
Indexes []IndexMeta // 二级索引集合
|
||||
}
|
||||
|
||||
// ColumnMeta 列元数据
|
||||
//
|
||||
// Type 为中间类型常量
|
||||
type ColumnMeta struct {
|
||||
Name string // 列名
|
||||
Type string // 中间类型
|
||||
Length int // varchar/char 长度;decimal 精度
|
||||
Scale int // decimal 小数位
|
||||
EnumVals []string // 枚举值集合
|
||||
Nullable bool // 是否可空
|
||||
Default string // 默认值原文(空=无默认);表达式类原样保留
|
||||
AutoInc bool // 是否自增
|
||||
Comment string // 列注释
|
||||
IsPK bool // 是否主键
|
||||
}
|
||||
|
||||
// IndexMeta 索引元数据
|
||||
//
|
||||
// 不含主键,主键经 ColumnMeta.IsPK 表达
|
||||
type IndexMeta struct {
|
||||
Unique bool // 是否唯一索引
|
||||
Name string // 索引名
|
||||
Columns []string // 索引列集合
|
||||
}
|
||||
|
||||
// ============================== 迁移汇总 ==============================
|
||||
|
||||
// Report 迁移汇总
|
||||
type Report struct {
|
||||
TableTotal int // 待迁移表总数
|
||||
TableOK int // 成功表数
|
||||
TableFailed int // 失败表数
|
||||
RowTotal int64 // 总搬运行数
|
||||
Failed []FailedTable // 失败表记录
|
||||
}
|
||||
|
||||
// FailedTable 失败表记录
|
||||
type FailedTable struct {
|
||||
Table string // 表名
|
||||
Err string // 错误信息
|
||||
}
|
||||
Reference in New Issue
Block a user