gorm/migrator.go

53 lines
1.2 KiB
Go
Raw Normal View History

2020-01-28 18:01:35 +03:00
package gorm
import (
"database/sql"
)
2020-02-20 18:04:03 +03:00
// Migrator returns migrator
func (db *DB) Migrator() Migrator {
return db.Dialector.Migrator()
}
2020-01-28 18:01:35 +03:00
// ViewOption view option
type ViewOption struct {
Replace bool
CheckOption string
Query *DB
}
type Migrator interface {
// AutoMigrate
AutoMigrate(dst ...interface{}) error
2020-02-20 18:04:03 +03:00
// Database
CurrentDatabase() string
2020-01-28 18:01:35 +03:00
// Tables
CreateTable(dst ...interface{}) error
DropTable(dst ...interface{}) error
2020-02-20 18:04:03 +03:00
HasTable(dst ...interface{}) bool
2020-01-28 18:01:35 +03:00
RenameTable(oldName, newName string) error
// Columns
AddColumn(dst interface{}, field string) error
DropColumn(dst interface{}, field string) error
AlterColumn(dst interface{}, field string) error
RenameColumn(dst interface{}, oldName, field string) error
ColumnTypes(dst interface{}) ([]*sql.ColumnType, error)
// Views
CreateView(name string, option ViewOption) error
DropView(name string) error
// Constraints
CreateConstraint(dst interface{}, name string) error
DropConstraint(dst interface{}, name string) error
// Indexes
CreateIndex(dst interface{}, name string) error
DropIndex(dst interface{}, name string) error
2020-02-20 18:04:03 +03:00
HasIndex(dst interface{}, name string) bool
2020-01-28 18:01:35 +03:00
RenameIndex(dst interface{}, oldName, newName string) error
}