-
-
Notifications
You must be signed in to change notification settings - Fork 853
Add @ database revision delimiter for ORMs and drivers
#10431
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 16 commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
92cb7dc
add implementation for new `@` database revision delimiter for use in…
elianddb 6ed4751
add new `ScriptTest`s in `DoltRevisionDbScripts` for database revisio…
elianddb f303fd4
fix ORM CI tests to run automatically, add new Prisma branch test usi…
elianddb 48f708d
rm unused orm-tests github action
elianddb 1040b9a
fix behavior when `dolt_show_branch_databases` interacts with `dolt_e…
elianddb 26c2de9
fix sql shell current database to resolve new delimiter and fix revis…
elianddb c1de39e
mv docker orm tests to separate branch
elianddb e196152
fix shell promp current db split system
elianddb 792ce9d
add tests for commit revisions
elianddb bb71e47
amend sess var querying
elianddb fa4da6b
rm configuration for delimiter
elianddb 6a0b0fc
fix normal db compatibility that use `@` character
elianddb e078b89
implement full prompt resolver for base db, revision, and dirty state
elianddb 3a532d4
amend base db and rev resolver to use new active_revision() and base_…
elianddb 332316e
add skip on windows
elianddb 37b922f
fix dolt_status check on non-dolt databases
elianddb 4a77378
mv delimiter alias to be parsed on last index
elianddb 5841bf0
amend sql-shell resolver to evaluate using `active_branch()` and `dat…
elianddb a436dac
Merge remote-tracking branch 'origin/main' into elian/10382
elianddb fd4c81f
amend to gms pr
elianddb 3b583ef
fix dolt_status test
elianddb 74d5d60
mv delimiter checks to dolt
elianddb 451b3af
Merge remote-tracking branch 'origin/main' into elian/10382
elianddb 831952b
amend gms ver.
elianddb cb6dc3b
amend delimiter precedence to be the same left-to-right evaluation, a…
elianddb f49fdf6
Merge remote-tracking branch 'origin/main' into elian/10382
elianddb ca74006
amend gms ver. to dolthub/go-mysql-server#3448
elianddb b6eaad2
rm string.ToLower() on SessionDatabase entirely, gms expects case-sen…
elianddb 710564a
Merge remote-tracking branch 'origin/main' into elian/10382
elianddb File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,4 +26,5 @@ CLAUDE.md | |
| .gitattributes | ||
|
|
||
| .de/ | ||
| .cursor | ||
| AGENTS.md | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,171 @@ | ||
| // Copyright 2026 Dolthub, Inc. | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| package prompt | ||
|
|
||
| import ( | ||
| "errors" | ||
|
|
||
| "github.com/dolthub/go-mysql-server/sql" | ||
|
|
||
| "github.com/dolthub/dolt/go/cmd/dolt/cli" | ||
| "github.com/dolthub/dolt/go/libraries/doltcore/doltdb" | ||
| ) | ||
|
|
||
| // Parts contains shell prompt components to render in the final prompt. | ||
| type Parts struct { | ||
| BaseDatabase string | ||
| ActiveRevision string | ||
| IsBranch bool | ||
| Dirty bool | ||
| } | ||
|
|
||
| // Resolver resolves prompt Parts for the active session. | ||
| type Resolver interface { | ||
| Resolve(sqlCtx *sql.Context, queryist cli.Queryist) (parts Parts, resolved bool, err error) | ||
| } | ||
|
|
||
| // sqlBaseRevisionResolver can resolve [prompt.Parts] using Dolt specific SQL functions that return canonical base | ||
| // database and revision, even when the [doltdb.DbRevisionDelimiterAlias] is in use. | ||
| type sqlBaseRevisionResolver struct{} | ||
|
|
||
| // sqlDBActiveBranchResolver can resolve [prompt.Parts] using the SQL-specific functions. It is a fallback for older | ||
| // servers, and is the method older shells use in general. This resolver does not support | ||
| // [doltdb.DbRevisionDelimiterAlias] as a revision delimiter. | ||
| type sqlDBActiveBranchResolver struct{} | ||
|
|
||
| // chainedResolver can resolve [prompt.Parts] through the sequential execution [prompt.Resolver](s). | ||
| type chainedResolver struct { | ||
| resolvers []Resolver | ||
| } | ||
|
|
||
| // NewPartsResolver constructs an up-to-date [prompt.Resolver]. | ||
| func NewPartsResolver() Resolver { | ||
| return chainedResolver{ | ||
| resolvers: []Resolver{ | ||
| sqlBaseRevisionResolver{}, | ||
| sqlDBActiveBranchResolver{}, | ||
| }, | ||
| } | ||
| } | ||
|
|
||
| // Resolve resolves [prompt.Parts] through a chain of [prompt.Resolver](s) in sequential order. If a Resolver encounters | ||
| // an error, it is returned immediately and no other Resolver executes. | ||
| func (cr chainedResolver) Resolve(sqlCtx *sql.Context, queryist cli.Queryist) (parts Parts, resolved bool, err error) { | ||
| for _, resolver := range cr.resolvers { | ||
| parts, resolved, err := resolver.Resolve(sqlCtx, queryist) | ||
| if err != nil { | ||
| return Parts{}, false, err | ||
| } | ||
| if resolved { | ||
| return parts, true, nil | ||
| } | ||
| } | ||
| return Parts{}, false, nil | ||
| } | ||
|
|
||
| // Resolve resolves [prompt.Parts] through SQL functions `base_database()` and `active_revision()`. | ||
| func (sqlBaseRevisionResolver) Resolve(sqlCtx *sql.Context, queryist cli.Queryist) (parts Parts, resolved bool, err error) { | ||
| parts = Parts{} | ||
|
|
||
| rows, err := cli.GetRowsForSql(queryist, sqlCtx, "select base_database() as base_database, active_revision() as active_revision") | ||
| if sql.ErrFunctionNotFound.Is(err) { | ||
| // Running on an older version. | ||
| return parts, false, nil | ||
| } else if err != nil { | ||
| return parts, false, err | ||
| } | ||
|
|
||
| if len(rows) > 0 { | ||
| if len(rows[0]) > 0 { | ||
| parts.BaseDatabase, err = cli.GetStringColumnValue(rows[0][0]) | ||
| if err != nil { | ||
| return parts, false, err | ||
| } | ||
| } | ||
| if len(rows[0]) > 1 { | ||
| parts.ActiveRevision, err = cli.GetStringColumnValue(rows[0][1]) | ||
| if err != nil { | ||
| return parts, false, err | ||
| } | ||
| } | ||
| } | ||
|
|
||
| parts.Dirty, parts.IsBranch, err = resolveDirty(sqlCtx, queryist, parts) | ||
| if err != nil { | ||
| return parts, false, err | ||
| } | ||
| return parts, true, nil | ||
| } | ||
|
|
||
| // Resolve resolves the base database and active revision through the SQL-specific functions `database()` and | ||
| // `active_branch()`. Unfortunately, to maintain support for ORMs that rely on the database in their connection URL, | ||
| // this method cannot interpret [doltdb.DbRevisionDelimiterAlias] as a revision delimiter. | ||
| func (sqlDBActiveBranchResolver) Resolve(sqlCtx *sql.Context, queryist cli.Queryist) (parts Parts, resolved bool, err error) { | ||
| parts = Parts{} | ||
|
elianddb marked this conversation as resolved.
Outdated
|
||
| dbRows, err := cli.GetRowsForSql(queryist, sqlCtx, "select database() as db") | ||
| if err != nil { | ||
| return parts, false, err | ||
| } | ||
| if len(dbRows) > 0 && len(dbRows[0]) > 0 { | ||
| dbName, err := cli.GetStringColumnValue(dbRows[0][0]) | ||
| if err != nil { | ||
| return parts, false, err | ||
| } | ||
| parts.BaseDatabase, parts.ActiveRevision = doltdb.SplitRevisionDbName(dbName) | ||
| } | ||
|
|
||
| if parts.ActiveRevision == "" { | ||
| activeBranchRows, err := cli.GetRowsForSql(queryist, sqlCtx, "select active_branch() as branch") | ||
| if err != nil { | ||
| return parts, false, err | ||
| } | ||
| if len(activeBranchRows) > 0 && len(activeBranchRows[0]) > 0 { | ||
| parts.ActiveRevision, err = cli.GetStringColumnValue(activeBranchRows[0][0]) | ||
| if err != nil { | ||
| return parts, false, err | ||
| } | ||
| } | ||
| } | ||
|
|
||
| parts.Dirty, parts.IsBranch, err = resolveDirty(sqlCtx, queryist, parts) | ||
| if err != nil { | ||
| return parts, false, err | ||
| } | ||
| return parts, true, nil | ||
| } | ||
|
|
||
| // resolveDirty resolves the dirty state of the current branch and whether the revision type is a branch. | ||
| func resolveDirty(sqlCtx *sql.Context, queryist cli.Queryist, parts Parts) (dirty bool, isBranch bool, err error) { | ||
| if doltdb.IsValidCommitHash(parts.ActiveRevision) { | ||
| return false, false, nil | ||
| } | ||
|
|
||
| rows, err := cli.GetRowsForSql(queryist, sqlCtx, "select count(table_name) > 0 as dirty from dolt_status") | ||
| if errors.Is(err, doltdb.ErrOperationNotSupportedInDetachedHead) || sql.ErrTableNotFound.Is(err) { | ||
| return false, false, nil | ||
| } else if err != nil { | ||
| return false, false, err | ||
| } | ||
|
|
||
| if len(rows) == 0 || len(rows[0]) == 0 { | ||
| return false, false, nil | ||
| } | ||
| dirty, err = cli.GetBoolColumnValue(rows[0][0]) | ||
| if err != nil { | ||
| return false, false, err | ||
| } | ||
|
|
||
| return dirty, true, nil | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.