Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into taylor/more-dg-types
Browse files Browse the repository at this point in the history
  • Loading branch information
tbantle22 committed Dec 4, 2024
2 parents e10835a + dcfc2a0 commit e11b19b
Show file tree
Hide file tree
Showing 9 changed files with 289 additions and 40 deletions.
14 changes: 14 additions & 0 deletions go/libraries/doltcore/branch_control/access.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ func (tbl *Access) Match(database string, branch string, user string, host strin
for _, result := range results {
if result.Length > length {
perms = result.Permissions
length = result.Length
} else if result.Length == length {
perms |= result.Permissions
}
Expand Down Expand Up @@ -258,3 +259,16 @@ OuterLoop:
}
return AccessRow{}, false
}

// Consolidate reduces the permission set down to the most representative permission. For example, having both admin and
// write permissions are equivalent to only having the admin permission. Additionally, having no permissions is
// equivalent to only having the read permission.
func (perm Permissions) Consolidate() Permissions {
if perm&Permissions_Admin == Permissions_Admin {
return Permissions_Admin
} else if perm&Permissions_Write == Permissions_Write {
return Permissions_Write
} else {
return Permissions_Read
}
}
1 change: 1 addition & 0 deletions go/libraries/doltcore/branch_control/namespace.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ func (tbl *Namespace) CanCreate(database string, branch string, user string, hos
matchedValue := tbl.Values[matched]
// If we've found a longer match, then we reset the slice. We append to it in the following if statement.
if len(matchedValue.Branch) > longest {
longest = len(matchedValue.Branch)
filteredIndexes = filteredIndexes[:0]
}
if len(matchedValue.Branch) >= longest {
Expand Down
78 changes: 78 additions & 0 deletions go/libraries/doltcore/diff/table_deltas.go
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,81 @@ func (td TableDelta) HasSchemaChanged(ctx context.Context) (bool, error) {
return !fromSchemaHash.Equal(toSchemaHash), nil
}

func (td TableDelta) HasChangesIgnoringColumnTags(ctx context.Context) (bool, error) {

if td.FromTable == nil && td.ToTable == nil {
return true, nil
}

if td.IsAdd() || td.IsDrop() {
return true, nil
}

if td.IsRename() {
return true, nil
}

if td.HasFKChanges() {
return true, nil
}

fromRowDataHash, err := td.FromTable.GetRowDataHash(ctx)
if err != nil {
return false, err
}

toRowDataHash, err := td.ToTable.GetRowDataHash(ctx)
if err != nil {
return false, err
}

// Any change to the table data counts as a change
if !fromRowDataHash.Equal(toRowDataHash) {
return true, nil
}

fromTableHash, err := td.FromTable.HashOf()
if err != nil {
return false, err
}

toTableHash, err := td.FromTable.HashOf()
if err != nil {
return false, err
}

// If the data hashes have changed, the table has obviously changed.
if !fromTableHash.Equal(toTableHash) {
return true, nil
}

fromSchemaHash, err := td.FromTable.GetSchemaHash(ctx)
if err != nil {
return false, err
}

toSchemaHash, err := td.ToTable.GetSchemaHash(ctx)
if err != nil {
return false, err
}

// If neither data nor schema hashes have changed, the table is obviously the same.
if fromSchemaHash.Equal(toSchemaHash) {
return false, nil
}

// The schema hash has changed but the data has remained the same. We must inspect the schema to determine
// whether the change is observable or if only column tags have changed.

fromSchema, toSchema, err := td.GetSchemas(ctx)
if err != nil {
return false, err
}

// SchemasAreEqual correctly accounts for tags
return !schema.SchemasAreEqual(fromSchema, toSchema), nil
}

func (td TableDelta) HasDataChanged(ctx context.Context) (bool, error) {
// Database collation change is not a data change
if td.FromTable == nil && td.ToTable == nil {
Expand Down Expand Up @@ -445,6 +520,9 @@ func (td TableDelta) HasPrimaryKeySetChanged() bool {
}

func (td TableDelta) HasChanges() (bool, error) {
fromString := td.FromTable.DebugString(context.Background(), td.FromTable.NodeStore())
toString := td.ToTable.DebugString(context.Background(), td.ToTable.NodeStore())
_, _ = fromString, toString
hashChanged, err := td.HasHashChanged()
if err != nil {
return false, err
Expand Down
7 changes: 4 additions & 3 deletions go/libraries/doltcore/sqle/dtables/branch_control_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,9 +202,10 @@ func (tbl BranchControlTable) Insert(ctx *sql.Context, row sql.Row) error {
}
}

// We check if we're inserting a subset of an already-existing row. If we are, we deny the insertion as the existing
// row will already match against ALL possible values for this row.
if ok, modPerms := tbl.Match(database, branch, user, host); ok {
// We check if we're inserting a subset of an already-existing row. We only consider this a subset if the
// permissions are as permissible as the existing ones, or are more restrictive (i.e. write is a "subset permission"
// of admin). If we are, we deny the insertion as the existing row will already match against ALL possible values for this row.
if ok, modPerms := tbl.Match(database, branch, user, host); ok && perms.Consolidate() >= modPerms.Consolidate() {
permBits := uint64(modPerms)
permStr, _ := accessSchema[4].Type.(sql.SetType).BitsToString(permBits)
return sql.NewUniqueKeyErr(
Expand Down
14 changes: 14 additions & 0 deletions go/libraries/doltcore/sqle/dtables/status_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,20 @@ func newStatusItr(ctx *sql.Context, st *StatusTable) (*StatusItr, error) {
return nil, err
}

// Some tables may differ only in column tags and/or recorded conflicts.
// We try to make such changes invisible to users and shouldn't display them for unstaged tables.
changedUnstagedTables := make([]diff.TableDelta, 0, len(unstagedTables))
for _, unstagedTableDiff := range unstagedTables {
changed, err := unstagedTableDiff.HasChangesIgnoringColumnTags(ctx)
if err != nil {
return nil, err
}
if changed {
changedUnstagedTables = append(changedUnstagedTables, unstagedTableDiff)
}
}
unstagedTables = changedUnstagedTables

stagedSchemas, unstagedSchemas, err := diff.GetStagedUnstagedDatabaseSchemaDeltas(ctx, roots)
if err != nil {
return nil, err
Expand Down
Loading

0 comments on commit e11b19b

Please sign in to comment.