RegisterTable creates table in the db
(s *schema.Schema, cascade, migrate bool)
| 555 | |
| 556 | //RegisterTable creates table in the db |
| 557 | func (db *DB) RegisterTable(s *schema.Schema, cascade, migrate bool) error { |
| 558 | if s.IsAbstract() { |
| 559 | return nil |
| 560 | } |
| 561 | tableDef, indices, err := db.AlterTableDef(s, cascade) |
| 562 | if !migrate { |
| 563 | if tableDef != "" || (indices != nil && len(indices) > 0) { |
| 564 | return fmt.Errorf("needs migration, run \"gohan migrate\"") |
| 565 | } |
| 566 | } |
| 567 | if err != nil { |
| 568 | tableDef, indices = db.GenTableDef(s, cascade) |
| 569 | } |
| 570 | if tableDef != "" { |
| 571 | if _, err = db.DB.Exec(tableDef); err != nil { |
| 572 | return errors.Errorf("error when exec table stmt: '%s': %s", tableDef, err) |
| 573 | } |
| 574 | } |
| 575 | for _, indexSQL := range indices { |
| 576 | if _, err = db.DB.Exec(indexSQL); err != nil { |
| 577 | return errors.Errorf("error when exec index stmt: '%s': %s", indexSQL, err) |
| 578 | } |
| 579 | } |
| 580 | return err |
| 581 | } |
| 582 | |
| 583 | //DropTable drop table definition |
| 584 | func (db *DB) DropTable(s *schema.Schema) error { |
nothing calls this directly
no test coverage detected