migrator.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. package gorm
  2. import (
  3. "database/sql"
  4. )
  5. // Migrator returns migrator
  6. func (db *DB) Migrator() Migrator {
  7. return db.Dialector.Migrator(db)
  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. HasColumn(dst interface{}, field string) bool
  30. RenameColumn(dst interface{}, oldName, field string) error
  31. ColumnTypes(dst interface{}) ([]*sql.ColumnType, error)
  32. // Views
  33. CreateView(name string, option ViewOption) error
  34. DropView(name string) error
  35. // Constraints
  36. CreateConstraint(dst interface{}, name string) error
  37. DropConstraint(dst interface{}, name string) error
  38. HasConstraint(dst interface{}, name string) bool
  39. // Indexes
  40. CreateIndex(dst interface{}, name string) error
  41. DropIndex(dst interface{}, name string) error
  42. HasIndex(dst interface{}, name string) bool
  43. RenameIndex(dst interface{}, oldName, newName string) error
  44. }