spanner

package
v1.11.0 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2024 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	FirstRun                           = UpgradeStatus("FirstRun")
	ExistingMigrationsNoUpgrade        = UpgradeStatus("NoUpgrade")
	ExistingMigrationsUpgradeStarted   = UpgradeStatus("Started")
	ExistingMigrationsUpgradeCompleted = UpgradeStatus("Completed")
)
View Source
const (
	ErrorCodeCreateClient = iota + 1
	ErrorCodeCloseClient
	ErrorCodeCreateDatabase
	ErrorCodeDropDatabase
	ErrorCodeTruncateAllTables
	ErrorCodeLoadSchema
	ErrorCodeUpdateDDL
	ErrorCodeUpdateDML
	ErrorCodeUpdatePartitionedDML
	ErrorCodeExecuteMigrations
	ErrorCodeGetMigrationVersion
	ErrorCodeSetMigrationVersion
	ErrorCodeNoMigration
	ErrorCodeMigrationVersionDirty
	ErrorCodeWaitOperation
	ErrorCodeEnsureMigrationTables
	ErrorCodeCompleteUpgrade
	ErrorCodeUndirtyMigration
)

Variables

View Source
var (
	MigrationNameRegex = regexp.MustCompile(`[a-zA-Z0-9_\-]+`)
)

Functions

This section is empty.

Types

type Client

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

func NewClient

func NewClient(ctx context.Context, config *Config) (*Client, error)

func (*Client) ApplyDDL

func (c *Client) ApplyDDL(ctx context.Context, statements []string) error

func (*Client) ApplyDDLFile

func (c *Client) ApplyDDLFile(ctx context.Context, ddl []byte) error

func (*Client) ApplyDML

func (c *Client) ApplyDML(ctx context.Context, statements []string) (int64, error)

func (*Client) ApplyDMLFile

func (c *Client) ApplyDMLFile(ctx context.Context, ddl []byte, partitioned bool) (int64, error)

func (*Client) ApplyPartitionedDML

func (c *Client) ApplyPartitionedDML(ctx context.Context, statements []string) (int64, error)

func (*Client) Close

func (c *Client) Close() error

func (*Client) CreateDatabase

func (c *Client) CreateDatabase(ctx context.Context, ddl []byte) error

func (*Client) DetermineUpgradeStatus

func (c *Client) DetermineUpgradeStatus(ctx context.Context, tableName string) (UpgradeStatus, error)

func (*Client) DropDatabase

func (c *Client) DropDatabase(ctx context.Context) error

func (*Client) EnsureMigrationTable

func (c *Client) EnsureMigrationTable(ctx context.Context, tableName string) error

func (*Client) ExecuteMigrations

func (c *Client) ExecuteMigrations(ctx context.Context, migrations Migrations, limit int, tableName string) (MigrationsOutput, error)

func (*Client) GetMigrationHistory

func (c *Client) GetMigrationHistory(ctx context.Context, versionTableName string) ([]MigrationHistoryRecord, error)

func (*Client) GetMigrationLock

func (c *Client) GetMigrationLock(ctx context.Context, tableName, lockIdentifier string) (lock MigrationLock, err error)

func (*Client) GetSchemaMigrationVersion

func (c *Client) GetSchemaMigrationVersion(ctx context.Context, tableName string) (uint, bool, error)

func (*Client) LoadDDL

func (c *Client) LoadDDL(ctx context.Context) ([]byte, error)

func (*Client) LoadDDLs added in v1.1.1

func (c *Client) LoadDDLs(ctx context.Context) ([]SchemaDDL, error)

func (*Client) LoadStaticDatas added in v1.2.0

func (c *Client) LoadStaticDatas(ctx context.Context, tables []string, customSort map[string]string) ([]StaticData, error)

func (*Client) RepairMigration added in v1.8.0

func (c *Client) RepairMigration(ctx context.Context, tableName string) error

RepairMigration will delete the dirty rows in the version and history tables

func (*Client) SetupMigrationLock

func (c *Client) SetupMigrationLock(ctx context.Context, tableName string) error

func (*Client) TruncateAllTables

func (c *Client) TruncateAllTables(ctx context.Context) error

func (*Client) UpgradeExecuteMigrations

func (c *Client) UpgradeExecuteMigrations(ctx context.Context, migrations Migrations, limit int, tableName string) (MigrationsOutput, error)

type Config

type Config struct {
	Project         string
	Instance        string
	Database        string
	CredentialsFile string
	StmtTimeout     time.Duration
}

func (*Config) URL

func (c *Config) URL() string

type Error

type Error struct {
	Code ErrorCode
	// contains filtered or unexported fields
}

func (*Error) Error

func (e *Error) Error() string

type ErrorCode

type ErrorCode int

type Migration

type Migration struct {
	// Version is the version of the migration
	Version uint

	// Name is the name of the migration
	Name string

	// FileName is the name of the source file for the migration
	FileName string

	// Statements is the migration statements
	Statements []string
	// contains filtered or unexported fields
}

migration represents the parsed migration file. e.g. version_name.sql

type MigrationHistoryRecord

type MigrationHistoryRecord struct {
	Version  int64     `spanner:"Version"`
	Dirty    bool      `spanner:"Dirty"`
	Created  time.Time `spanner:"Created"`
	Modified time.Time `spanner:"Modified"`
}

type MigrationLock

type MigrationLock struct {
	Success        bool
	Release        func()
	LockIdentifier string    `spanner:"LockIdentifier"`
	Expiry         time.Time `spanner:"Expiry"`
}

type Migrations

type Migrations []*Migration

func LoadMigrations

func LoadMigrations(dir string, toSkipSlice []uint) (Migrations, error)

func (Migrations) Len

func (ms Migrations) Len() int

func (Migrations) Less

func (ms Migrations) Less(i, j int) bool

func (Migrations) Swap

func (ms Migrations) Swap(i, j int)

type MigrationsOutput added in v1.10.0

type MigrationsOutput map[string]migrationInfo

func (MigrationsOutput) String added in v1.10.0

func (i MigrationsOutput) String() string

type SchemaDDL added in v1.1.1

type SchemaDDL struct {
	Statement  string
	Filename   string
	ObjectType string
}

type StaticData added in v1.2.0

type StaticData struct {
	TableName  string
	Statements []string
	Count      int
}

func (StaticData) ToFileName added in v1.2.0

func (s StaticData) ToFileName() string

type UpgradeStatus

type UpgradeStatus string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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