migrator

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Aug 13, 2021 License: AGPL-3.0 Imports: 27 Imported by: 0

Documentation

Index

Constants

View Source
const CreateTableHistoryModel = `` /* 834-byte string literal not displayed */
View Source
const SchemaMigrationHistory = `schema_migration_history`

Variables

This section is empty.

Functions

This section is empty.

Types

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) 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

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

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) 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
	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 (*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

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
	// 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) Get

func (s *Scripts) Get(serviceName string) ([]*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() 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 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