CreateTable creates a new table in the schema. Returns the created TableMetadata or an error if the table already exists.
(tableName string)
| 513 | // CreateTable creates a new table in the schema. |
| 514 | // Returns the created TableMetadata or an error if the table already exists. |
| 515 | func (s *SchemaMetadata) CreateTable(tableName string) (*TableMetadata, error) { |
| 516 | // Check if table already exists |
| 517 | if s.GetTable(tableName) != nil { |
| 518 | return nil, errors.Errorf("table %q already exists in schema %q", tableName, s.proto.Name) |
| 519 | } |
| 520 | |
| 521 | // Create new table proto |
| 522 | newTableProto := &storepb.TableMetadata{ |
| 523 | Name: tableName, |
| 524 | Columns: []*storepb.ColumnMetadata{}, |
| 525 | Indexes: []*storepb.IndexMetadata{}, |
| 526 | } |
| 527 | |
| 528 | // Add to proto's table list |
| 529 | s.proto.Tables = append(s.proto.Tables, newTableProto) |
| 530 | |
| 531 | // Create TableMetadata wrapper |
| 532 | tableMeta := &TableMetadata{ |
| 533 | isDetailCaseSensitive: s.isDetailCaseSensitive, |
| 534 | internalColumn: make(map[string]*ColumnMetadata), |
| 535 | internalIndexes: make(map[string]*IndexMetadata), |
| 536 | proto: newTableProto, |
| 537 | } |
| 538 | |
| 539 | // Add to internal map |
| 540 | tableID := normalizeNameByCaseSensitivity(tableName, s.isObjectCaseSensitive) |
| 541 | s.internalTables[tableID] = tableMeta |
| 542 | |
| 543 | return tableMeta, nil |
| 544 | } |
| 545 | |
| 546 | // DropTable drops a table from the schema. |
| 547 | // Returns an error if the table does not exist. |