Skip to content

Commit

Permalink
working?
Browse files Browse the repository at this point in the history
  • Loading branch information
James Cor committed Aug 23, 2024
1 parent 8238c28 commit 762e8da
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 100 deletions.
51 changes: 30 additions & 21 deletions go/libraries/doltcore/sqle/dolt_ci_tables_creator.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@
package sqle

import (
"github.com/dolthub/dolt/go/libraries/doltcore/branch_control"
"github.com/dolthub/dolt/go/libraries/doltcore/sqle/dsess"
"fmt"
"github.com/dolthub/dolt/go/libraries/doltcore/branch_control"
"github.com/dolthub/dolt/go/libraries/doltcore/doltdb"
"github.com/dolthub/dolt/go/libraries/doltcore/sqle/dsess"
"github.com/dolthub/go-mysql-server/sql"
)

Expand Down Expand Up @@ -45,31 +47,38 @@ func (d doltCITablesCreator) CreateTables(ctx *sql.Context) error {
return err
}

//dbName := ctx.GetCurrentDatabase()
//dSess := dsess.DSessFromSess(ctx.Session)

//dbState, ok, err := dSess.LookupDbState(ctx, dbName)
//if err != nil {
// return err
//}
//
//if !ok {
// return fmt.Errorf("database %s not found in database state", dbName)
//}
// TOD0: maybe CreateTable(...) should take in old RootVal and return new RootVal?
err := d.workflowsTC.CreateTable(ctx)
if err != nil {
return err
}

//originalWorkingSetHash, err := dbState.WorkingSet().HashOf()
//if err != nil {
// return err
//}
//
//fmt.Fprintf(color.Output, "original working set hash: %s\n", originalWorkingSetHash)
err = d.workflowEventsTC.CreateTable(ctx)
if err != nil {
return err
}

err := d.workflowsTC.CreateTable(ctx)
// update doltdb workingset exactly once
dbName := ctx.GetCurrentDatabase()
dSess := dsess.DSessFromSess(ctx.Session)
ws, err := dSess.WorkingSet(ctx, dbName)
if err != nil {
return err
}
wsHash, err := ws.HashOf() // TODO: setting the WorkingRoot of WorkingSet has no impact on hash
if err != nil {
return err
}
ddb, exists := dSess.GetDoltDB(ctx, dbName)
if !exists {
return fmt.Errorf("database not found in database %s", dbName)
}
err = ddb.UpdateWorkingSet(ctx, ws.Ref(), ws, wsHash, doltdb.TodoWorkingSetMeta(), nil)
if err != nil {
return err
}

return d.workflowEventsTC.CreateTable(ctx)
return nil
}

var _ DoltCITablesCreator = &doltCITablesCreator{}
40 changes: 8 additions & 32 deletions go/libraries/doltcore/sqle/dolt_ci_workflow_events_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,22 +39,19 @@ func NewDoltCIWorkflowEventsTableCreator() *doltCIWorkflowEventsTableCreator {
func (d *doltCIWorkflowEventsTableCreator) CreateTable(ctx *sql.Context) error {
dbName := ctx.GetCurrentDatabase()
dSess := dsess.DSessFromSess(ctx.Session)

ws, err := dSess.WorkingSet(ctx, dbName)
if err != nil {
return err
}

startHash, err := ws.HashOf()
root := ws.WorkingRoot()
startHash, err := root.HashOf()
if err != nil {
return err
}
fmt.Fprintf(color.Output, "workflow events WorkingSet.WorkingRoot.HashOf() start: %s\n", startHash)

fmt.Fprintf(color.Output, "workflow events working set hash at start: %s\n", startHash)

roots, _ := dSess.GetRoots(ctx, dbName)

found, err := roots.Working.HasTable(ctx, doltdb.TableName{Name: doltdb.WorkflowEventsTableName})
found, err := root.HasTable(ctx, doltdb.TableName{Name: doltdb.WorkflowEventsTableName})
if err != nil {
return err
}
Expand Down Expand Up @@ -104,7 +101,7 @@ func (d *doltCIWorkflowEventsTableCreator) CreateTable(ctx *sql.Context) error {
}

// underlying table doesn't exist. Record this, then create the table.
nrv, err := doltdb.CreateEmptyTable(ctx, roots.Working, doltdb.TableName{Name: doltdb.WorkflowEventsTableName}, sch)
nrv, err := doltdb.CreateEmptyTable(ctx, root, doltdb.TableName{Name: doltdb.WorkflowEventsTableName}, sch)
if err != nil {
return err
}
Expand Down Expand Up @@ -187,38 +184,17 @@ func (d *doltCIWorkflowEventsTableCreator) CreateTable(ctx *sql.Context) error {
return err
}

//newWorkingSetRef := newWorkingSet.Ref()
//ddb, exists := dSess.GetDoltDB(ctx, dbName)
//if !exists {
// return fmt.Errorf("database not found in database %s", dbName)
//}

////oldHash, err := newWorkingSet.HashOf()
////if err != nil {
//// return err
////}
//
//oldHash, err := dbState.WorkingSet().HashOf()
//if err != nil {
// return err
//}

//err = ddb.UpdateWorkingSet(ctx, newWorkingSetRef, newWorkingSet, startHash, doltdb.TodoWorkingSetMeta(), nil)
//if err != nil {
// return err
//}

nws, err := dSess.WorkingSet(ctx, dbName)
if err != nil {
return err
}

endHash, err := nws.HashOf()
newRoot := nws.WorkingRoot()
endHash, err := newRoot.HashOf()
if err != nil {
return err
}

fmt.Fprintf(color.Output, "workflow events working set hash at end: %s\n", endHash)
fmt.Fprintf(color.Output, "workflow events WorkingSet.WorkingRoot.HashOf() end: %s\n", endHash)
return nil

}
55 changes: 8 additions & 47 deletions go/libraries/doltcore/sqle/dolt_ci_workflows_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,31 +36,19 @@ func NewDoltCIWorkflowsTableCreator() *doltCIWorkflowsTableCreator {
func (d *doltCIWorkflowsTableCreator) CreateTable(ctx *sql.Context) error {
dbName := ctx.GetCurrentDatabase()
dSess := dsess.DSessFromSess(ctx.Session)

ws, err := dSess.WorkingSet(ctx, dbName)
if err != nil {
return err
}

startHash, err := ws.HashOf()
root := ws.WorkingRoot()
startHash, err := root.HashOf()
if err != nil {
return err
}
fmt.Fprintf(color.Output, "workflow WorkingSet.WorkingRoot.HashOf() start: %s\n", startHash)

fmt.Fprintf(color.Output, "workflow working set hash at start: %s\n", startHash)

//dbState, ok, err := dSess.LookupDbState(ctx, dbName)
//if err != nil {
// return err
//}

//if !ok {
// return fmt.Errorf("no root value found in session")
//}

roots, _ := dSess.GetRoots(ctx, dbName)

found, err := roots.Working.HasTable(ctx, doltdb.TableName{Name: doltdb.WorkflowsTableName})
found, err := root.HasTable(ctx, doltdb.TableName{Name: doltdb.WorkflowsTableName})
if err != nil {
return err
}
Expand Down Expand Up @@ -111,14 +99,7 @@ func (d *doltCIWorkflowsTableCreator) CreateTable(ctx *sql.Context) error {
}

// underlying table doesn't exist. Record this, then create the table.
nrv, err := doltdb.CreateEmptyTable(ctx, roots.Working, doltdb.TableName{Name: doltdb.WorkflowsTableName}, newSchema)
if err != nil {
return err
}

newWorkingSet := ws.WithWorkingRoot(nrv)
//newWorkingSet := dbState.WorkingSet().WithWorkingRoot(nrv)
err = dSess.SetWorkingSet(ctx, dbName, newWorkingSet)
nrv, err := doltdb.CreateEmptyTable(ctx, root, doltdb.TableName{Name: doltdb.WorkflowsTableName}, newSchema)
if err != nil {
return err
}
Expand All @@ -128,37 +109,17 @@ func (d *doltCIWorkflowsTableCreator) CreateTable(ctx *sql.Context) error {
return err
}

newWorkingSetRef := newWorkingSet.Ref()
ddb, exists := dSess.GetDoltDB(ctx, dbName)
if !exists {
return fmt.Errorf("database not found in database %s", dbName)
}

//oldHash, err := newWorkingSet.HashOf()
//if err != nil {
// return err
//}
//
//oldHash, err := dbState.WorkingSet().HashOf()
//if err != nil {
// return err
//}

err = ddb.UpdateWorkingSet(ctx, newWorkingSetRef, newWorkingSet, startHash, doltdb.TodoWorkingSetMeta(), nil)
if err != nil {
return err
}

nws, err := dSess.WorkingSet(ctx, dbName)
if err != nil {
return err
}

endHash, err := nws.HashOf()
newRoot := nws.WorkingRoot()
endHash, err := newRoot.HashOf()
if err != nil {
return err
}

fmt.Fprintf(color.Output, "workflow working set hash at end: %s\n", endHash)
fmt.Fprintf(color.Output, "workflow WorkingSet.WorkingRoot.HashOf() end: %s\n", endHash)
return nil
}

0 comments on commit 762e8da

Please sign in to comment.