MCPcopy Index your code
hub / github.com/bytebase/bytebase / DropTable

Method DropTable

backend/store/model/database.go:548–574  ·  view source on GitHub ↗

DropTable drops a table from the schema. Returns an error if the table does not exist.

(tableName string)

Source from the content-addressed store, hash-verified

546// DropTable drops a table from the schema.
547// Returns an error if the table does not exist.
548func (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.

Callers 4

tidbRenameTableFunction · 0.80
tidbDropTableFunction · 0.80

Calls 3

GetTableMethod · 0.95
ErrorfMethod · 0.80