DropTable drops a table from the schema. Returns an error if the table does not exist.
(tableName string)
| 546 | // DropTable drops a table from the schema. |
| 547 | // Returns an error if the table does not exist. |
| 548 | func (s *SchemaMetadata) DropTable(tableName string) error { |
| 549 | // Check if table exists |
| 550 | if s.GetTable(tableName) == nil { |
| 551 | return errors.Errorf("table %q does not exist in schema %q", tableName, s.proto.Name) |
| 552 | } |
| 553 | |
| 554 | // Remove from internal map |
| 555 | tableID := normalizeNameByCaseSensitivity(tableName, s.isObjectCaseSensitive) |
| 556 | delete(s.internalTables, tableID) |
| 557 | |
| 558 | // Remove from proto's table list |
| 559 | newTables := make([]*storepb.TableMetadata, 0, len(s.proto.Tables)-1) |
| 560 | for _, table := range s.proto.Tables { |
| 561 | if s.isObjectCaseSensitive { |
| 562 | if table.Name != tableName { |
| 563 | newTables = append(newTables, table) |
| 564 | } |
| 565 | } else { |
| 566 | if !strings.EqualFold(table.Name, tableName) { |
| 567 | newTables = append(newTables, table) |
| 568 | } |
| 569 | } |
| 570 | } |
| 571 | s.proto.Tables = newTables |
| 572 | |
| 573 | return nil |
| 574 | } |
| 575 | |
| 576 | // RenameTable renames a table in the schema. |
| 577 | // Returns an error if the old table doesn't exist or new table already exists. |