migrationpkg

package
v0.3.35 Latest Latest
Warning

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

Go to latest
Published: Dec 27, 2024 License: Apache-2.0 Imports: 4 Imported by: 29

Documentation

Overview

Package migrationpkg Package repos Code generated by ikaiguang. <https://github.com/ikaiguang>

Index

Constants

View Source
const (
	Version = "v0.0.1"
)

Variables

View Source
var (
	DefaultTableName         = "srv_migration_record"
	DefaultVersion           = "v0.0.1"
	DefaultInitIdentifier    = DefaultVersion + ":init:create:migration_schema"
	FieldMigrationIdentifier = "migration_identifier"
)

Functions

This section is empty.

Types

type AnyMigrator

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

AnyMigrator 任意

func (*AnyMigrator) Down

func (s *AnyMigrator) Down() error

Down implements the Migration

func (*AnyMigrator) Identifier

func (s *AnyMigrator) Identifier() string

Identifier implements the Migration.

func (*AnyMigrator) Up

func (s *AnyMigrator) Up() error

Up implements the Migration

func (*AnyMigrator) Version

func (s *AnyMigrator) Version() string

Version implements the Migration.

type AnyMigratorExec

type AnyMigratorExec func() error

AnyMigratorExec ...

type CreateTable

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

CreateTable 创建表

func (*CreateTable) Down

func (s *CreateTable) Down() error

Down implements the Migration

func (*CreateTable) Identifier

func (s *CreateTable) Identifier() string

Identifier implements the Migration

func (*CreateTable) Up

func (s *CreateTable) Up() error

Up implements the Migration

func (*CreateTable) Version

func (s *CreateTable) Version() string

Version implements the Migration.

type DropTable

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

DropTable 删除表

func (*DropTable) Down

func (s *DropTable) Down() error

Down implements the Migration

func (*DropTable) Identifier

func (s *DropTable) Identifier() string

Identifier implements the Migration

func (*DropTable) Up

func (s *DropTable) Up() error

Up implements the Migration

func (*DropTable) Version

func (s *DropTable) Version() string

Version implements the Migration.

type MigrateRepo

type MigrateRepo interface {
	InitializeSchema(ctx context.Context) (err error)
	QueryRecord(ctx context.Context, identifier string) (dataModel *MigrationEntity, isNotFound bool, err error)
	CreateRecord(ctx context.Context, serverVersion, migrateIdentifier string) (err error)
	CreateRecordByEntity(ctx context.Context, dataModel *MigrationEntity) (err error)
	RunMigratorUp(ctx context.Context, migratorRepo MigrationInterface) error
	RunMigratorDown(ctx context.Context, migratorRepo MigrationInterface) error
}

MigrateRepo ...

func NewMigrateRepo

func NewMigrateRepo(dbConn *gorm.DB) MigrateRepo

NewMigrateRepo ...

type Migration

type Migration struct {
	Id                  uint64    `gorm:"column:id;type:uint;autoIncrement;comment:ID" json:"id"`
	ServerVersion       string    `gorm:"column:server_version;type:string;size:255;not null;default:'';comment:服务版本" json:"server_version"`
	MigrationIdentifier string    `` /* 137-byte string literal not displayed */
	MigrationBatch      uint      `gorm:"column:migration_batch;type:uint;not null;default:0;comment:迁移批次" json:"migration_batch"`
	MigrationDesc       string    `gorm:"column:migration_desc;type:text;not null;comment:迁移描述" json:"migration_desc"`
	MigrationExtraInfo  string    `gorm:"column:migration_extra_info;type:json;not null;comment:迁移:额外信息" json:"migration_extra_info"`
	CreatedTime         time.Time `gorm:"column:created_time;type:time;not null;comment:创建时间" json:"created_time"`
	UpdatedTime         time.Time `gorm:"column:updated_time;type:time;not null;comment:更新时间" json:"updated_time"`
}

Migration CHARSET utf8mb4 Migration 数据库迁移 文档地址:https://gorm.io/docs/models.html MySQL 支持 unsigned Postgres 不支持 unsigned MySQL 支持 auto_increment Postgres : serial or bigserial

var MigrationSchema Migration

MigrationSchema ...

func (*Migration) CreateTableMigrator

func (s *Migration) CreateTableMigrator(migrator gorm.Migrator) MigrationInterface

CreateTableMigrator create table migrator

func (*Migration) DropTableMigrator

func (s *Migration) DropTableMigrator(migrator gorm.Migrator) MigrationInterface

DropTableMigrator create table migrator

func (*Migration) TableName

func (s *Migration) TableName() string

TableName table name

type MigrationDataRepo

type MigrationDataRepo interface {
	Create(ctx context.Context, dataModel *MigrationEntity) error
	QueryOneByIdentifier(ctx context.Context, identifier string) (dataModel *MigrationEntity, isNotFound bool, err error)
	DeleteOneByIdentifier(ctx context.Context, identifier string) error
}

MigrationDataRepo repo

func NewMigrationDataRepo

func NewMigrationDataRepo(dbConn *gorm.DB) MigrationDataRepo

NewMigrationDataRepo new data repo

type MigrationEntity

type MigrationEntity struct {
	Id                  uint64    `gorm:"column:id;primaryKey" json:"id"`                          // ID
	ServerVersion       string    `gorm:"column:server_version" json:"server_version"`             // 服务版本
	MigrationIdentifier string    `gorm:"column:migration_identifier" json:"migration_identifier"` // 迁移key:唯一
	MigrationBatch      uint64    `gorm:"column:migration_batch" json:"migration_batch"`           // 迁移批次
	MigrationDesc       string    `gorm:"column:migration_desc" json:"migration_desc"`             // 迁移描述
	MigrationExtraInfo  string    `gorm:"column:migration_extra_info" json:"migration_extra_info"` // 迁移:额外信息
	CreatedTime         time.Time `gorm:"column:created_time" json:"created_time"`                 // 创建时间
	UpdatedTime         time.Time `gorm:"column:updated_time" json:"updated_time"`                 // 更新时间
}

MigrationEntity srv_migration Migration 数据库迁移 文档地址:https://gorm.io/docs/models.html MySQL 支持 unsigned Postgres 不支持 unsigned MySQL 支持 auto_increment Postgres : serial or bigserial

type MigrationInterface

type MigrationInterface interface {
	// Version 版本
	Version() string
	// Identifier 迁移标识
	Identifier() string
	// Up 运行迁移
	Up() error
	// Down 回滚迁移
	Down() error
}

MigrationInterface 数据库迁移

func NewAnyMigrator

func NewAnyMigrator(version, identifier string, up, down AnyMigratorExec) MigrationInterface

NewAnyMigrator ...

func NewCreateTable

func NewCreateTable(migrator gorm.Migrator, version string, table schema.Tabler) MigrationInterface

NewCreateTable 创建表

func NewDropTable

func NewDropTable(migrator gorm.Migrator, version string, table schema.Tabler) MigrationInterface

NewDropTable 删除表

Jump to

Keyboard shortcuts

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