migrator

package
v1.25.12 Latest Latest
Warning

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

Go to latest
Published: Aug 22, 2024 License: MIT Imports: 13 Imported by: 408

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BuildIndexOptionsInterface

type BuildIndexOptionsInterface interface {
	BuildIndexOptions([]schema.IndexOption, *gorm.Statement) []interface{}
}

BuildIndexOptionsInterface build index options interface

type ColumnType added in v1.23.0

type ColumnType struct {
	SQLColumnType      *sql.ColumnType
	NameValue          sql.NullString
	DataTypeValue      sql.NullString
	ColumnTypeValue    sql.NullString
	PrimaryKeyValue    sql.NullBool
	UniqueValue        sql.NullBool
	AutoIncrementValue sql.NullBool
	LengthValue        sql.NullInt64
	DecimalSizeValue   sql.NullInt64
	ScaleValue         sql.NullInt64
	NullableValue      sql.NullBool
	ScanTypeValue      reflect.Type
	CommentValue       sql.NullString
	DefaultValueValue  sql.NullString
}

ColumnType column type implements ColumnType interface

func (ColumnType) AutoIncrement added in v1.23.0

func (ct ColumnType) AutoIncrement() (isAutoIncrement bool, ok bool)

AutoIncrement returns the column is auto increment or not.

func (ColumnType) ColumnType added in v1.23.0

func (ct ColumnType) ColumnType() (columnType string, ok bool)

ColumnType returns the database type of the column. like `varchar(16)`

func (ColumnType) Comment added in v1.23.0

func (ct ColumnType) Comment() (value string, ok bool)

Comment returns the comment of current column.

func (ColumnType) DatabaseTypeName added in v1.23.0

func (ct ColumnType) DatabaseTypeName() string

DatabaseTypeName returns the database system name of the column type. If an empty string is returned, then the driver type name is not supported. Consult your driver documentation for a list of driver data types. Length specifiers are not included. Common type names include "VARCHAR", "TEXT", "NVARCHAR", "DECIMAL", "BOOL", "INT", and "BIGINT".

func (ColumnType) DecimalSize added in v1.23.0

func (ct ColumnType) DecimalSize() (precision int64, scale int64, ok bool)

DecimalSize returns the scale and precision of a decimal type.

func (ColumnType) DefaultValue added in v1.23.0

func (ct ColumnType) DefaultValue() (value string, ok bool)

DefaultValue returns the default value of current column.

func (ColumnType) Length added in v1.23.0

func (ct ColumnType) Length() (length int64, ok bool)

Length returns the column type length for variable length column types

func (ColumnType) Name added in v1.23.0

func (ct ColumnType) Name() string

Name returns the name or alias of the column.

func (ColumnType) Nullable added in v1.23.0

func (ct ColumnType) Nullable() (nullable bool, ok bool)

Nullable reports whether the column may be null.

func (ColumnType) PrimaryKey added in v1.23.0

func (ct ColumnType) PrimaryKey() (isPrimaryKey bool, ok bool)

PrimaryKey returns the column is primary key or not.

func (ColumnType) ScanType added in v1.23.0

func (ct ColumnType) ScanType() reflect.Type

ScanType returns a Go type suitable for scanning into using Rows.Scan.

func (ColumnType) Unique added in v1.23.0

func (ct ColumnType) Unique() (unique bool, ok bool)

Unique reports whether the column may be unique.

type Config

type Config struct {
	CreateIndexAfterCreateTable bool
	DB                          *gorm.DB
	gorm.Dialector
}

Config schema config

type GormDataTypeInterface added in v0.2.3

type GormDataTypeInterface interface {
	GormDBDataType(*gorm.DB, *schema.Field) string
}

GormDataTypeInterface gorm data type interface

type Index added in v1.23.7

type Index struct {
	TableName       string
	NameValue       string
	ColumnList      []string
	PrimaryKeyValue sql.NullBool
	UniqueValue     sql.NullBool
	OptionValue     string
}

Index implements gorm.Index interface

func (Index) Columns added in v1.23.7

func (idx Index) Columns() []string

Columns return the columns of the index

func (Index) Name added in v1.23.7

func (idx Index) Name() string

Name return the name of the index.

func (Index) Option added in v1.23.7

func (idx Index) Option() string

Option return the optional attribute of the index

func (Index) PrimaryKey added in v1.23.7

func (idx Index) PrimaryKey() (isPrimaryKey bool, ok bool)

PrimaryKey returns the index is primary key or not.

func (Index) Table added in v1.23.7

func (idx Index) Table() string

Table return the table name of the index.

func (Index) Unique added in v1.23.7

func (idx Index) Unique() (unique bool, ok bool)

Unique returns whether the index is unique or not.

type Migrator

type Migrator struct {
	Config
}

Migrator m struct

func (Migrator) AddColumn

func (m Migrator) AddColumn(value interface{}, name string) error

AddColumn create `name` column for value

func (Migrator) AlterColumn

func (m Migrator) AlterColumn(value interface{}, field string) error

AlterColumn alter value's `field` column' type based on schema definition

func (Migrator) AutoMigrate

func (m Migrator) AutoMigrate(values ...interface{}) error

AutoMigrate auto migrate values

func (Migrator) BuildIndexOptions

func (m Migrator) BuildIndexOptions(opts []schema.IndexOption, stmt *gorm.Statement) (results []interface{})

BuildIndexOptions build index options

func (Migrator) ColumnTypes

func (m Migrator) ColumnTypes(value interface{}) ([]gorm.ColumnType, error)

ColumnTypes return columnTypes []gorm.ColumnType and execErr error

func (Migrator) CreateConstraint

func (m Migrator) CreateConstraint(value interface{}, name string) error

CreateConstraint create constraint

func (Migrator) CreateIndex

func (m Migrator) CreateIndex(value interface{}, name string) error

CreateIndex create index `name`

func (Migrator) CreateTable

func (m Migrator) CreateTable(values ...interface{}) error

CreateTable create table in database for values

func (Migrator) CreateView

func (m Migrator) CreateView(name string, option gorm.ViewOption) error

CreateView create view from Query in gorm.ViewOption. Query in gorm.ViewOption is a subquery

// CREATE VIEW `user_view` AS SELECT * FROM `users` WHERE age > 20
q := DB.Model(&User{}).Where("age > ?", 20)
DB.Debug().Migrator().CreateView("user_view", gorm.ViewOption{Query: q})

// CREATE OR REPLACE VIEW `users_view` AS SELECT * FROM `users` WITH CHECK OPTION
q := DB.Model(&User{})
DB.Debug().Migrator().CreateView("user_view", gorm.ViewOption{Query: q, Replace: true, CheckOption: "WITH CHECK OPTION"})

func (Migrator) CurrentDatabase

func (m Migrator) CurrentDatabase() (name string)

CurrentDatabase returns current database name

func (Migrator) CurrentTable added in v1.20.6

func (m Migrator) CurrentTable(stmt *gorm.Statement) interface{}

CurrentTable returns current statement's table expression

func (Migrator) DataTypeOf

func (m Migrator) DataTypeOf(field *schema.Field) string

DataTypeOf return field's db data type

func (Migrator) DropColumn

func (m Migrator) DropColumn(value interface{}, name string) error

DropColumn drop value's `name` column

func (Migrator) DropConstraint

func (m Migrator) DropConstraint(value interface{}, name string) error

DropConstraint drop constraint

func (Migrator) DropIndex

func (m Migrator) DropIndex(value interface{}, name string) error

DropIndex drop index `name`

func (Migrator) DropTable

func (m Migrator) DropTable(values ...interface{}) error

DropTable drop table for values

func (Migrator) DropView

func (m Migrator) DropView(name string) error

DropView drop view

func (Migrator) FullDataTypeOf

func (m Migrator) FullDataTypeOf(field *schema.Field) (expr clause.Expr)

FullDataTypeOf returns field's db full data type

func (Migrator) GetIndexes added in v1.23.7

func (m Migrator) GetIndexes(dst interface{}) ([]gorm.Index, error)

GetIndexes return Indexes []gorm.Index and execErr error

func (Migrator) GetQueryAndExecTx added in v1.25.7

func (m Migrator) GetQueryAndExecTx() (queryTx, execTx *gorm.DB)

func (Migrator) GetTables added in v1.22.3

func (m Migrator) GetTables() (tableList []string, err error)

GetTables returns tables

func (Migrator) GetTypeAliases added in v1.23.10

func (m Migrator) GetTypeAliases(databaseTypeName string) []string

GetTypeAliases return database type aliases

func (Migrator) GuessConstraintAndTable deprecated added in v1.20.12

func (m Migrator) GuessConstraintAndTable(stmt *gorm.Statement, name string) (*schema.Constraint, *schema.CheckConstraint, string)

GuessConstraintAndTable guess statement's constraint and it's table based on name

Deprecated: use GuessConstraintInterfaceAndTable instead.

func (Migrator) GuessConstraintInterfaceAndTable added in v1.25.7

func (m Migrator) GuessConstraintInterfaceAndTable(stmt *gorm.Statement, name string) (_ schema.ConstraintInterface, table string)

GuessConstraintInterfaceAndTable guess statement's constraint and it's table based on name nolint:cyclop

func (Migrator) HasColumn

func (m Migrator) HasColumn(value interface{}, field string) bool

HasColumn check has column `field` for value or not

func (Migrator) HasConstraint

func (m Migrator) HasConstraint(value interface{}, name string) bool

HasConstraint check has constraint or not

func (Migrator) HasIndex

func (m Migrator) HasIndex(value interface{}, name string) bool

HasIndex check has index `name` or not

func (Migrator) HasTable

func (m Migrator) HasTable(value interface{}) bool

HasTable returns table exists or not for value, value could be a struct or string

func (Migrator) MigrateColumn added in v0.2.36

func (m Migrator) MigrateColumn(value interface{}, field *schema.Field, columnType gorm.ColumnType) error

MigrateColumn migrate column

func (Migrator) MigrateColumnUnique added in v1.25.6

func (m Migrator) MigrateColumnUnique(value interface{}, field *schema.Field, columnType gorm.ColumnType) error

func (Migrator) RenameColumn

func (m Migrator) RenameColumn(value interface{}, oldName, newName string) error

RenameColumn rename value's field name from oldName to newName

func (Migrator) RenameIndex

func (m Migrator) RenameIndex(value interface{}, oldName, newName string) error

RenameIndex rename index from oldName to newName

func (Migrator) RenameTable

func (m Migrator) RenameTable(oldName, newName interface{}) error

RenameTable rename table from oldName to newName

func (Migrator) ReorderModels

func (m Migrator) ReorderModels(values []interface{}, autoAdd bool) (results []interface{})

ReorderModels reorder models according to constraint dependencies

func (Migrator) RunWithValue

func (m Migrator) RunWithValue(value interface{}, fc func(*gorm.Statement) error) error

RunWithValue run migration with statement value

func (Migrator) TableType added in v1.25.1

func (m Migrator) TableType(dst interface{}) (gorm.TableType, error)

TableType return tableType gorm.TableType and execErr error

type TableType added in v1.25.1

type TableType struct {
	SchemaValue  string
	NameValue    string
	TypeValue    string
	CommentValue sql.NullString
}

TableType table type implements TableType interface

func (TableType) Comment added in v1.25.1

func (ct TableType) Comment() (comment string, ok bool)

Comment returns the comment of current table.

func (TableType) Name added in v1.25.1

func (ct TableType) Name() string

Name returns the name of the table.

func (TableType) Schema added in v1.25.1

func (ct TableType) Schema() string

Schema returns the schema of the table.

func (TableType) Type added in v1.25.1

func (ct TableType) Type() string

Type returns the type of the table.

Jump to

Keyboard shortcuts

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