Skip to content

Commit

Permalink
feat: rename keyspace properties to drop the FK_ prefix and make lowe…
Browse files Browse the repository at this point in the history
…rcase

Signed-off-by: Manan Gupta <[email protected]>
  • Loading branch information
GuptaManan100 committed Oct 16, 2023
1 parent 0f751fb commit c850445
Show file tree
Hide file tree
Showing 16 changed files with 166 additions and 166 deletions.
4 changes: 2 additions & 2 deletions go/test/vschemawrapper/vschema_wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ func (vw *VSchemaWrapper) PlannerWarning(_ string) {
}

func (vw *VSchemaWrapper) ForeignKeyMode(keyspace string) (vschemapb.Keyspace_ForeignKeyMode, error) {
defaultFkMode := vschemapb.Keyspace_FK_UNMANAGED
if vw.V.Keyspaces[keyspace] != nil && vw.V.Keyspaces[keyspace].ForeignKeyMode != vschemapb.Keyspace_FK_DEFAULT {
defaultFkMode := vschemapb.Keyspace_unmanaged
if vw.V.Keyspaces[keyspace] != nil && vw.V.Keyspaces[keyspace].ForeignKeyMode != vschemapb.Keyspace_default {
return vw.V.Keyspaces[keyspace].ForeignKeyMode, nil
}
return defaultFkMode, nil
Expand Down
190 changes: 95 additions & 95 deletions go/vt/proto/vschema/vschema.pb.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion go/vt/vtgate/planbuilder/ddl.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ func checkFKError(vschema plancontext.VSchema, ddlStatement sqlparser.DDLStateme
if err != nil {
return err
}
if fkMode == vschemapb.Keyspace_FK_DISALLOW {
if fkMode == vschemapb.Keyspace_disallow {
fk := &fkContraint{}
_ = sqlparser.Walk(fk.FkWalk, ddlStatement)
if fk.found {
Expand Down
2 changes: 1 addition & 1 deletion go/vt/vtgate/planbuilder/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func fkManagementNotRequired(ctx *plancontext.PlanningContext, vschema planconte
if err != nil {
return false
}
if ksMode != vschemapb.Keyspace_FK_MANAGED {
if ksMode != vschemapb.Keyspace_managed {
continue
}
childFks := vTable.ChildFKsNeedsHandling(ctx.VerifyAllFKs, vindexes.DeleteAction)
Expand Down
2 changes: 1 addition & 1 deletion go/vt/vtgate/planbuilder/insert.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func errOutIfPlanCannotBeConstructed(ctx *plancontext.PlanningContext, vTbl *vin
// TODO: Handle all this in semantic analysis.
func fkManagementRequiredForInsert(ctx *plancontext.PlanningContext, vTbl *vindexes.Table, updateExprs sqlparser.UpdateExprs, replace bool) bool {
ksMode, err := ctx.VSchema.ForeignKeyMode(vTbl.Keyspace.Name)
if err != nil || ksMode != vschemapb.Keyspace_FK_MANAGED {
if err != nil || ksMode != vschemapb.Keyspace_managed {
return false
}

Expand Down
2 changes: 1 addition & 1 deletion go/vt/vtgate/planbuilder/operators/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func createOperatorFromDelete(ctx *plancontext.PlanningContext, deleteStmt *sqlp
}

// Unmanaged foreign-key-mode, we don't need to do anything.
if ksMode != vschemapb.Keyspace_FK_MANAGED {
if ksMode != vschemapb.Keyspace_managed {
return delOp, nil
}

Expand Down
2 changes: 1 addition & 1 deletion go/vt/vtgate/planbuilder/operators/insert.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ func createOperatorFromInsert(ctx *plancontext.PlanningContext, ins *sqlparser.I
if err != nil {
return nil, err
}
if ksMode != vschemapb.Keyspace_FK_MANAGED {
if ksMode != vschemapb.Keyspace_managed {
return insOp, nil
}

Expand Down
2 changes: 1 addition & 1 deletion go/vt/vtgate/planbuilder/operators/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ func createOperatorFromUpdate(ctx *plancontext.PlanningContext, updStmt *sqlpars
return nil, err
}
// Unmanaged foreign-key-mode, we don't need to do anything.
if ksMode != vschemapb.Keyspace_FK_MANAGED {
if ksMode != vschemapb.Keyspace_managed {
return updOp, nil
}

Expand Down
2 changes: 1 addition & 1 deletion go/vt/vtgate/planbuilder/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func fkManagementNotRequiredForUpdate(ctx *plancontext.PlanningContext, vTables
if err != nil {
return false
}
if ksMode != vschemapb.Keyspace_FK_MANAGED {
if ksMode != vschemapb.Keyspace_managed {
continue
}
childFks := vTable.ChildFKsNeedsHandling(ctx.VerifyAllFKs, vindexes.UpdateAction)
Expand Down
2 changes: 1 addition & 1 deletion go/vt/vtgate/vcursor_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -1038,7 +1038,7 @@ func (vc *vcursorImpl) PlannerWarning(message string) {
// ForeignKeyMode implements the VCursor interface
func (vc *vcursorImpl) ForeignKeyMode(keyspace string) (vschemapb.Keyspace_ForeignKeyMode, error) {
if strings.ToLower(foreignKeyMode) == "disallow" {
return vschemapb.Keyspace_FK_DISALLOW, nil
return vschemapb.Keyspace_disallow, nil
}
ks := vc.vschema.Keyspaces[keyspace]
if ks == nil {
Expand Down
4 changes: 2 additions & 2 deletions go/vt/vtgate/vindexes/vschema.go
Original file line number Diff line number Diff line change
Expand Up @@ -337,8 +337,8 @@ func buildKeyspaces(source *vschemapb.SrvVSchema, vschema *VSchema) {

// replaceDefaultForeignKeyMode replaces the default value of the foreign key mode enum with the default we want to keep.
func replaceDefaultForeignKeyMode(fkMode vschemapb.Keyspace_ForeignKeyMode) vschemapb.Keyspace_ForeignKeyMode {
if fkMode == vschemapb.Keyspace_FK_DEFAULT {
return vschemapb.Keyspace_FK_UNMANAGED
if fkMode == vschemapb.Keyspace_default {
return vschemapb.Keyspace_unmanaged
}
return fkMode
}
Expand Down
68 changes: 34 additions & 34 deletions go/vt/vtgate/vindexes/vschema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,19 +259,19 @@ func TestForeignKeyMode(t *testing.T) {
}{
{
name: "Default Value",
wantedFkMode: vschemapb.Keyspace_FK_UNMANAGED,
wantedFkMode: vschemapb.Keyspace_unmanaged,
}, {
name: "Managed Value",
fkMode: vschemapb.Keyspace_FK_MANAGED,
wantedFkMode: vschemapb.Keyspace_FK_MANAGED,
fkMode: vschemapb.Keyspace_managed,
wantedFkMode: vschemapb.Keyspace_managed,
}, {
name: "Unmanaged Value",
fkMode: vschemapb.Keyspace_FK_UNMANAGED,
wantedFkMode: vschemapb.Keyspace_FK_UNMANAGED,
fkMode: vschemapb.Keyspace_unmanaged,
wantedFkMode: vschemapb.Keyspace_unmanaged,
}, {
name: "Disallow Value",
fkMode: vschemapb.Keyspace_FK_DISALLOW,
wantedFkMode: vschemapb.Keyspace_FK_DISALLOW,
fkMode: vschemapb.Keyspace_disallow,
wantedFkMode: vschemapb.Keyspace_disallow,
},
}

Expand Down Expand Up @@ -681,7 +681,7 @@ func TestVSchemaRoutingRules(t *testing.T) {
Keyspaces: map[string]*vschemapb.Keyspace{
"ks1": {
Sharded: true,
ForeignKeyMode: vschemapb.Keyspace_FK_UNMANAGED,
ForeignKeyMode: vschemapb.Keyspace_unmanaged,
Vindexes: map[string]*vschemapb.Vindex{
"stfu1": {
Type: "stfu",
Expand All @@ -699,7 +699,7 @@ func TestVSchemaRoutingRules(t *testing.T) {
},
},
"ks2": {
ForeignKeyMode: vschemapb.Keyspace_FK_MANAGED,
ForeignKeyMode: vschemapb.Keyspace_managed,
Tables: map[string]*vschemapb.Table{
"t2": {},
},
Expand Down Expand Up @@ -773,7 +773,7 @@ func TestVSchemaRoutingRules(t *testing.T) {
Keyspaces: map[string]*KeyspaceSchema{
"ks1": {
Keyspace: ks1,
ForeignKeyMode: vschemapb.Keyspace_FK_UNMANAGED,
ForeignKeyMode: vschemapb.Keyspace_unmanaged,
Tables: map[string]*Table{
"t1": t1,
},
Expand All @@ -782,7 +782,7 @@ func TestVSchemaRoutingRules(t *testing.T) {
},
},
"ks2": {
ForeignKeyMode: vschemapb.Keyspace_FK_MANAGED,
ForeignKeyMode: vschemapb.Keyspace_managed,
Keyspace: ks2,
Tables: map[string]*Table{
"t2": t2,
Expand Down Expand Up @@ -1108,7 +1108,7 @@ func TestShardedVSchemaMultiColumnVindex(t *testing.T) {
Keyspaces: map[string]*vschemapb.Keyspace{
"sharded": {
Sharded: true,
ForeignKeyMode: vschemapb.Keyspace_FK_DISALLOW,
ForeignKeyMode: vschemapb.Keyspace_disallow,
Vindexes: map[string]*vschemapb.Vindex{
"stfu1": {
Type: "stfu",
Expand Down Expand Up @@ -1155,7 +1155,7 @@ func TestShardedVSchemaMultiColumnVindex(t *testing.T) {
},
Keyspaces: map[string]*KeyspaceSchema{
"sharded": {
ForeignKeyMode: vschemapb.Keyspace_FK_DISALLOW,
ForeignKeyMode: vschemapb.Keyspace_disallow,
Keyspace: ks,
Tables: map[string]*Table{
"t1": t1},
Expand All @@ -1173,7 +1173,7 @@ func TestShardedVSchemaNotOwned(t *testing.T) {
good := vschemapb.SrvVSchema{
Keyspaces: map[string]*vschemapb.Keyspace{
"sharded": {
ForeignKeyMode: vschemapb.Keyspace_FK_MANAGED,
ForeignKeyMode: vschemapb.Keyspace_managed,
Sharded: true,
Vindexes: map[string]*vschemapb.Vindex{
"stlu1": {
Expand Down Expand Up @@ -1231,7 +1231,7 @@ func TestShardedVSchemaNotOwned(t *testing.T) {
"stfu1": vindex2},
Keyspaces: map[string]*KeyspaceSchema{
"sharded": {
ForeignKeyMode: vschemapb.Keyspace_FK_MANAGED,
ForeignKeyMode: vschemapb.Keyspace_managed,
Keyspace: ks,
Tables: map[string]*Table{
"t1": t1,
Expand Down Expand Up @@ -1306,12 +1306,12 @@ func TestBuildVSchemaDupSeq(t *testing.T) {
good := vschemapb.SrvVSchema{
Keyspaces: map[string]*vschemapb.Keyspace{
"ksa": {
ForeignKeyMode: vschemapb.Keyspace_FK_MANAGED,
ForeignKeyMode: vschemapb.Keyspace_managed,
Tables: map[string]*vschemapb.Table{
"t1": {
Type: "sequence"}}},
"ksb": {
ForeignKeyMode: vschemapb.Keyspace_FK_MANAGED,
ForeignKeyMode: vschemapb.Keyspace_managed,
Tables: map[string]*vschemapb.Table{
"t1": {
Type: "sequence"}}}}}
Expand All @@ -1336,15 +1336,15 @@ func TestBuildVSchemaDupSeq(t *testing.T) {
uniqueVindexes: map[string]Vindex{},
Keyspaces: map[string]*KeyspaceSchema{
"ksa": {
ForeignKeyMode: vschemapb.Keyspace_FK_MANAGED,
ForeignKeyMode: vschemapb.Keyspace_managed,
Keyspace: ksa,
Tables: map[string]*Table{
"t1": t1a,
},
Vindexes: map[string]Vindex{},
},
"ksb": {
ForeignKeyMode: vschemapb.Keyspace_FK_MANAGED,
ForeignKeyMode: vschemapb.Keyspace_managed,
Keyspace: ksb,
Tables: map[string]*Table{
"t1": t1b,
Expand All @@ -1361,13 +1361,13 @@ func TestBuildVSchemaDupTable(t *testing.T) {
good := vschemapb.SrvVSchema{
Keyspaces: map[string]*vschemapb.Keyspace{
"ksa": {
ForeignKeyMode: vschemapb.Keyspace_FK_UNMANAGED,
ForeignKeyMode: vschemapb.Keyspace_unmanaged,
Tables: map[string]*vschemapb.Table{
"t1": {},
},
},
"ksb": {
ForeignKeyMode: vschemapb.Keyspace_FK_UNMANAGED,
ForeignKeyMode: vschemapb.Keyspace_unmanaged,
Tables: map[string]*vschemapb.Table{
"t1": {},
},
Expand Down Expand Up @@ -1397,15 +1397,15 @@ func TestBuildVSchemaDupTable(t *testing.T) {
uniqueVindexes: map[string]Vindex{},
Keyspaces: map[string]*KeyspaceSchema{
"ksa": {
ForeignKeyMode: vschemapb.Keyspace_FK_UNMANAGED,
ForeignKeyMode: vschemapb.Keyspace_unmanaged,
Keyspace: ksa,
Tables: map[string]*Table{
"t1": t1a,
},
Vindexes: map[string]Vindex{},
},
"ksb": {
ForeignKeyMode: vschemapb.Keyspace_FK_UNMANAGED,
ForeignKeyMode: vschemapb.Keyspace_unmanaged,
Keyspace: ksb,
Tables: map[string]*Table{
"t1": t1b,
Expand All @@ -1425,7 +1425,7 @@ func TestBuildVSchemaDupVindex(t *testing.T) {
good := vschemapb.SrvVSchema{
Keyspaces: map[string]*vschemapb.Keyspace{
"ksa": {
ForeignKeyMode: vschemapb.Keyspace_FK_UNMANAGED,
ForeignKeyMode: vschemapb.Keyspace_unmanaged,
Sharded: true,
Vindexes: map[string]*vschemapb.Vindex{
"stlu1": {
Expand All @@ -1445,7 +1445,7 @@ func TestBuildVSchemaDupVindex(t *testing.T) {
},
},
"ksb": {
ForeignKeyMode: vschemapb.Keyspace_FK_UNMANAGED,
ForeignKeyMode: vschemapb.Keyspace_unmanaged,
Sharded: true,
Vindexes: map[string]*vschemapb.Vindex{
"stlu1": {
Expand Down Expand Up @@ -1528,7 +1528,7 @@ func TestBuildVSchemaDupVindex(t *testing.T) {
},
Keyspaces: map[string]*KeyspaceSchema{
"ksa": {
ForeignKeyMode: vschemapb.Keyspace_FK_UNMANAGED,
ForeignKeyMode: vschemapb.Keyspace_unmanaged,
Keyspace: ksa,
Tables: map[string]*Table{
"t1": t1,
Expand All @@ -1538,7 +1538,7 @@ func TestBuildVSchemaDupVindex(t *testing.T) {
},
},
"ksb": {
ForeignKeyMode: vschemapb.Keyspace_FK_UNMANAGED,
ForeignKeyMode: vschemapb.Keyspace_unmanaged,
Keyspace: ksb,
Tables: map[string]*Table{
"t1": t2,
Expand Down Expand Up @@ -1997,7 +1997,7 @@ func TestSequence(t *testing.T) {
good := vschemapb.SrvVSchema{
Keyspaces: map[string]*vschemapb.Keyspace{
"unsharded": {
ForeignKeyMode: vschemapb.Keyspace_FK_DISALLOW,
ForeignKeyMode: vschemapb.Keyspace_disallow,
Tables: map[string]*vschemapb.Table{
"seq": {
Type: "sequence",
Expand All @@ -2006,7 +2006,7 @@ func TestSequence(t *testing.T) {
},
"sharded": {
Sharded: true,
ForeignKeyMode: vschemapb.Keyspace_FK_UNMANAGED,
ForeignKeyMode: vschemapb.Keyspace_unmanaged,
Vindexes: map[string]*vschemapb.Vindex{
"stfu1": {
Type: "stfu",
Expand Down Expand Up @@ -2116,15 +2116,15 @@ func TestSequence(t *testing.T) {
},
Keyspaces: map[string]*KeyspaceSchema{
"unsharded": {
ForeignKeyMode: vschemapb.Keyspace_FK_DISALLOW,
ForeignKeyMode: vschemapb.Keyspace_disallow,
Keyspace: ksu,
Tables: map[string]*Table{
"seq": seq,
},
Vindexes: map[string]Vindex{},
},
"sharded": {
ForeignKeyMode: vschemapb.Keyspace_FK_UNMANAGED,
ForeignKeyMode: vschemapb.Keyspace_unmanaged,
Keyspace: kss,
Tables: map[string]*Table{
"t1": t1,
Expand Down Expand Up @@ -2555,7 +2555,7 @@ func TestBuildKeyspaceSchema(t *testing.T) {
}
want := &KeyspaceSchema{
Keyspace: ks,
ForeignKeyMode: vschemapb.Keyspace_FK_UNMANAGED,
ForeignKeyMode: vschemapb.Keyspace_unmanaged,
Tables: map[string]*Table{
"t1": t1,
"t2": t2,
Expand Down Expand Up @@ -2677,7 +2677,7 @@ func TestVSchemaJSON(t *testing.T) {

in := map[string]*KeyspaceSchema{
"unsharded": {
ForeignKeyMode: vschemapb.Keyspace_FK_MANAGED,
ForeignKeyMode: vschemapb.Keyspace_managed,
Keyspace: &Keyspace{
Name: "k1",
},
Expand All @@ -2698,7 +2698,7 @@ func TestVSchemaJSON(t *testing.T) {
},
},
"sharded": {
ForeignKeyMode: vschemapb.Keyspace_FK_DISALLOW,
ForeignKeyMode: vschemapb.Keyspace_disallow,
Keyspace: &Keyspace{
Name: "k2",
Sharded: true,
Expand Down
8 changes: 4 additions & 4 deletions go/vt/vtgate/vschema_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ func TestVSchemaUpdate(t *testing.T) {
Keyspaces: map[string]*vschemapb.Keyspace{
"ks": {
Sharded: false,
ForeignKeyMode: vschemapb.Keyspace_FK_MANAGED,
ForeignKeyMode: vschemapb.Keyspace_managed,
Tables: map[string]*vschemapb.Table{
"t1": {
Columns: []*vschemapb.Column{
Expand Down Expand Up @@ -237,7 +237,7 @@ func TestVSchemaUpdate(t *testing.T) {
Keyspaces: map[string]*vindexes.KeyspaceSchema{
"ks": {
Keyspace: ks,
ForeignKeyMode: vschemapb.Keyspace_FK_MANAGED,
ForeignKeyMode: vschemapb.Keyspace_managed,
Vindexes: map[string]vindexes.Vindex{},
Tables: map[string]*vindexes.Table{
"t1": vindexTable_t1,
Expand Down Expand Up @@ -379,7 +379,7 @@ func makeTestVSchema(ks string, sharded bool, tbls map[string]*vindexes.Table) *
Sharded: sharded,
},
// Default foreign key mode
ForeignKeyMode: vschemapb.Keyspace_FK_UNMANAGED,
ForeignKeyMode: vschemapb.Keyspace_unmanaged,
Tables: tbls,
Vindexes: map[string]vindexes.Vindex{},
}
Expand All @@ -401,7 +401,7 @@ func makeTestSrvVSchema(ks string, sharded bool, tbls map[string]*vschemapb.Tabl
Sharded: sharded,
Tables: tbls,
// Default foreign key mode
ForeignKeyMode: vschemapb.Keyspace_FK_UNMANAGED,
ForeignKeyMode: vschemapb.Keyspace_unmanaged,
}
return &vschemapb.SrvVSchema{
Keyspaces: map[string]*vschemapb.Keyspace{ks: keyspaceSchema},
Expand Down
Loading

0 comments on commit c850445

Please sign in to comment.