model

package
v1.0.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 5, 2022 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Copyright © 2020 Marvin

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BaseModel

type BaseModel struct {
	Comment   string `gorm:"type:varchar(1000);comment:comment content" json:"comment"`
	CreatedAt string `gorm:"type:datetime(3) default current_timestamp(3);comment:'创建时间'" json:"createdAt"`
	UpdatedAt string `gorm:"type:datetime(3) default current_timestamp(3) on update current_timestamp(3);comment:'更新时间'" json:"updatedAt"`
	*MetaDB   `gorm:"-" json:"-"`
}

BaseModel returns model struct base fields

func (*BaseModel) BeforeCreate

func (v *BaseModel) BeforeCreate(db *gorm.DB) (err error)

func (*BaseModel) BeforeUpdate

func (v *BaseModel) BeforeUpdate(db *gorm.DB) (err error)

type ColumnRuleMap

type ColumnRuleMap struct {
	ID               uint   `gorm:"primary_key;autoIncrement;comment:'自增编号'" json:"id"`
	SourceSchemaName string `gorm:"not null;index:unique_schema_table_col,unique;comment:'源端库 schema'" json:"source_schema_name"`
	SourceTableName  string `gorm:"not null;index:unique_schema_table_col,unique;comment:'源端表名'" json:"source_table_name"`
	SourceColumnName string `gorm:"not null;index:unique_schema_table_col,unique;comment:'源端表字段列名'" json:"source_column_name"`
	SourceColumnType string `gorm:"not null;index:idx_source_col;comment:'源端表字段类型'" json:"source_column_type"`
	TargetColumnType string `gorm:"not null;index:idx_source_col;comment:'目标表字段类型'" json:"target_column_type"`
	ReverseMode      string `gorm:"not null;index:idx_reverse_mode;comment:'表结构转换模式 ReverseO2M/ReverseM2O'" json:"reverse_mode"`
	*BaseModel
}
上下游字段类型映射表

数据类型转换优先级: column > table > schema > build-in 自定义列转换规则 - 字段列级别

func (*ColumnRuleMap) Create

func (rw *ColumnRuleMap) Create(ctx context.Context, createS interface{}) error

func (*ColumnRuleMap) Detail

func (rw *ColumnRuleMap) Detail(ctx context.Context, detailS interface{}) (interface{}, error)

type DataCompareMeta

type DataCompareMeta struct {
	ID               uint   `gorm:"primary_key;autoIncrement;comment:'自增编号'" json:"id"`
	SourceSchemaName string `gorm:"not null;index:idx_schema_table_range;comment:'源端 schema'" json:"source_schema_name"`
	SourceTableName  string `gorm:"not null;index:idx_schema_table_range;comment:'源端表名'" json:"source_table_name"`
	SourceColumnInfo string `gorm:"type:text;comment:'源端查询字段信息'" json:"source_column_info"`
	TargetSchemaName string `gorm:"not null;comment:'目标端 schema'" json:"target_schema_name"`
	TargetTableName  string `gorm:"not null;comment:'目标端表名'" json:"target_table_name"`
	TargetColumnInfo string `gorm:"type:text;comment:'目标端查询字段信息'" json:"target_column_info"`
	WhereColumn      string `gorm:"comment:'查询类型字段列'" json:"where_column"` // 值为空则是指定 WHERE 对比或者 WHERE 1=1 对比
	WhereRange       string `gorm:"not null;index:idx_schema_table_range;comment:'查询 where 条件'" json:"where_range"`
	IsPartition      string `gorm:"comment:'是否是分区表'" json:"is_partition"` // 同步转换统一转换成非分区表,此处只做标志
	*BaseModel
}

数据校验元数据表

func NewDataCompareMetaModel

func NewDataCompareMetaModel(gormDB *gorm.DB) *DataCompareMeta

func (*DataCompareMeta) BatchCreate

func (rw *DataCompareMeta) BatchCreate(ctx context.Context, createS interface{}, batchSize int) error

func (*DataCompareMeta) Create

func (rw *DataCompareMeta) Create(ctx context.Context, createS interface{}) error

func (*DataCompareMeta) Delete

func (rw *DataCompareMeta) Delete(ctx context.Context, deleteS interface{}) error

func (*DataCompareMeta) Detail

func (rw *DataCompareMeta) Detail(ctx context.Context, detailS interface{}) (interface{}, error)

func (*DataCompareMeta) DistinctTableName

func (rw *DataCompareMeta) DistinctTableName(ctx context.Context, detailS interface{}) (interface{}, error)

func (*DataCompareMeta) Truncate

func (rw *DataCompareMeta) Truncate(ctx context.Context, truncateS interface{}) error

type DefaultValueMap

type DefaultValueMap struct {
	ID                 uint   `gorm:"primary_key;autoIncrement;comment:'自增编号'" json:"id"`
	SourceDefaultValue string `gorm:"not null;index:unique_source_default,unique;comment:'源端默认值'" json:"source_default_value"`
	TargetDefaultValue string `gorm:"not null;index:idx_target_default;comment:'目标默认值'" json:"target_default_value"`
	ReverseMode        string `gorm:"not null;index:idx_reverse_mode;comment:'表结构转换模式 ReverseO2M/ReverseM2O'" json:"reverse_mode"`
	*BaseModel
}

自定义字段默认值转换规则 - global 级别

func (*DefaultValueMap) Create

func (rw *DefaultValueMap) Create(ctx context.Context, createS interface{}) error

func (*DefaultValueMap) Detail

func (rw *DefaultValueMap) Detail(ctx context.Context, detailS interface{}) (interface{}, error)

func (*DefaultValueMap) RowsAffected

func (rw *DefaultValueMap) RowsAffected(ctx context.Context, defaultVal *DefaultValueMap) int64

type FullSyncMeta

type FullSyncMeta struct {
	ID               uint   `gorm:"primary_key;autoIncrement;comment:'自增编号'" json:"id"`
	SourceSchemaName string `gorm:"not null;index:idx_schema_table_rowid;comment:'源端 schema'" json:"source_schema_name"`
	SourceTableName  string `gorm:"not null;index:idx_schema_table_rowid;comment:'源端表名'" json:"source_table_name"`
	TargetSchemaName string `gorm:"not null;comment:'目标端 schema'" json:"target_schema_name"`
	TargetTableName  string `gorm:"not null;comment:'目标端表名'" json:"target_table_name"`
	GlobalSCN        uint64 `gorm:"comment:'全局 SCN'" json:"global_scn"`
	SourceColumnInfo string `gorm:"type:text;comment:'源端查询字段信息'" json:"source_column_info"`
	SourceRowidInfo  string `gorm:"type:varchar(300);not null;index:idx_schema_table_rowid;comment:'表 rowid 切分信息'" json:"source_rowid_info"`
	SyncMode         string `gorm:"not null;comment:'同步模式'" json:"sync_mode"`
	IsPartition      string `gorm:"comment:'是否是分区表'" json:"is_partition"` // 同步转换统一转换成非分区表,此处只做标志
	CSVFile          string `gorm:"type:varchar(300);comment:'csv 文件名'" json:"csv_file"`
	*BaseModel
}

全量同步元数据表

func (*FullSyncMeta) BatchCreate

func (rw *FullSyncMeta) BatchCreate(ctx context.Context, createS interface{}, batchSize int) error

func (*FullSyncMeta) DeleteBySchemaSyncMode

func (rw *FullSyncMeta) DeleteBySchemaSyncMode(ctx context.Context, deleteS interface{}) error

func (*FullSyncMeta) DeleteBySchemaTableRowid

func (rw *FullSyncMeta) DeleteBySchemaTableRowid(ctx context.Context, deleteS interface{}) error

清理并更新同步任务元数据表 1、全量每成功同步一张表记录,再清理记录 2、更新同步数据表元信息

func (*FullSyncMeta) Detail

func (rw *FullSyncMeta) Detail(ctx context.Context, detailS interface{}) (interface{}, error)

func (*FullSyncMeta) DistinctTableName

func (rw *FullSyncMeta) DistinctTableName(ctx context.Context, detailS interface{}) (interface{}, error)

func (*FullSyncMeta) String

func (rw *FullSyncMeta) String() string

type IncrSyncMeta

type IncrSyncMeta struct {
	ID               uint   `gorm:"primary_key;autoIncrement;comment:'自增编号'" json:"id"`
	SourceSchemaName string `gorm:"not null;index:unique_schema_table,unique;comment:'源端 schema'" json:"source_schema_name"`
	SourceTableName  string `gorm:"not null;index:unique_schema_table,unique;comment:'源端表名'" json:"source_table_name"`
	GlobalSCN        uint64 `gorm:"comment:'全局 SCN'" json:"global_scn"`
	SourceTableSCN   uint64 `gorm:"comment:'表同步 SCN'" json:"source_table_scn"`
	IsPartition      string `gorm:"comment:'是否是分区表'" json:"is_partition"` // 同步转换统一转换成非分区表,此处只做标志
	*BaseModel
}

增量同步元数据表

func (*IncrSyncMeta) BatchCreate

func (rw *IncrSyncMeta) BatchCreate(ctx context.Context, createS interface{}, batchSize int) error

func (*IncrSyncMeta) CountsBySchemaTable

func (rw *IncrSyncMeta) CountsBySchemaTable(ctx context.Context, detailS interface{}) (int64, error)

func (*IncrSyncMeta) DetailBySchema

func (rw *IncrSyncMeta) DetailBySchema(ctx context.Context, detailS interface{}) (interface{}, error)

func (*IncrSyncMeta) MinGlobalSCNBySchema

func (rw *IncrSyncMeta) MinGlobalSCNBySchema(ctx context.Context, detailS interface{}) (uint64, error)

func (*IncrSyncMeta) MinSourceTableSCNBySchema

func (rw *IncrSyncMeta) MinSourceTableSCNBySchema(ctx context.Context, detailS interface{}) (uint64, error)

func (*IncrSyncMeta) Update

func (rw *IncrSyncMeta) Update(ctx context.Context, detailS interface{}) error

type MetaDB

type MetaDB struct {
	Gorm *gorm.DB
}

func WrapGormDB

func WrapGormDB(gormDB *gorm.DB) *MetaDB

func (*MetaDB) DB

func (g *MetaDB) DB(ctx context.Context) *gorm.DB

func (*MetaDB) InitDefaultValue

func (g *MetaDB) InitDefaultValue(ctx context.Context) error

func (*MetaDB) MigrateTables

func (g *MetaDB) MigrateTables() (err error)

type ReverseRuleMap

type ReverseRuleMap struct {
	*ColumnRuleMap
	*TableRuleMap
	*SchemaRuleMap
	*DefaultValueMap
}

func NewReverseModel

func NewReverseModel(gormDB *gorm.DB) *ReverseRuleMap

type SchemaRuleMap

type SchemaRuleMap struct {
	ID               uint   `gorm:"primary_key;autoIncrement;comment:'自增编号'" json:"id"`
	SourceSchemaName string `gorm:"not null;index:unique_schema_col,unique;comment:'源端库 schema'" json:"source_schema_name"`
	SourceColumnType string `gorm:"not null;index:unique_schema_col,unique;comment:'源端表字段类型'" json:"source_column_type"`
	TargetColumnType string `gorm:"not null;index:idx_target_col;comment:'目标表字段类型'" json:"target_column_type"`
	ReverseMode      string `gorm:"not null;index:idx_reverse_mode;comment:'表结构转换模式 ReverseO2M/ReverseM2O'" json:"reverse_mode"`
	*BaseModel
}

自定义库转换规则 - schema 级别

func (*SchemaRuleMap) Create

func (rw *SchemaRuleMap) Create(ctx context.Context, createS interface{}) error

func (*SchemaRuleMap) Detail

func (rw *SchemaRuleMap) Detail(ctx context.Context, detailS interface{}) (interface{}, error)

type SyncMeta

type SyncMeta struct {
	*WaitSyncMeta
	*FullSyncMeta
	*IncrSyncMeta
}

func NewSyncMetaModel

func NewSyncMetaModel(gormDB *gorm.DB) *SyncMeta

type TableErrorDetail

type TableErrorDetail struct {
	ID               uint   `gorm:"primary_key;autoIncrement;comment:'自增编号'" json:"id"`
	SourceSchemaName string `gorm:"not null;index:idx_schema_table_mode;comment:'源端 schema'" json:"source_schema_name"`
	SourceTableName  string `gorm:"not null;index:idx_schema_table_mode;comment:'源端表名'" json:"source_table_name"`
	RunMode          string `gorm:"not null;index:idx_schema_table_mode;comment:'运行模式'" json:"run_mode"`
	InfoSources      string `gorm:"not null;comment:'信息来源'" json:"info_sources"`
	RunStatus        string `gorm:"not null;comment:'运行状态'" json:"run_status"`
	InfoDetail       string `gorm:"not null;comment:'信息详情'" json:"info_detail"`
	ErrorDetail      string `gorm:"not null;comment:'错误详情'" json:"error_detail"`
	*BaseModel
}

表错误详情 用于 reverse 和 check 模式

func NewTableErrorDetailModel

func NewTableErrorDetailModel(gormDB *gorm.DB) *TableErrorDetail

func (*TableErrorDetail) Counts

func (rw *TableErrorDetail) Counts(ctx context.Context, tableErrDetail interface{}) (int64, error)

func (*TableErrorDetail) CountsBySchema

func (rw *TableErrorDetail) CountsBySchema(ctx context.Context, tableErrDetail interface{}) (int64, error)

func (*TableErrorDetail) Create

func (rw *TableErrorDetail) Create(ctx context.Context, createS interface{}) error

func (*TableErrorDetail) Detail

func (rw *TableErrorDetail) Detail(ctx context.Context, detailS interface{}) (interface{}, error)

type TableRuleMap

type TableRuleMap struct {
	ID               uint   `gorm:"primary_key;autoIncrement;comment:'自增编号'" json:"id"`
	SourceSchemaName string `gorm:"not null;index:unique_schema_table_col,unique;comment:'源端库 schema'" json:"source_schema_name"`
	SourceTableName  string `gorm:"not null;index:unique_schema_table_col,unique;comment:'源端表名'" json:"source_table_name"`
	SourceColumnType string `gorm:"not null;index:unique_schema_table_col,unique;comment:'源端表字段类型'" json:"source_column_type"`
	TargetColumnType string `gorm:"not null;index:idx_target_col;comment:'目标表字段类型'" json:"target_column_type"`
	ReverseMode      string `gorm:"not null;index:idx_reverse_mode;comment:'表结构转换模式 ReverseO2M/ReverseM2O'" json:"reverse_mode"`
	*BaseModel
}

自定义表转换规则 - table 级别

func (*TableRuleMap) Create

func (rw *TableRuleMap) Create(ctx context.Context, createS interface{}) error

func (*TableRuleMap) Detail

func (rw *TableRuleMap) Detail(ctx context.Context, detailS interface{}) (interface{}, error)

type Transaction

type Transaction struct {
	*MetaDB
}

func NewCommonModel

func NewCommonModel(gormDB *gorm.DB) *Transaction

func (*Transaction) CreateDataCompareMetaAndUpdateWaitSyncMeta

func (rw *Transaction) CreateDataCompareMetaAndUpdateWaitSyncMeta(ctx context.Context, dataDiffMeta *DataCompareMeta, waitSyncMeta *WaitSyncMeta) error

func (*Transaction) CreateFullSyncMetaAndUpdateWaitSyncMeta

func (rw *Transaction) CreateFullSyncMetaAndUpdateWaitSyncMeta(ctx context.Context, fullSyncMeta *FullSyncMeta, waitSyncMeta *WaitSyncMeta) error

func (*Transaction) DeleteIncrSyncMetaAndWaitSyncMeta

func (rw *Transaction) DeleteIncrSyncMetaAndWaitSyncMeta(ctx context.Context, incrSyncMeta *IncrSyncMeta, waitSyncMeta *WaitSyncMeta) error

func (*Transaction) UpdateIncrSyncMetaSCNByArchivedLog

func (rw *Transaction) UpdateIncrSyncMetaSCNByArchivedLog(ctx context.Context,
	sourceSchemaName string, logFileEndSCN uint64, transferTableSlice []string) error

func (*Transaction) UpdateIncrSyncMetaSCNByCurrentRedo

func (rw *Transaction) UpdateIncrSyncMetaSCNByCurrentRedo(ctx context.Context,
	sourceSchemaName string, lastRedoLogMaxSCN, logFileStartSCN, logFileEndSCN uint64) error

func (*Transaction) UpdateIncrSyncMetaSCNByNonCurrentRedo

func (rw *Transaction) UpdateIncrSyncMetaSCNByNonCurrentRedo(ctx context.Context,
	sourceSchemaName string, lastRedoLogMaxSCN, logFileStartSCN, logFileEndSCN uint64, transferTableSlice []string) error

type WaitSyncMeta

type WaitSyncMeta struct {
	ID               uint   `gorm:"primary_key;autoIncrement;comment:'自增编号'" json:"id"`
	SourceSchemaName string `gorm:"not null;index:idx_schema_table_mode,unique;comment:'源端 schema'" json:"source_schema_name"`
	SourceTableName  string `gorm:"not null;index:idx_schema_table_mode,unique;comment:'源端表名'" json:"source_table_name"`
	SyncMode         string `gorm:"not null;index:idx_schema_table_mode,unique;comment:'同步模式'" json:"sync_mode"`
	FullGlobalSCN    uint64 `gorm:"comment:'全量全局 SCN'" json:"full_global_scn"`
	FullSplitTimes   int    `gorm:"comment:'全量任务切分 SQL 次数'" json:"full_split_times"`
	IsPartition      string `gorm:"comment:'是否是分区表'" json:"is_partition"` // 同步转换统一转换成非分区表,此处只做标志
	*BaseModel
}

同步元数据表

func (*WaitSyncMeta) Create

func (rw *WaitSyncMeta) Create(ctx context.Context, createS interface{}) error

func (*WaitSyncMeta) Delete

func (rw *WaitSyncMeta) Delete(ctx context.Context, deleteS interface{}) error

func (*WaitSyncMeta) Detail

func (rw *WaitSyncMeta) Detail(ctx context.Context, detailS interface{}) (interface{}, error)

Detail returns wait sync meta records

func (*WaitSyncMeta) DetailBySchema

func (rw *WaitSyncMeta) DetailBySchema(ctx context.Context, detailS interface{}) (interface{}, error)

func (*WaitSyncMeta) DetailBySchemaTableSCN

func (rw *WaitSyncMeta) DetailBySchemaTableSCN(ctx context.Context, detailS interface{}) (interface{}, error)

func (*WaitSyncMeta) ModifyFullSplitTimesZero

func (rw *WaitSyncMeta) ModifyFullSplitTimesZero(ctx context.Context, detailS interface{}) error

func (*WaitSyncMeta) Query

func (rw *WaitSyncMeta) Query(ctx context.Context, queryS interface{}) (interface{}, error)

Query returns part sync meta records

func (*WaitSyncMeta) Update

func (rw *WaitSyncMeta) Update(ctx context.Context, detailS interface{}) error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL