migrator

package
v1.3.1 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2021 License: Apache-2.0 Imports: 29 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DDL = "DDL"
	DML = "DML"
)
View Source
const CreateTableHistoryModel = `` /* 834-byte string literal not displayed */
View Source
const SchemaMigrationHistory = `schema_migration_history`

Variables

This section is empty.

Functions

func RetryTimeout added in v1.3.0

func RetryTimeout(timeout uint64) time.Duration

func SQLCollectorFilename added in v1.3.0

func SQLCollectorFilename() string

Types

type Block added in v1.3.0

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

func AppendBlock added in v1.3.0

func AppendBlock(blocks []Block, node ast.Node, typ StmtType) []Block

func (Block) Nodes added in v1.3.0

func (block Block) Nodes() []ast.Node

func (Block) Type added in v1.3.0

func (block Block) Type() StmtType

type DSNParameters

type DSNParameters struct {
	Username  string
	Password  string
	Host      string
	Port      int
	Database  string
	ParseTime bool
	Timeout   time.Duration
}

func (DSNParameters) Format

func (c DSNParameters) Format(database bool) (dsn string)

type Equal

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

func FieldTypeEqual

func FieldTypeEqual(l, r *types.FieldType) *Equal

func (*Equal) Equal

func (e *Equal) Equal() bool

func (*Equal) Reason

func (e *Equal) Reason() string

type HistoryModel

type HistoryModel struct {
	ID        uint64    `gorm:"primary key"`
	CreatedAt time.Time `json:"createdAt" gorm:"created_at"`
	UpdatedAt time.Time `json:"updatedAt" gorm:"updated_at"`

	ServiceName  string `json:"serviceName"  gorm:"service_name"`
	Filename     string `json:"filename"     gorm:"filename"`
	Checksum     string `json:"checksum"     gorm:"checksum"`
	InstalledBy  string `json:"installedBy"  gorm:"installed_by"`
	InstalledOn  string `json:"installedOn"  gorm:"install_on"`
	LanguageType string `json:"languageType" gorm:"language_type"`
	Reversed     string `json:"reversed"     gorm:"reversed"`
}

func (HistoryModel) CreateTable

func (m HistoryModel) CreateTable(db *gorm.DB)

func (HistoryModel) TableName

func (m HistoryModel) TableName() string

type Migrator

type Migrator struct {
	Parameters

	LocalScripts *Scripts
	// contains filtered or unexported fields
}

func New

func New(parameters Parameters) (mig *Migrator, err error)

func (*Migrator) ClearSandbox

func (mig *Migrator) ClearSandbox()

ClearSandbox if you want to do a new migration in a clean sandbox, you should ClearSandbox to clear all changes on last migration

func (*Migrator) DB

func (mig *Migrator) DB() *gorm.DB

func (*Migrator) Run

func (mig *Migrator) Run() (err error)

func (*Migrator) SandBox

func (mig *Migrator) SandBox() *gorm.DB

type Module

type Module struct {
	// Name is the name of the module
	Name string
	// Scripts contains all sql or python scripts in the module
	Scripts []*Script
	// PythonRequirementsText is the text of python requirements file in the module.
	// it is used to install dependencies of python package by "pip install -r requirements.txt -v"
	PythonRequirementsText []byte
}

Module is the list of Script

func (*Module) BaselineEqualCloud

func (m *Module) BaselineEqualCloud(tx *gorm.DB) *Equal

BaselineEqualCloud check baseline script schema is equal with cloud schema or not

func (*Module) BaselineSchema

func (m *Module) BaselineSchema() *Schema

func (*Module) BaselineTableNames

func (m *Module) BaselineTableNames() []string

func (*Module) Filenames

func (m *Module) Filenames() []string

func (*Module) FilterFreshBaseline added in v1.3.0

func (m *Module) FilterFreshBaseline(db *gorm.DB) *Module

func (*Module) GetScriptByFilename added in v1.3.0

func (m *Module) GetScriptByFilename(filename string) (*Script, bool)

func (*Module) Schema

func (m *Module) Schema() *Schema

func (*Module) Sort

func (m *Module) Sort()

func (*Module) TableNames

func (m *Module) TableNames() []string

type Parameters

type Parameters interface {
	ScriptsParameters

	// MySQLParameters returns MySQL DSN configuration
	MySQLParameters() *DSNParameters

	// SandboxParameters returns Sandbox DSN configuration
	SandboxParameters() *DSNParameters

	// DebugSQL gets weather to debug SQL executing
	DebugSQL() bool

	// RetryTimeout unit: second
	RetryTimeout() uint64

	SkipMigrationLint() bool
	SkipSandbox() bool
	SkipPreMigrate() bool
	SkipMigrate() bool
}

type SQLCollectorDir added in v1.3.0

type SQLCollectorDir interface {
	SQLCollectorDir() string
}

type Schema

type Schema struct {
	TableDefinitions map[string]*TableDefinition
}

Schema is the set of TableDefinitions. Is presents the status of the set of some tables.

func NewSchema

func NewSchema() *Schema

func (*Schema) Enter

func (s *Schema) Enter(in ast.Node) (ast.Node, bool)

func (*Schema) Equal

func (s *Schema) Equal(o *Schema) *Equal

func (*Schema) EqualWith added in v1.3.0

func (s *Schema) EqualWith(db *gorm.DB) *Equal

func (*Schema) Leave

func (s *Schema) Leave(in ast.Node) (ast.Node, bool)

type Script

type Script struct {
	// path from repo root, filepath.Base(script.Name) for base filename
	Name      string
	Rawtext   []byte
	Reversing []string
	Nodes     []ast.StmtNode
	Blocks    []Block
	Pending   bool
	Record    *HistoryModel
	Workdir   string
	Type      ScriptType
	// contains filtered or unexported fields
}

Script is the object from a SQL script file, it contains many statements.

func NewScript

func NewScript(workdir, pathFromRepoRoot string) (*Script, error)

NewScript read the local file, parse data as SQL AST nodes, and mark script IsBase or not

func NewScriptFromData added in v1.3.0

func NewScriptFromData(workdir, pathFromRepoRoot string, data []byte) (s *Script, err error)

func (*Script) Checksum

func (s *Script) Checksum() string

func (*Script) DDLNodes

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

func (*Script) DMLNodes

func (s *Script) DMLNodes() []ast.StmtNode

func (*Script) GetData

func (s *Script) GetData() []byte

func (*Script) GetName

func (s *Script) GetName() string

func (*Script) IsBaseline

func (s *Script) IsBaseline() bool

func (*Script) IsEmpty added in v1.3.0

func (s *Script) IsEmpty() bool

type ScriptType

type ScriptType string
const (
	ScriptTypeSQL    ScriptType = ".sql"
	ScriptTypePython ScriptType = ".py"
)

type Scripts

type Scripts struct {
	Workdir       string
	Dirname       string
	ServicesNames []string
	Services      map[string]*Module
	Patches       *Module
	// contains filtered or unexported fields
}

Scripts is the set of Module

func NewScripts

func NewScripts(parameters ScriptsParameters) (*Scripts, error)

NewScripts range the directory

func (*Scripts) AlterPermissionLint

func (s *Scripts) AlterPermissionLint() error

func (*Scripts) FreshBaselineModules added in v1.3.0

func (s *Scripts) FreshBaselineModules(db *gorm.DB) map[string]*Module

func (*Scripts) Get

func (s *Scripts) Get(serviceName string) ([]*Script, bool)

func (*Scripts) GetPatches added in v1.3.0

func (s *Scripts) GetPatches() *Module

func (*Scripts) GetScriptByFilename added in v1.3.0

func (s *Scripts) GetScriptByFilename(filename string) (*Module, *Script, bool)

func (*Scripts) HasDestructiveOperationInPending

func (s *Scripts) HasDestructiveOperationInPending() (string, bool)

func (*Scripts) IgnoreMarkPending

func (s *Scripts) IgnoreMarkPending()

func (*Scripts) InstalledChangesLint

func (s *Scripts) InstalledChangesLint(ctx *context.Context, db *gorm.DB) error

func (*Scripts) Lint

func (s *Scripts) Lint() error

func (*Scripts) MarkPending

func (s *Scripts) MarkPending(tx *gorm.DB)

func (*Scripts) SameNameLint

func (s *Scripts) SameNameLint() error

SameNameLint lint whether there is same script name in different directories

type ScriptsParameters

type ScriptsParameters interface {
	// Workdir gets pipeline node workdir
	Workdir() string

	// MigrationDir gets migration scripts direction from repo, like .dice/migrations or 4.1/sqls
	MigrationDir() string

	// Modules is the modules for installing.
	// if is nil, to install all modules in the MigrationDir()
	Modules() []string

	Rules() []rules.Ruler
}

type StmtType added in v1.3.0

type StmtType string

type TableDefinition

type TableDefinition struct {
	CreateStmt *ast.CreateTableStmt
}

TableDefinition is the table definition (CreateTableStmt) object. It can be accepted by SQL AST Node and then to update it's status.

func NewTableDefinition

func NewTableDefinition(stmt *ast.CreateTableStmt) *TableDefinition

func (*TableDefinition) Enter

func (d *TableDefinition) Enter(in ast.Node) (ast.Node, bool)

func (*TableDefinition) Equal

func (d *TableDefinition) Equal(o *TableDefinition) *Equal

func (*TableDefinition) Leave

func (d *TableDefinition) Leave(in ast.Node) (ast.Node, bool)

Jump to

Keyboard shortcuts

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