migrator.go 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. package gorm
  2. import (
  3. "database/sql"
  4. )
  5. // Migrator returns migrator
  6. func (db *DB) Migrator() Migrator {
  7. return db.Dialector.Migrator()
  8. }
  9. // ViewOption view option
  10. type ViewOption struct {
  11. Replace bool
  12. CheckOption string
  13. Query *DB
  14. }
  15. type Migrator interface {
  16. // AutoMigrate
  17. AutoMigrate(dst ...interface{}) error
  18. // Database
  19. CurrentDatabase() string
  20. // Tables
  21. CreateTable(dst ...interface{}) error
  22. DropTable(dst ...interface{}) error
  23. HasTable(dst ...interface{}) bool
  24. RenameTable(oldName, newName string) error
  25. // Columns
  26. AddColumn(dst interface{}, field string) error
  27. DropColumn(dst interface{}, field string) error
  28. AlterColumn(dst interface{}, field string) error
  29. RenameColumn(dst interface{}, oldName, field string) error
  30. ColumnTypes(dst interface{}) ([]*sql.ColumnType, error)
  31. // Views
  32. CreateView(name string, option ViewOption) error
  33. DropView(name string) error
  34. // Constraints
  35. CreateConstraint(dst interface{}, name string) error
  36. DropConstraint(dst interface{}, name string) error
  37. // Indexes
  38. CreateIndex(dst interface{}, name string) error
  39. DropIndex(dst interface{}, name string) error
  40. HasIndex(dst interface{}, name string) bool
  41. RenameIndex(dst interface{}, oldName, newName string) error
  42. }