Skip to content

Commit

Permalink
Move dolt_log and dolt_branches to dolt schema for doltgres
Browse files Browse the repository at this point in the history
  • Loading branch information
tbantle22 committed Oct 24, 2024
1 parent 2bb1a17 commit aee5383
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 37 deletions.
42 changes: 24 additions & 18 deletions go/libraries/doltcore/doltdb/system_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ func GetPersistedSystemTables(ctx context.Context, root RootValue) ([]string, er

// GetGeneratedSystemTables returns table names of all generated system tables.
func GetGeneratedSystemTables(ctx context.Context, root RootValue) ([]string, error) {
s := set.NewStrSet(generatedSystemTables)
s := set.NewStrSet(getGeneratedSystemTables())

tn, err := root.GetTableNames(ctx, DefaultSchemaName)
if err != nil {
Expand Down Expand Up @@ -148,16 +148,18 @@ var getWriteableSystemTables = func() []string {
}
}

var generatedSystemTables = []string{
BranchesTableName,
RemoteBranchesTableName,
LogTableName,
TableOfTablesInConflictName,
TableOfTablesWithViolationsName,
CommitsTableName,
CommitAncestorsTableName,
StatusTableName,
RemotesTableName,
var getGeneratedSystemTables = func() []string {
return []string{
GetBranchesTableName(),
RemoteBranchesTableName,
GetLogTableName(),
TableOfTablesInConflictName,
TableOfTablesWithViolationsName,
CommitsTableName,
CommitAncestorsTableName,
StatusTableName,
RemotesTableName,
}
}

var generatedSystemTablePrefixes = []string{
Expand All @@ -176,7 +178,7 @@ const (
ReadmeDoc = "README.md"
)

// DocTableName is the name of the dolt table containing documents such as the license and readme
// GetDocTableName returns the name of the dolt table containing documents such as the license and readme
var GetDocTableName = func() string {
return "dolt_docs"
}
Expand Down Expand Up @@ -243,10 +245,17 @@ const (
DoltWorkspaceTablePrefix = "dolt_workspace_"
)

const (
// LogTableName is the log system table name
LogTableName = "dolt_log"
// GetBranchesTableName returns the branches system table name
var GetBranchesTableName = func() string {
return "dolt_branches"
}

// GetLogTableName returns the log system table name
var GetLogTableName = func() string {
return "dolt_log"
}

const (
// DiffTableName is the name of the table with a map of commits to tables changed
DiffTableName = "dolt_diff"

Expand All @@ -262,9 +271,6 @@ const (
// SchemaConflictsTableName is the schema conflicts system table name
SchemaConflictsTableName = "dolt_schema_conflicts"

// BranchesTableName is the branches system table name
BranchesTableName = "dolt_branches"

// RemoteBranchesTableName is the all-branches system table name
RemoteBranchesTableName = "dolt_remote_branches"

Expand Down
19 changes: 16 additions & 3 deletions go/libraries/doltcore/sqle/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,11 @@ func (db Database) getTableInsensitive(ctx *sql.Context, head *doltdb.Commit, ds
var dt sql.Table
found := false
switch lwrName {
case doltdb.LogTableName:
case doltdb.GetLogTableName():
// TODO: This should be moved once all the system tables are moved to the dolt schema
if resolve.UseSearchPath && db.schemaName != "dolt" {
return nil, false, nil
}
if head == nil {
var err error
head, err = ds.GetHeadCommit(ctx, db.RevisionQualifiedName())
Expand Down Expand Up @@ -456,7 +460,11 @@ func (db Database) getTableInsensitive(ctx *sql.Context, head *doltdb.Commit, ds
dt, found = dtables.NewTableOfTablesConstraintViolations(ctx, root), true
case doltdb.SchemaConflictsTableName:
dt, found = dtables.NewSchemaConflictsTable(ctx, db.RevisionQualifiedName(), db.ddb), true
case doltdb.BranchesTableName:
case doltdb.GetBranchesTableName():
// TODO: This should be moved once all the system tables are moved to the dolt schema
if resolve.UseSearchPath && db.schemaName != "dolt" {
return nil, false, nil
}
dt, found = dtables.NewBranchesTable(ctx, db), true
case doltdb.RemoteBranchesTableName:
dt, found = dtables.NewRemoteBranchesTable(ctx, db), true
Expand Down Expand Up @@ -509,6 +517,10 @@ func (db Database) getTableInsensitive(ctx *sql.Context, head *doltdb.Commit, ds
dt, found = dtables.NewIgnoreTable(ctx, versionableTable), true
}
case doltdb.GetDocTableName():
// TODO: This should be moved once all the system tables are moved to the dolt schema
if resolve.UseSearchPath && db.schemaName != "dolt" {
return nil, false, nil
}
backingTable, _, err := db.getTable(ctx, root, doltdb.GetDocTableName())
if err != nil {
return nil, false, err
Expand Down Expand Up @@ -952,7 +964,8 @@ func (db Database) getAllTableNames(ctx *sql.Context, root doltdb.RootValue) ([]
func filterDoltInternalTables(tblNames []string) []string {
result := []string{}
for _, tbl := range tblNames {
if !doltdb.HasDoltPrefix(tbl) {
// TODO: Need to consider dolt schema
if !doltdb.HasDoltPrefix(tbl) && tbl != doltdb.GetBranchesTableName() && tbl != doltdb.GetLogTableName() {
result = append(result, tbl)
}
}
Expand Down
14 changes: 7 additions & 7 deletions go/libraries/doltcore/sqle/dtables/branches_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,27 +66,27 @@ func (bt *BranchesTable) RowCount(_ *sql.Context) (uint64, bool, error) {
return branchesDefaultRowCount, false, nil
}

// Name is a sql.Table interface function which returns the name of the table which is defined by the constant
// BranchesTableName
// Name is a sql.Table interface function which returns the name of the table
// which is defined by the function GetBranchesTableName()
func (bt *BranchesTable) Name() string {
if bt.remote {
return doltdb.RemoteBranchesTableName
}
return doltdb.BranchesTableName
return doltdb.GetBranchesTableName()
}

// String is a sql.Table interface function which returns the name of the table which is defined by the constant
// BranchesTableName
// String is a sql.Table interface function which returns the name of the table
// which is defined by the function GetBranchesTableName()
func (bt *BranchesTable) String() string {
if bt.remote {
return doltdb.RemoteBranchesTableName
}
return doltdb.BranchesTableName
return doltdb.GetBranchesTableName()
}

// Schema is a sql.Table interface function that gets the sql.Schema of the branches system table
func (bt *BranchesTable) Schema() sql.Schema {
tableName := doltdb.BranchesTableName
tableName := doltdb.GetBranchesTableName()
if bt.remote {
tableName = doltdb.RemoteBranchesTableName
}
Expand Down
18 changes: 9 additions & 9 deletions go/libraries/doltcore/sqle/dtables/log_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,25 +74,25 @@ func (dt *LogTable) RowCount(ctx *sql.Context) (uint64, bool, error) {
}

// Name is a sql.Table interface function which returns the name of the table which is defined by the constant
// LogTableName
// GetLogTableName()
func (dt *LogTable) Name() string {
return doltdb.LogTableName
return doltdb.GetLogTableName()
}

// String is a sql.Table interface function which returns the name of the table which is defined by the constant
// LogTableName
// GetLogTableName()
func (dt *LogTable) String() string {
return doltdb.LogTableName
return doltdb.GetLogTableName()
}

// Schema is a sql.Table interface function that gets the sql.Schema of the log system table.
func (dt *LogTable) Schema() sql.Schema {
return []*sql.Column{
{Name: "commit_hash", Type: types.Text, Source: doltdb.LogTableName, PrimaryKey: true, DatabaseSource: dt.dbName},
{Name: "committer", Type: types.Text, Source: doltdb.LogTableName, PrimaryKey: false, DatabaseSource: dt.dbName},
{Name: "email", Type: types.Text, Source: doltdb.LogTableName, PrimaryKey: false, DatabaseSource: dt.dbName},
{Name: "date", Type: types.Datetime, Source: doltdb.LogTableName, PrimaryKey: false, DatabaseSource: dt.dbName},
{Name: "message", Type: types.Text, Source: doltdb.LogTableName, PrimaryKey: false, DatabaseSource: dt.dbName},
{Name: "commit_hash", Type: types.Text, Source: doltdb.GetLogTableName(), PrimaryKey: true, DatabaseSource: dt.dbName},
{Name: "committer", Type: types.Text, Source: doltdb.GetLogTableName(), PrimaryKey: false, DatabaseSource: dt.dbName},
{Name: "email", Type: types.Text, Source: doltdb.GetLogTableName(), PrimaryKey: false, DatabaseSource: dt.dbName},
{Name: "date", Type: types.Datetime, Source: doltdb.GetLogTableName(), PrimaryKey: false, DatabaseSource: dt.dbName},
{Name: "message", Type: types.Text, Source: doltdb.GetLogTableName(), PrimaryKey: false, DatabaseSource: dt.dbName},
}
}

Expand Down

0 comments on commit aee5383

Please sign in to comment.