snapshot

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Aug 15, 2024 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	CharsetCollatePat = `` /* 187-byte string literal not displayed */
	//CharsetCollateRe    = regexp.MustCompile(`(?mi)(?P<charset_expr>((default\s+)?(CHARACTER\s+SET|CHARSET)(\s*=?\s*|\s+)(?P<charset_value>[^(utf8mb4)]+))|(?P<collate_expr>COLLATE(\s*=?\s*|\s+)(?P<collate_value>[A-Za-z0-9_]+)))`)
	CharsetCollateRe = regexp.MustCompile(CharsetCollatePat, regexp.IgnoreCase|regexp.Multiline|regexp.RE2)
)

Functions

func CharsetWhite

func CharsetWhite() []string

func IsCannotAddOrUpdateAChildRowError

func IsCannotAddOrUpdateAChildRowError(e error) bool

func MaxSamplingSize

func MaxSamplingSize() uint64

MaxSamplingSize returns the max sampling size. Set it by env "PIPELINE_MIGRATION_SAMPLING_SIZE"

func ParseCreateTableStmt

func ParseCreateTableStmt(create string) (*ast.CreateTableStmt, error)

ParseCreateTableStmt parses CreateTableStmt as *ast.CreateTableStmt node

func Sampling

func Sampling() bool

Sampling returns true if it needs to sampling when snapshot. Set it by env "PIPELINE_MIGRATION_DATABASE=true"

func TrimBlockFormat

func TrimBlockFormat(create string) string

func TrimCharacterSetFromRawCreateTableSQL

func TrimCharacterSetFromRawCreateTableSQL(create string, except ...string) string

func TrimCollateOptionFromCols

func TrimCollateOptionFromCols(create *ast.CreateTableStmt)

func TrimCollateOptionFromCreateTable

func TrimCollateOptionFromCreateTable(create *ast.CreateTableStmt)

func TrimConstraintCheckFromCreateTable

func TrimConstraintCheckFromCreateTable(create *ast.CreateTableStmt)

func TrimInvalidCollate

func TrimInvalidCollate(create string) string

Types

type Snapshot

type Snapshot struct {
	// contains filtered or unexported fields
}

Snapshot maintains the structure of the database tables

func From

func From(tx *gorm.DB, ignore ...string) (s *Snapshot, err error)

From snapshots the structure of the database tables, and returns the Snapshot. tx is the connection handler of the goal DB. ignore is the tables you do not want to snapshot.

func (*Snapshot) DDLNodes

func (s *Snapshot) DDLNodes() []ast.DDLNode

DDLNodes returns DDLs

func (*Snapshot) Dump

func (s *Snapshot) Dump(tableName string, lines uint64) ([]map[string]interface{}, uint64, error)

Dump dumps data from DB. tableName is the table you want to dump. lines is the numbers of lines you want to dump. Note: lines is an approximate number rather than an exact number. Note: the max data size is not more than 1<<16 (the MySQL default max placeholders size).

func (*Snapshot) HasAnyTable

func (s *Snapshot) HasAnyTable() bool

HasAnyTable returns true if there is any table in the Snapshot

func (*Snapshot) RecoverTo

func (s *Snapshot) RecoverTo(tx *gorm.DB) error

RecoverTo recover the data structure and data to goal db

func (*Snapshot) TableNames

func (s *Snapshot) TableNames() []string

TableNames returns all tables names

Jump to

Keyboard shortcuts

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