Skip to content

Commit

Permalink
Schema fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
tbantle22 committed Nov 13, 2024
1 parent 7a8d094 commit ec0bc7c
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 12 deletions.
32 changes: 21 additions & 11 deletions go/libraries/doltcore/sqle/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -1770,7 +1770,8 @@ func (db Database) GetViewDefinition(ctx *sql.Context, viewName string) (sql.Vie
return sql.ViewDefinition{Name: viewName, TextDefinition: blameViewTextDef, CreateViewStatement: fmt.Sprintf("CREATE VIEW `%s` AS %s", viewName, blameViewTextDef)}, true, nil
}

schTblHash, ok, err := root.GetTableHash(ctx, doltdb.TableName{Name: doltdb.GetSchemasTableName(), Schema: db.schemaName})
schemasTableName := getDoltSchemasTableName()
schTblHash, ok, err := root.GetTableHash(ctx, schemasTableName)
if err != nil {
return sql.ViewDefinition{}, false, err
}
Expand All @@ -1793,6 +1794,10 @@ func (db Database) GetViewDefinition(ctx *sql.Context, viewName string) (sql.Vie
}
}

if resolve.UseSearchPath {
db.schemaName = "dolt"
}

tbl, _, err := db.GetTableInsensitive(ctx, doltdb.GetSchemasTableName())
if err != nil {
return sql.ViewDefinition{}, false, err
Expand Down Expand Up @@ -1856,6 +1861,10 @@ func getViewDefinitionFromSchemaFragmentsOfView(ctx *sql.Context, tbl *WritableD

// AllViews implements sql.ViewDatabase
func (db Database) AllViews(ctx *sql.Context) ([]sql.ViewDefinition, error) {
if resolve.UseSearchPath {
db.schemaName = "dolt"
}

tbl, _, err := db.GetTableInsensitive(ctx, doltdb.GetSchemasTableName())
if err != nil {
return nil, err
Expand Down Expand Up @@ -1921,6 +1930,9 @@ func (db Database) GetTriggers(ctx *sql.Context) ([]sql.TriggerDefinition, error
dbState.SessionCache().CacheTriggers(key, triggers, db.schemaName)
}()

if resolve.UseSearchPath {
db.schemaName = "dolt"
}
tbl, _, err := db.GetTableInsensitive(ctx, doltdb.GetSchemasTableName())
if err != nil {
return nil, err
Expand Down Expand Up @@ -1974,6 +1986,9 @@ func (db Database) DropTrigger(ctx *sql.Context, name string) error {

// GetEvent implements sql.EventDatabase.
func (db Database) GetEvent(ctx *sql.Context, name string) (sql.EventDefinition, bool, error) {
if resolve.UseSearchPath {
db.schemaName = "dolt"
}
tbl, _, err := db.GetTableInsensitive(ctx, doltdb.GetSchemasTableName())
if err != nil {
return sql.EventDefinition{}, false, err
Expand Down Expand Up @@ -2006,6 +2021,9 @@ func (db Database) GetEvent(ctx *sql.Context, name string) (sql.EventDefinition,

// GetEvents implements sql.EventDatabase.
func (db Database) GetEvents(ctx *sql.Context) (events []sql.EventDefinition, token interface{}, err error) {
if resolve.UseSearchPath {
db.schemaName = "dolt"
}
tbl, _, err := db.GetTableInsensitive(ctx, doltdb.GetSchemasTableName())
if err != nil {
return nil, nil, err
Expand Down Expand Up @@ -2253,16 +2271,8 @@ func (db Database) dropFragFromSchemasTable(ctx *sql.Context, fragType, name str
return err
}

root, err := db.GetRoot(ctx)
if err != nil {
return err
}
if resolve.UseSearchPath && db.schemaName == "" {
schemaName, err := resolve.FirstExistingSchemaOnSearchPath(ctx, root)
if err != nil {
return err
}
db.schemaName = schemaName
if resolve.UseSearchPath {
db.schemaName = "dolt"
}

stbl, _, err := db.GetTableInsensitive(ctx, doltdb.GetSchemasTableName())
Expand Down
6 changes: 5 additions & 1 deletion go/libraries/doltcore/sqle/schema_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ func getOrCreateDoltSchemasTable(ctx *sql.Context, db Database) (retTbl *Writabl
}

tname := getDoltSchemasTableName()
if resolve.UseSearchPath && db.schemaName == "" {
if resolve.UseSearchPath {
db.schemaName = "dolt"
}

Expand Down Expand Up @@ -332,6 +332,10 @@ func migrateOldSchemasTableToNew(ctx *sql.Context, db Database, schemasTable *Wr
return nil, err
}

if resolve.UseSearchPath {
db.schemaName = "dolt"
}

tbl, _, err := db.GetTableInsensitive(ctx, tname.Name)
if err != nil {
return nil, err
Expand Down

0 comments on commit ec0bc7c

Please sign in to comment.