GenTableDef generates create table sql
(s *schema.Schema, cascade bool)
| 536 | |
| 537 | //GenTableDef generates create table sql |
| 538 | func (db *DB) GenTableDef(s *schema.Schema, cascade bool) (string, []string) { |
| 539 | cols, relations, indices := db.genTableCols(s, cascade, nil) |
| 540 | |
| 541 | if s.StateVersioning() { |
| 542 | cols = append(cols, quote(configVersionColumnName)+"int not null default 1") |
| 543 | cols = append(cols, quote(stateVersionColumnName)+"int not null default 0") |
| 544 | cols = append(cols, quote(stateErrorColumnName)+"text not null default ''") |
| 545 | cols = append(cols, quote(stateColumnName)+"text not null default ''") |
| 546 | cols = append(cols, quote(stateMonitoringColumnName)+"text not null default ''") |
| 547 | } |
| 548 | |
| 549 | cols = append(cols, relations...) |
| 550 | tableSQL := fmt.Sprintf("create table `%s` (%s);\n", s.GetDbTableName(), strings.Join(cols, ",")) |
| 551 | log.Debug("Creating table: " + tableSQL) |
| 552 | log.Debug("Creating indices: " + strings.Join(indices, "")) |
| 553 | return tableSQL, indices |
| 554 | } |
| 555 | |
| 556 | //RegisterTable creates table in the db |
| 557 | func (db *DB) RegisterTable(s *schema.Schema, cascade, migrate bool) error { |
no test coverage detected