Skip to content

Commit

Permalink
Merge branch 'zachmu/fk-debug' of github.com:dolthub/dolt into zachmu…
Browse files Browse the repository at this point in the history
…/fk-debug
  • Loading branch information
zachmu committed Oct 17, 2024
2 parents 133795d + 737281d commit 1f6d3d1
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 13 deletions.
4 changes: 2 additions & 2 deletions go/libraries/doltcore/doltdb/foreign_key_serialization.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,12 +135,12 @@ func deserializeFlatbufferForeignKeys(msg types.SerialMessage) (*ForeignKeyColle
if !ok {
return nil, fmt.Errorf("could not decode table name: %s", string(fk.ChildTableName()))
}

parentTableName, ok := decodeTableNameFromSerialization(string(fk.ParentTableName()))
if !ok {
return nil, fmt.Errorf("could not decode table name: %s", string(fk.ParentTableName()))
}

err := collection.AddKeys(ForeignKey{
Name: string(fk.Name()),
TableName: tableName,
Expand Down
2 changes: 1 addition & 1 deletion go/libraries/doltcore/doltdb/foreign_key_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ var foreignKeyTests = []foreignKeyTest{
},
{
Name: "fk2",
TableName: doltdb.TableName{Name: "child"},
TableName: doltdb.TableName{Name: "child"},
TableIndex: "v2_idx",
TableColumns: []uint64{8734},
ReferencedTableName: doltdb.TableName{Name: "parent"},
Expand Down
8 changes: 4 additions & 4 deletions go/libraries/doltcore/doltdb/root_val_storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -455,8 +455,8 @@ func serializeDatabaseSchemas(b *flatbuffers.Builder, dbSchemas []schema.Databas
return b.EndVector(len(offsets))
}

// encodeTableNameForSerialization encodes a table name for serialization. Table names with no schema are encoded as
// just the bare table name. Table names with schemas are encoded by surrounding the schema name with null bytes and
// encodeTableNameForSerialization encodes a table name for serialization. Table names with no schema are encoded as
// just the bare table name. Table names with schemas are encoded by surrounding the schema name with null bytes and
// appending the table name.
func encodeTableNameForSerialization(name TableName) string {
if name.Schema == "" {
Expand All @@ -477,13 +477,13 @@ func decodeTableNameFromSerialization(encodedName string) (TableName, bool) {
Name: encodedName[schemaEnd+1:],
}, true
}

// invalid encoding
return TableName{}, false
}

// decodeTableNameForAddressMap decodes a table name from an address map key, expecting a particular schema name. See
// notes on serialization in |encodeTableNameForSerialization|
// notes on serialization in |encodeTableNameForSerialization|
func decodeTableNameForAddressMap(encodedName, schemaName string) (string, bool) {
if schemaName == "" && encodedName[0] != 0 {
return encodedName, true
Expand Down
2 changes: 1 addition & 1 deletion go/libraries/doltcore/sqle/sqlfmt/row_fmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ import (
"fmt"
"strings"

"github.com/dolthub/dolt/go/libraries/doltcore/doltdb"
"github.com/dolthub/go-mysql-server/sql"
"github.com/dolthub/vitess/go/sqltypes"
"github.com/dolthub/vitess/go/vt/sqlparser"

"github.com/dolthub/dolt/go/libraries/doltcore/doltdb"
"github.com/dolthub/dolt/go/libraries/doltcore/row"
"github.com/dolthub/dolt/go/libraries/doltcore/schema"
"github.com/dolthub/dolt/go/libraries/doltcore/schema/typeinfo"
Expand Down
2 changes: 1 addition & 1 deletion go/libraries/doltcore/sqle/sqlfmt/schema_fmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ func GenerateCreateTableForeignKeyDefinition(fk doltdb.ForeignKey, sch, parentSc
if fk.OnUpdate != doltdb.ForeignKeyReferentialAction_DefaultAction {
onUpdate = fk.OnUpdate.String()
}

// TODO: schema name
return sql.GenerateCreateTableForiegnKeyDefinition(fk.Name, fkCols, fk.ReferencedTableName.Name, parentCols, onDelete, onUpdate)
}
Expand Down
8 changes: 4 additions & 4 deletions go/libraries/doltcore/sqle/tables.go
Original file line number Diff line number Diff line change
Expand Up @@ -2630,7 +2630,7 @@ func (t *WritableDoltTable) createForeignKey(
tbl *doltdb.Table,
sqlFk sql.ForeignKeyConstraint,
onUpdateRefAction, onDeleteRefAction doltdb.ForeignKeyReferentialAction) (doltdb.ForeignKey, error) {

if !sqlFk.IsResolved {
// TODO: schema should be part of the foreign key defn
return doltdb.ForeignKey{
Expand Down Expand Up @@ -2707,7 +2707,7 @@ func (t *WritableDoltTable) createForeignKey(
if ok {
refTableIndexName = refTableIndex.Name()
}

// TODO: foreign key defn should include schema names
return doltdb.ForeignKey{
Name: sqlFk.Name,
Expand Down Expand Up @@ -2835,7 +2835,7 @@ func (t *WritableDoltTable) UpdateForeignKey(ctx *sql.Context, fkName string, sq
}
fkc.RemoveKeyByName(doltFk.Name)
doltFk.Name = sqlFk.Name

// TODO: need schema name in foreign key defn
doltFk.TableName = doltdb.TableName{Name: sqlFk.Table, Schema: t.db.SchemaName()}
doltFk.ReferencedTableName = doltdb.TableName{Name: sqlFk.ParentTable, Schema: t.db.SchemaName()}
Expand Down Expand Up @@ -2917,7 +2917,7 @@ func (t *AlterableDoltTable) CreateIndexForForeignKey(ctx *sql.Context, idx sql.
// toForeignKeyConstraint converts a Dolt resolved foreign key to a GMS foreign key. If the key is unresolved, then this
// function should not be used.
func toForeignKeyConstraint(fk doltdb.ForeignKey, dbName string, childSch, parentSch schema.Schema) (cst sql.ForeignKeyConstraint, err error) {
// TODO: foreign key defn should include schema name
// TODO: foreign key defn should include schema name
cst = sql.ForeignKeyConstraint{
Name: fk.Name,
Database: dbName,
Expand Down

0 comments on commit 1f6d3d1

Please sign in to comment.