reverting constraint equality

This commit is contained in:
James Cor
2022-03-07 13:10:34 -08:00
parent f0d47bd82f
commit 0a8b66b158
2 changed files with 3 additions and 41 deletions
@@ -39,7 +39,7 @@ func DropPrimaryKeyFromTable(ctx context.Context, table *doltdb.Table, nbf *type
// Modify the schema to convert the primary key cols into non primary key cols
newCollection := schema.MapColCollection(sch.GetAllCols(), func(col schema.Column) schema.Column {
col.IsPartOfPK = false
// Remove PK, does not remove NOT NULL constraint, so add it back if it's somehow gone
// Removing PK does not remove NOT NULL constraint, so add it back if it's somehow gone
if col.IsNullable() {
col.Constraints = append(col.Constraints, schema.NotNullConstraint{})
}
+2 -40
View File
@@ -92,47 +92,9 @@ func IndexOfConstraint(constraints []ColConstraint, constraintType string) int {
// ColConstraintsAreEqual validates two ColConstraint slices are identical.
func ColConstraintsAreEqual(a, b []ColConstraint) bool {
// TODO: do something with maps to avoid all duplicate constraint issues, and order issues too
// Remove all duplicate NOT NULL constraints from a
var aa []ColConstraint
seenNotNull := false
for _, cc := range a {
// Only allow one NotNullConstraint through
if cc.GetConstraintType() == NotNullConstraintType {
if !seenNotNull {
aa = append(aa, cc)
seenNotNull = true
}
} else {
aa = append(aa, cc)
}
}
// Remove all duplicate NOT NULL constraints from b
var bb []ColConstraint
seenNotNull = false
for _, cc := range b {
// Only allow one NotNullConstraint through
if cc.GetConstraintType() == NotNullConstraintType {
if !seenNotNull {
bb = append(bb, cc)
seenNotNull = true
}
} else {
bb = append(bb, cc)
}
}
if len(aa) != len(bb) {
return false
} else if len(aa) == 0 {
return true
}
// kinda shitty. Probably shouldn't require order to be identical
for i := 0; i < len(aa); i++ {
ca, cb := aa[i], bb[i]
for i := 0; i < len(a); i++ {
ca, cb := a[i], b[i]
if ca.GetConstraintType() != cb.GetConstraintType() {
return false