mirror of
https://github.com/dolthub/dolt.git
synced 2025-12-30 16:12:39 -06:00
Starting to regret my life decisions
This commit is contained in:
@@ -63,8 +63,8 @@ type TableDelta struct {
|
||||
ToSch schema.Schema
|
||||
FromFks []doltdb.ForeignKey
|
||||
ToFks []doltdb.ForeignKey
|
||||
ToFksParentSch map[string]schema.Schema
|
||||
FromFksParentSch map[string]schema.Schema
|
||||
ToFksParentSch map[doltdb.TableName]schema.Schema
|
||||
FromFksParentSch map[doltdb.TableName]schema.Schema
|
||||
}
|
||||
|
||||
type TableDeltaSummary struct {
|
||||
@@ -119,7 +119,7 @@ func GetTableDeltas(ctx context.Context, fromRoot, toRoot doltdb.RootValue) (del
|
||||
toNS := toRoot.NodeStore()
|
||||
|
||||
fromDeltas := make([]TableDelta, 0)
|
||||
err = fromRoot.IterTables(ctx, func(name string, tbl *doltdb.Table, sch schema.Schema) (stop bool, err error) {
|
||||
err = fromRoot.IterTables(ctx, func(name doltdb.TableName, tbl *doltdb.Table, sch schema.Schema) (stop bool, err error) {
|
||||
c, err := fromRoot.GetForeignKeyCollection(ctx)
|
||||
if err != nil {
|
||||
return true, err
|
||||
@@ -149,7 +149,7 @@ func GetTableDeltas(ctx context.Context, fromRoot, toRoot doltdb.RootValue) (del
|
||||
|
||||
toDeltas := make([]TableDelta, 0)
|
||||
|
||||
err = toRoot.IterTables(ctx, func(name string, tbl *doltdb.Table, sch schema.Schema) (stop bool, err error) {
|
||||
err = toRoot.IterTables(ctx, func(name doltdb.TableName, tbl *doltdb.Table, sch schema.Schema) (stop bool, err error) {
|
||||
c, err := toRoot.GetForeignKeyCollection(ctx)
|
||||
if err != nil {
|
||||
return true, err
|
||||
@@ -197,8 +197,8 @@ func GetTableDeltas(ctx context.Context, fromRoot, toRoot doltdb.RootValue) (del
|
||||
if ok {
|
||||
dbName := DBPrefix + sqlCtx.GetCurrentDatabase()
|
||||
deltas = append(deltas, TableDelta{
|
||||
FromName: dbName,
|
||||
ToName: dbName,
|
||||
FromName: doltdb.TableName{Name: dbName},
|
||||
ToName: doltdb.TableName{Name: dbName},
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -206,16 +206,16 @@ func GetTableDeltas(ctx context.Context, fromRoot, toRoot doltdb.RootValue) (del
|
||||
// Make sure we always return the same order of deltas
|
||||
sort.Slice(deltas, func(i, j int) bool {
|
||||
if deltas[i].FromName == deltas[j].FromName {
|
||||
return deltas[i].ToName < deltas[j].ToName
|
||||
return deltas[i].ToName.Less(deltas[j].ToName)
|
||||
}
|
||||
return deltas[i].FromName < deltas[j].FromName
|
||||
return deltas[i].FromName.Less(deltas[j].FromName)
|
||||
})
|
||||
|
||||
return deltas, nil
|
||||
}
|
||||
|
||||
func getFkParentSchs(ctx context.Context, root doltdb.RootValue, fks ...doltdb.ForeignKey) (map[string]schema.Schema, error) {
|
||||
schs := make(map[string]schema.Schema)
|
||||
func getFkParentSchs(ctx context.Context, root doltdb.RootValue, fks ...doltdb.ForeignKey) (map[doltdb.TableName]schema.Schema, error) {
|
||||
schs := make(map[doltdb.TableName]schema.Schema)
|
||||
for _, toFk := range fks {
|
||||
// TODO: schema
|
||||
toRefTable, _, ok, err := doltdb.GetTableInsensitive(ctx, root, doltdb.TableName{Name: toFk.ReferencedTableName})
|
||||
@@ -229,7 +229,8 @@ func getFkParentSchs(ctx context.Context, root doltdb.RootValue, fks ...doltdb.F
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
schs[toFk.ReferencedTableName] = toRefSch
|
||||
// TODO: schema name
|
||||
schs[doltdb.TableName{Name: toFk.ReferencedTableName}] = toRefSch
|
||||
}
|
||||
return schs, nil
|
||||
}
|
||||
@@ -258,13 +259,13 @@ func filterUnmodifiedTableDeltas(deltas []TableDelta) ([]TableDelta, error) {
|
||||
}
|
||||
|
||||
func matchTableDeltas(fromDeltas, toDeltas []TableDelta) (deltas []TableDelta) {
|
||||
var matchedNames []string
|
||||
from := make(map[string]TableDelta, len(fromDeltas))
|
||||
var matchedNames []doltdb.TableName
|
||||
from := make(map[doltdb.TableName]TableDelta, len(fromDeltas))
|
||||
for _, f := range fromDeltas {
|
||||
from[f.FromName] = f
|
||||
}
|
||||
|
||||
to := make(map[string]TableDelta, len(toDeltas))
|
||||
to := make(map[doltdb.TableName]TableDelta, len(toDeltas))
|
||||
for _, t := range toDeltas {
|
||||
to[t.ToName] = t
|
||||
if _, ok := from[t.ToName]; ok {
|
||||
@@ -445,10 +446,10 @@ func (td TableDelta) HasChanges() (bool, error) {
|
||||
|
||||
// CurName returns the most recent name of the table.
|
||||
func (td TableDelta) CurName() string {
|
||||
if td.ToName != "" {
|
||||
return td.ToName
|
||||
if td.ToName.Name != "" {
|
||||
return td.ToName.Name
|
||||
}
|
||||
return td.FromName
|
||||
return td.FromName.Name
|
||||
}
|
||||
|
||||
func (td TableDelta) HasFKChanges() bool {
|
||||
|
||||
@@ -175,7 +175,7 @@ func GetUnreachableRootCause(err error) error {
|
||||
|
||||
// DoltIgnoreConflictError is an error that is returned when the user attempts to stage a table that matches conflicting dolt_ignore patterns
|
||||
type DoltIgnoreConflictError struct {
|
||||
Table string
|
||||
Table TableName
|
||||
TruePatterns []string
|
||||
FalsePatterns []string
|
||||
}
|
||||
@@ -183,7 +183,7 @@ type DoltIgnoreConflictError struct {
|
||||
func (dc DoltIgnoreConflictError) Error() string {
|
||||
var buffer bytes.Buffer
|
||||
buffer.WriteString("the table ")
|
||||
buffer.WriteString(dc.Table)
|
||||
buffer.WriteString(dc.Table.Name)
|
||||
buffer.WriteString(" matches conflicting patterns in dolt_ignore:")
|
||||
|
||||
for _, pattern := range dc.TruePatterns {
|
||||
|
||||
@@ -22,7 +22,7 @@ import (
|
||||
"fmt"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/row"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/schema"
|
||||
"github.com/dolthub/dolt/go/libraries/utils/set"
|
||||
@@ -133,7 +133,7 @@ func (fk ForeignKey) EqualDefs(other ForeignKey) bool {
|
||||
// column names to column tags, which is why |fkSchemasByName| and |otherSchemasByName| are passed in. Each of these
|
||||
// is a map of table schemas for |fk| and |other|, where the child table and every parent table referenced in the
|
||||
// foreign key is present in the map.
|
||||
func (fk ForeignKey) Equals(other ForeignKey, fkSchemasByName, otherSchemasByName map[string]schema.Schema) bool {
|
||||
func (fk ForeignKey) Equals(other ForeignKey, fkSchemasByName, otherSchemasByName map[TableName]schema.Schema) bool {
|
||||
// If both FKs are resolved or unresolved, we can just deeply compare them
|
||||
if fk.IsResolved() == other.IsResolved() {
|
||||
return fk.DeepEquals(other)
|
||||
@@ -154,7 +154,7 @@ func (fk ForeignKey) Equals(other ForeignKey, fkSchemasByName, otherSchemasByNam
|
||||
|
||||
// Sort out which FK is resolved and which is not
|
||||
var resolvedFK, unresolvedFK ForeignKey
|
||||
var resolvedSchemasByName map[string]schema.Schema
|
||||
var resolvedSchemasByName map[TableName]schema.Schema
|
||||
if fk.IsResolved() {
|
||||
resolvedFK, unresolvedFK, resolvedSchemasByName = fk, other, fkSchemasByName
|
||||
} else {
|
||||
@@ -167,7 +167,7 @@ func (fk ForeignKey) Equals(other ForeignKey, fkSchemasByName, otherSchemasByNam
|
||||
}
|
||||
for i, tag := range resolvedFK.TableColumns {
|
||||
unresolvedColName := unresolvedFK.UnresolvedFKDetails.TableColumns[i]
|
||||
resolvedSch, ok := resolvedSchemasByName[resolvedFK.TableName]
|
||||
resolvedSch, ok := resolvedSchemasByName[TableName{Name: resolvedFK.TableName}]
|
||||
if !ok {
|
||||
return false
|
||||
}
|
||||
@@ -186,7 +186,7 @@ func (fk ForeignKey) Equals(other ForeignKey, fkSchemasByName, otherSchemasByNam
|
||||
}
|
||||
for i, tag := range resolvedFK.ReferencedTableColumns {
|
||||
unresolvedColName := unresolvedFK.UnresolvedFKDetails.ReferencedTableColumns[i]
|
||||
resolvedSch, ok := resolvedSchemasByName[unresolvedFK.ReferencedTableName]
|
||||
resolvedSch, ok := resolvedSchemasByName[TableName{Name: unresolvedFK.ReferencedTableName}]
|
||||
if !ok {
|
||||
return false
|
||||
}
|
||||
@@ -578,13 +578,13 @@ func (fkc *ForeignKeyCollection) Iter(cb func(fk ForeignKey) (stop bool, err err
|
||||
// declaredFk contains all foreign keys in which this table declared the foreign key. The array referencedByFk contains
|
||||
// all foreign keys in which this table is the referenced table. If the table contains a self-referential foreign key,
|
||||
// it will be present in both declaresFk and referencedByFk. Each array is sorted by name ascending.
|
||||
func (fkc *ForeignKeyCollection) KeysForTable(tableName string) (declaredFk, referencedByFk []ForeignKey) {
|
||||
lowercaseTblName := strings.ToLower(tableName)
|
||||
func (fkc *ForeignKeyCollection) KeysForTable(tableName TableName) (declaredFk, referencedByFk []ForeignKey) {
|
||||
lowercaseTblName := tableName.ToLower()
|
||||
for _, foreignKey := range fkc.foreignKeys {
|
||||
if strings.ToLower(foreignKey.TableName) == lowercaseTblName {
|
||||
if strings.ToLower(foreignKey.TableName) == lowercaseTblName.Name {
|
||||
declaredFk = append(declaredFk, foreignKey)
|
||||
}
|
||||
if strings.ToLower(foreignKey.ReferencedTableName) == lowercaseTblName {
|
||||
if strings.ToLower(foreignKey.ReferencedTableName) == lowercaseTblName.Name {
|
||||
referencedByFk = append(referencedByFk, foreignKey)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -112,12 +112,12 @@ func GetIgnoredTablePatterns(ctx context.Context, roots Roots) (IgnorePatterns,
|
||||
// ExcludeIgnoredTables takes a list of table names and removes any tables that should be ignored,
|
||||
// as determined by the patterns in the dolt_ignore table.
|
||||
// The ignore patterns are read from the dolt_ignore table in the working set.
|
||||
func ExcludeIgnoredTables(ctx context.Context, roots Roots, tables []string) ([]string, error) {
|
||||
func ExcludeIgnoredTables(ctx context.Context, roots Roots, tables []TableName) ([]TableName, error) {
|
||||
ignorePatterns, err := GetIgnoredTablePatterns(ctx, roots)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
filteredTables := []string{}
|
||||
filteredTables := []TableName{}
|
||||
for _, tbl := range tables {
|
||||
ignored, err := ignorePatterns.IsTableNameIgnored(tbl)
|
||||
if err != nil {
|
||||
@@ -176,7 +176,7 @@ func normalizePattern(pattern string) string {
|
||||
return pattern
|
||||
}
|
||||
|
||||
func resolveConflictingPatterns(trueMatches, falseMatches []string, tableName string) (IgnoreResult, error) {
|
||||
func resolveConflictingPatterns(trueMatches, falseMatches []string, tableName TableName) (IgnoreResult, error) {
|
||||
trueMatchesToRemove := map[string]struct{}{}
|
||||
falseMatchesToRemove := map[string]struct{}{}
|
||||
for _, trueMatch := range trueMatches {
|
||||
@@ -231,10 +231,10 @@ func resolveConflictingPatterns(trueMatches, falseMatches []string, tableName st
|
||||
return IgnorePatternConflict, DoltIgnoreConflictError{Table: tableName, TruePatterns: conflictingTrueMatches, FalsePatterns: conflictingFalseMatches}
|
||||
}
|
||||
|
||||
func (ip *IgnorePatterns) IsTableNameIgnored(tableName string) (IgnoreResult, error) {
|
||||
func (ip *IgnorePatterns) IsTableNameIgnored(tableName TableName) (IgnoreResult, error) {
|
||||
// The dolt_rebase table is automatically ignored by Dolt – it shouldn't ever
|
||||
// be checked in to a Dolt database.
|
||||
if strings.ToLower(tableName) == strings.ToLower(RebaseTableName) {
|
||||
if strings.ToLower(tableName.Name) == strings.ToLower(RebaseTableName) {
|
||||
return Ignore, nil
|
||||
}
|
||||
|
||||
@@ -247,7 +247,7 @@ func (ip *IgnorePatterns) IsTableNameIgnored(tableName string) (IgnoreResult, er
|
||||
if err != nil {
|
||||
return ErrorOccurred, err
|
||||
}
|
||||
if patternRegExp.MatchString(tableName) {
|
||||
if patternRegExp.MatchString(tableName.Name) {
|
||||
if ignore {
|
||||
trueMatches = append(trueMatches, pattern)
|
||||
} else {
|
||||
|
||||
@@ -426,8 +426,9 @@ func GetExistingColumns(
|
||||
|
||||
func GetAllSchemas(ctx context.Context, root RootValue) (map[string]schema.Schema, error) {
|
||||
m := make(map[string]schema.Schema)
|
||||
err := root.IterTables(ctx, func(name string, table *Table, sch schema.Schema) (stop bool, err error) {
|
||||
m[name] = sch
|
||||
err := root.IterTables(ctx, func(name TableName, table *Table, sch schema.Schema) (stop bool, err error) {
|
||||
// TODO: schema name
|
||||
m[name.Name] = sch
|
||||
return false, nil
|
||||
})
|
||||
|
||||
@@ -544,8 +545,8 @@ func GetTableInsensitive(ctx context.Context, root RootValue, tName TableName) (
|
||||
}
|
||||
|
||||
// GetTableByColTag looks for the table containing the given column tag.
|
||||
func GetTableByColTag(ctx context.Context, root RootValue, tag uint64) (tbl *Table, name string, found bool, err error) {
|
||||
err = root.IterTables(ctx, func(tn string, t *Table, s schema.Schema) (bool, error) {
|
||||
func GetTableByColTag(ctx context.Context, root RootValue, tag uint64) (tbl *Table, name TableName, found bool, err error) {
|
||||
err = root.IterTables(ctx, func(tn TableName, t *Table, s schema.Schema) (bool, error) {
|
||||
_, found = s.GetAllCols().GetByTag(tag)
|
||||
if found {
|
||||
name, tbl = tn, t
|
||||
@@ -555,7 +556,7 @@ func GetTableByColTag(ctx context.Context, root RootValue, tag uint64) (tbl *Tab
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
return nil, "", false, err
|
||||
return nil, TableName{}, false, err
|
||||
}
|
||||
|
||||
return tbl, name, found, nil
|
||||
@@ -1000,9 +1001,10 @@ func GetAllTagsForRoots(ctx context.Context, roots ...RootValue) (tags schema.Ta
|
||||
if root == nil {
|
||||
continue
|
||||
}
|
||||
err = root.IterTables(ctx, func(tblName string, _ *Table, sch schema.Schema) (stop bool, err error) {
|
||||
err = root.IterTables(ctx, func(tblName TableName, _ *Table, sch schema.Schema) (stop bool, err error) {
|
||||
for _, t := range sch.GetAllCols().Tags {
|
||||
tags.Add(t, tblName)
|
||||
// TODO: schema names
|
||||
tags.Add(t, tblName.Name)
|
||||
}
|
||||
return
|
||||
})
|
||||
@@ -1137,9 +1139,9 @@ func (root *rootValue) DebugString(ctx context.Context, transitive bool) string
|
||||
|
||||
if transitive {
|
||||
buf.WriteString("\nTables:")
|
||||
root.IterTables(ctx, func(name string, table *Table, sch schema.Schema) (stop bool, err error) {
|
||||
root.IterTables(ctx, func(name TableName, table *Table, sch schema.Schema) (stop bool, err error) {
|
||||
buf.WriteString("\nTable ")
|
||||
buf.WriteString(name)
|
||||
buf.WriteString(name.Name)
|
||||
buf.WriteString(":\n")
|
||||
|
||||
buf.WriteString(table.DebugString(ctx, root.ns))
|
||||
|
||||
6
go/libraries/doltcore/env/actions/staged.go
vendored
6
go/libraries/doltcore/env/actions/staged.go
vendored
@@ -103,9 +103,9 @@ func stageTables(ctx context.Context, roots doltdb.Roots, tbls []doltdb.TableNam
|
||||
}
|
||||
|
||||
// clearEmptyConflicts clears any 0-row conflicts from the tables named, and returns a new root.
|
||||
func clearEmptyConflicts(ctx context.Context, tbls []string, working doltdb.RootValue) (doltdb.RootValue, error) {
|
||||
func clearEmptyConflicts(ctx context.Context, tbls []doltdb.TableName, working doltdb.RootValue) (doltdb.RootValue, error) {
|
||||
for _, tblName := range tbls {
|
||||
tbl, ok, err := working.GetTable(ctx, doltdb.TableName{Name: tblName})
|
||||
tbl, ok, err := working.GetTable(ctx, tblName)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -129,7 +129,7 @@ func clearEmptyConflicts(ctx context.Context, tbls []string, working doltdb.Root
|
||||
return nil, err
|
||||
}
|
||||
|
||||
working, err = working.PutTable(ctx, doltdb.TableName{Name: tblName}, clrTbl)
|
||||
working, err = working.PutTable(ctx, tblName, clrTbl)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user