conditions.go 950 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. package migrator
  2. type MigrationCondition interface {
  3. Sql(dialect Dialect) (string, []interface{})
  4. IsFulfilled(results []map[string][]byte) bool
  5. }
  6. type ExistsMigrationCondition struct{}
  7. func (c *ExistsMigrationCondition) IsFulfilled(results []map[string][]byte) bool {
  8. return len(results) >= 1
  9. }
  10. type NotExistsMigrationCondition struct{}
  11. func (c *NotExistsMigrationCondition) IsFulfilled(results []map[string][]byte) bool {
  12. return len(results) == 0
  13. }
  14. type IfIndexExistsCondition struct {
  15. ExistsMigrationCondition
  16. TableName string
  17. IndexName string
  18. }
  19. func (c *IfIndexExistsCondition) Sql(dialect Dialect) (string, []interface{}) {
  20. return dialect.IndexCheckSql(c.TableName, c.IndexName)
  21. }
  22. type IfIndexNotExistsCondition struct {
  23. NotExistsMigrationCondition
  24. TableName string
  25. IndexName string
  26. }
  27. func (c *IfIndexNotExistsCondition) Sql(dialect Dialect) (string, []interface{}) {
  28. return dialect.IndexCheckSql(c.TableName, c.IndexName)
  29. }