Doltgres provides native stored procedures to access version control features in a SQL session. Each procedure is named after the dolt command line command it matches, and takes arguments in an identical form.
For example, dolt checkout -b feature-branch is equivalent to executing the following SQL statement:
SELECT DOLT_CHECKOUT('-b', 'feature-branch');
SQL procedures are provided for all imperative version control operations. For operations that inspect the state of the database and print some information, (dolt diff, dolt log, etc.) system tables are provided instead.
DOLT_ADD()
Adds working changes to staged for this session.
After adding tables to the staged area, they can be committed with DOLT_COMMIT().
table: Table(s) to add to the list tables staged to be committed. The abbreviation '.' can be used to add all tables.
-A: Stages all tables with changes.
Output Schema
+--------+------+---------------------------+
| Field | Type | Description |
+--------+------+---------------------------+
| status | int | 0 if successful, 1 if not |
+--------+------+---------------------------+
Example
-- Set the current database for the sessionUSE mydb;-- Make modificationsUPDATEtableSET column ='new value'WHERE pk ='key';-- Stage all changes.SELECT DOLT_ADD('-A');-- Commit the changes.SELECT DOLT_COMMIT('-m', 'committing all changes');
DOLT_BACKUP()
Sync with a configured backup. Other backup commands not supported via SQL yet.
SELECT DOLT_BACKUP('sync', 'name');
Output Schema
+--------+------+---------------------------+
| Field | Type | Description |
+--------+------+---------------------------+
| status | int | 0 if successful, 1 if not |
+--------+------+---------------------------+
Example
-- Set the current database for the sessionUSE mydb;-- Upload the current database contents to the named backupSELECT dolt_backup('sync', 'my-backup')
To look up the current branch, use the @@<dbname>_head_ref system variable, or the active_branch() SQL function, as shown in the examples section below.
WARNING: In a multi-session server environment, Dolt will prevent you from deleting or renaming a branch in use in another session. You can force renaming or deletion by passing the --force option, but be aware that active clients on other sessions will no longer be able to execute statements after their active branch is removed and will need to end their session and reconnect.
-- Create a new branch from the current HEADSELECT DOLT_BRANCH('myNewBranch');-- Create a new branch from start point of tip of feature1 branch.SELECT DOLT_BRANCH('myNewBranch', 'feature1');-- Create a new branch by copying an existing branch-- Will fail if feature1 branch already existsSELECT DOLT_BRANCH('-c', 'main', 'feature1');-- Create or replace a branch by copying an existing branch-- '-f' forces the copy, even if feature1 branch already existsSELECT DOLT_BRANCH('-c', '-f', 'main', 'feature1');-- Delete a branchSELECT DOLT_BRANCH('-d', 'branchToDelete');-- Rename a branchSELECT DOLT_BRANCH('-m', 'currentBranchName', 'newBranchName')
Notes
Branch names have a few restrictions which are similar to the constraints Git puts on branch names. Dolt's branches are a little more restrictive, as ASCII characters are required. Rules are as follows:
All characters must be ASCII (7 Bit)
May not start with '.' (period)
May not contain '..' (two periods)
May not contain '@{'
May not contain ASCII control characters
May not contain characters: ':', '?', '[', '\', '^', '~', '*'
May not contain whitespace (spaces, tabs, newlines)
May not end with '/'
May not end with '.lock'
May not be HEAD (case insensitive)
May not be indistinguishable from a commit hash. 32 characters, where all characters are 0-9 or a-z (case sensitive)
The dolt_branch() procedure implicitly commits the current transaction and begins a new one.
Options
-c, --copy: Create a copy of a branch. Must be followed by the name of the source branch to copy and the name of the new branch to create. Without the --force option, the copy will fail if the new branch already exists.
-m, --move: Move/rename a branch. Must be followed by the current name of an existing branch and a new name for that branch. Without the --force option, renaming a branch in use on another server session will fail. Be aware that forcibly renaming or deleting a branch in use in another session will require that session to disconnect and reconnect before it can execute statements again.
-d, --delete: Delete a branch. Must be followed by the name of an existing branch to delete. Without the --force option, deleting a branch in use on another server session will fail. Be aware that forcibly renaming or deleting a branch in use in another session will require that session to disconnect and reconnect before it can execute statements again.
-f, --force: When used with the --copy option, allows for recreating a branch from another branch, even if the branch already exists. When used with the --move or --delete options, force will allow you to rename or delete branches in use in other active server sessions, but be aware that this will require those other sessions to disconnect and reconnect before they can execute statements again.
-D: Shortcut for --delete --force.
Output Schema
+--------+------+---------------------------+
| Field | Type | Description |
+--------+------+---------------------------+
| status | int | 0 if successful, 1 if not |
+--------+------+---------------------------+
Examples
-- List the available branchesSELECT*FROM DOLT_BRANCHES;+--------+----------------------------------+| name | hash |+--------+----------------------------------+| backup | nsqtc86d54kafkuf0a24s4hqircvg68g || main | dvtsgnlg7n9squriob3nq6kve6gnhkf2 |+--------+----------------------------------+-- Create a new branch for development work from the tip of head and switch to itSELECT DOLT_BRANCH('myNewFeature');SELECT DOLT_CHECKOUT('myNewFeature');-- View your current branchselect active_branch();+----------------+| active_branch |+----------------+| myNewFeature |+----------------+-- Create a new branch from an existing branchSELECT DOLT_BRANCH('-c', 'backup', 'bugfix-3482');-- Rename a branchSELECT DOLT_BRANCH('-m', 'bugfix-3482', 'critical-bugfix-3482');-- Delete a branchSELECT DOLT_BRANCH('-d', 'old-unused-branch');
DOLT_CHECKOUT()
Switches this session to a different branch.
With table names as arguments, restores those tables to their contents in the current HEAD.
Note, unlike the Git command-line, if you have a modified working set, those changes remain on the branch you modified after a DOLT_CHECKOUT(). Uncommitted changes in the working set do not transfer to the checked out branch as on the command line. We modified this behavior in the SQL context because multiple users may be connected to the same branch. Having one user bring changes from various other branches with them when they switch branches is too disruptive in the multi-tenant SQL context.
DOLT_CHECKOUT() with a branch argument has two side effects on your session state:
The session's current database, as returned by SELECT DATABASE(), is now the unqualified database name.
For the remainder of this session, references to the unqualified name of this database will resolve to the branch checked out.
See the comments after the statements below for an example of this behavior, and also read Using Branches
set autocommit =on;use mydb/branch1; -- current db is now `mydb/branch1`insert into t1 values (1); -- modifying the `branch1` branchselect dolt_checkout('branch2'); -- current db is now `mydb`insert into t1 values (2); -- modifying the `branch2` branchuse mydb/branch3; -- current db is now `mydb/branch3`insert into mydb.t1 values (3); -- modifying the `branch2` branch
Options
-b: Create a new branch with the given name.
-B: Similar to -b, but will move a branch if it already exists.
-t: When creating a new branch, set up 'upstream' configuration.
Output Schema
+---------+------+-----------------------------+
| Field | Type | Description |
+---------+------+-----------------------------+
| status | int | 0 if successful, 1 if not |
| message | text | success/failure information |
+---------+------+-----------------------------+
Example
-- Set the current database for the sessionUSE mydb;-- Create and checkout to a new branch.SELECT DOLT_CHECKOUT('-b', 'feature-branch');-- Make modificationsUPDATEtableSET column ='new value'WHERE pk ='key';-- Stage and commit all changes.SELECT DOLT_COMMIT('-a', '-m', 'committing all changes');-- Go back to mainSELECT DOLT_CHECKOUT('main');
DOLT_CHERRY_PICK()
Apply the changes introduced by an existing commit.
Apply changes from existing commit and creates a new commit from the current HEAD.
+-----------------------+------+---------------------------------+
| Field | Type | Description |
+-----------------------+------+---------------------------------+
| hash | text | hash of the applied commit |
| data_conflicts | int | number of data conflicts |
| schema_conflicts | int | number of schema conflicts |
| constraint_violations | int | number of constraint violations |
+-----------------------+------+---------------------------------+
Example
For the below example consider the following set up of main and mybranch branches:
-- Checkout main branchSELECT DOLT_CHECKOUT('main');-- View a log of commitsSELECT commit_hash, messageFROM dolt_log;+----------------------------------+----------------------------+| commit_hash | message |+----------------------------------+----------------------------+| 7e2q0hibo2m2af874i4e7isgnum74j4m | create a new table || omuqq67att6vfnka94drdallu4983gnr | Initialize data repository |+----------------------------------+----------------------------+2rowsinset (0.00 sec)-- View the tableSELECT*FROM mytable;Emptyset (0.00 sec)-- Checkout new branchSELECT DOLT_CHECKOUT('mybranch');-- View a log of commitsSELECT commit_hash, messageFROM dolt_log;+----------------------------------+----------------------------+| commit_hash | message |+----------------------------------+----------------------------+| 577isdjbq1951k2q4dqhli06jlauo51p | add3, 4, 5to the table || k318tpmqn4l97ofpaerato9c3m70lc14 | add1, 2to the table || 7e2q0hibo2m2af874i4e7isgnum74j4m | create a new table || omuqq67att6vfnka94drdallu4983gnr | Initialize data repository |+----------------------------------+----------------------------+4rowsinset (0.00 sec)-- View the tableSELECT*FROM mytable;+---+| a |+---+| 1 || 2 || 3 || 4 || 5 |+---+5rowsinset (0.00 sec)
We want to cherry-pick only the change introduced in commit hash 'k318tpmqn4l97ofpaerato9c3m70lc14', which inserts 1 and 2 to the table. Specifying 'mybranch~1' instead of the commit hash also works.
-- Checkout main branchSELECT DOLT_CHECKOUT('main');-- Cherry-pick the commitSELECT DOLT_CHERRY_PICK('k318tpmqn4l97ofpaerato9c3m70lc14');+----------------------------------+| hash |+----------------------------------+| mh518gdgbsut8m705b7b5rie9neq9uaj |+----------------------------------+1rowinset (0.02 sec)mydb>SELECT*FROM mytable;+---+| a |+---+| 1 || 2 |+---+2rowsinset (0.00 sec)mydb>SELECT commit_hash, messageFROM dolt_log;+----------------------------------+----------------------------+| commit_hash | message |+----------------------------------+----------------------------+| mh518gdgbsut8m705b7b5rie9neq9uaj | add1, 2to the table || 7e2q0hibo2m2af874i4e7isgnum74j4m | create a new table || omuqq67att6vfnka94drdallu4983gnr | Initialize data repository |+----------------------------------+----------------------------+3rowsinset (0.00 sec)
DOLT_CLEAN()
Deletes untracked tables in the working set.
Deletes only specified untracked tables if table names passed as arguments.
With --dry-run flag, tests whether removing untracked tables will return with zero status.
--dry-run: Test removing untracked tables from working set.
Output Schema
+--------+------+---------------------------+
| Field | Type | Description |
+--------+------+---------------------------+
| status | int | 0 if successful, 1 if not |
+--------+------+---------------------------+
Example
-- Create three new tablescreatetabletracked (x intprimary key);createtablecommitted (x intprimary key);createtableuntracked (x intprimary key);-- Commit the first tableselect dolt_add('committed');select dolt_commit('-m', 'commit a table');+----------------------------------+| hash |+----------------------------------+| n7gle7jv6aqf72stbdicees6iduhuoo9 |+----------------------------------+-- Track the second tableselect dolt_add('tracked');-- Observe database statusselect*from dolt_status;+-------------------+--------+-----------+| table_name | staged | status |+-------------------+--------+-----------+| public.tracked | 1 | new table || public.untracked | 0 | new table |+-------------------+--------+-----------+-- Clear untracked tablesselect dolt_clean('untracked');-- Observe final statusselect*from dolt_status;+-----------------+--------+-----------+| table_name | staged | status |+-----------------+--------+-----------+| public.tracked | 1 | new table |+-----------------+--------+-----------+-- Committed and tracked tables are preservedselect tablename from pg_tables;+----------------+| tablename |+----------------+| committed || tracked |+----------------+
DOLT_CLONE()
Clones an existing Dolt database into a new database within the current Dolt environment. The existing database must be specified as an argument, either as a file URL that points to an existing Dolt database on disk, or a doltremote URL for remote hosted database (e.g. a database hosted on DoltHub or DoltLab), or a <org>/<database> (e.g. dolthub/us-jails) as a shorthand for a database hosted on DoltHub. An additional argument can optionally be supplied to specify the name of the new, cloned database, otherwise the current name of the existing database will be used.
NOTE: When cloning from a file URL, you must currently include the .dolt/noms subdirectories. For more details see the GitHub tracking issue, dolt#1860.
--remote: Name of the remote to be added to the new, cloned database. The default is 'origin'.
-b, --branch: The branch to be cloned. If not specified all branches will be cloned.
--depth: Clone a single branch and limit history to the given commit depth.
Output Schema
+--------+------+---------------------------+
| Field | Type | Description |
+--------+------+---------------------------+
| status | int | 0 if successful, 1 if not |
+--------+------+---------------------------+
Examples
-- Clone the dolthub/us-jails database from DoltHub using the <org>/<database> notation.SELECT DOLT_CLONE('dolthub/us-jails');-- Use the new, cloned database-- NOTE: backticks are required for database names with hyphensUSE`us-jails`;select tablename from pg_tables;+-----------------------------+| tablename |+-----------------------------+| incidents || inmate_population_snapshots || jails |+-----------------------------+-- Clone the dolthub/museum-collections database, this time using a doltremoteapi URL, cloning-- only a single branch, customizing the remote name, and providing a custom database name.SELECT DOLT_CLONE('-branch', 'prod', '-remote', 'dolthub','https://doltremoteapi.dolthub.com/dolthub/ge-taxi-demo', 'taxis');-- Verify that only the prod branch was clonedUSE taxis;SELECT*FROM DOLT_BRANCHES;+------+----------------------------------+------------------+------------------------+-------------------------+------------------------------+| name | hash | latest_committer | latest_committer_email | latest_commit_date | latest_commit_message |+------+----------------------------------+------------------+------------------------+-------------------------+------------------------------+| prod | 1s61u4rbbd26u0tlpdhb46cuejd1dogj | oscarbatori | oscarbatori@gmail.com | 2021-06-1417:52:58.702 | Added first cut of trip data |+------+----------------------------------+------------------+------------------------+-------------------------+------------------------------+-- Verify that the default remote for this new, cloned database is named "dolthub" (not "origin")SELECT*FROM DOLT_REMOTES;+---------+--------------------------------------------------------+-----------------------------------------+--------+| name | url | fetch_specs | params |+---------+--------------------------------------------------------+-----------------------------------------+--------+| dolthub | https://doltremoteapi.dolthub.com/dolthub/ge-taxi-demo | ["refs/heads/*:refs/remotes/dolthub/*"] | {} |+---------+--------------------------------------------------------+-----------------------------------------+--------+
DOLT_COMMIT()
Commits staged tables to HEAD. Works exactly like dolt commit with each value directly following the flag.
DOLT_COMMIT() also commits the current transaction.
SELECT DOLT_COMMIT('-a', '-m', 'This is a commit');SELECT DOLT_COMMIT('-m', 'This is a commit');SELECT DOLT_COMMIT('-m', 'This is a commit', '--author', 'John Doe <johndoe@example.com>');
Options
-m, --message: Use the given <msg> as the commit message. Required
-a, --all: Stages all modified tables (but not newly created tables) before committing.
-A, --ALL: Stages all tables (including new tables) before committing.
--allow-empty: Allow recording a commit that has the exact same data as its sole parent. This is usually a mistake, so it is disabled by default. This option bypasses that safety.
--skip-empty: Record a commit only if there are changes to be committed. The commit operation will be a no-op, instead of an error, if there are no changes staged to commit. An error will be thrown if --skip-empty is used with --allow-empty.
--date: Specify the date used in the commit. If not specified the current system time is used.
--author: Specify an explicit author using the standard "A U Thor author@example.com" format.
Output Schema
+-------+------+----------------------------+
| Field | Type | Description |
+-------+------+----------------------------+
| hash | text | hash of the commit created |
+-------+------+----------------------------+
Examples
-- Set the current database for the sessionUSE mydb;-- Make modificationsUPDATEtableSET column ='new value'WHERE pk ='key';-- Stage all changes and commit.SELECT DOLT_COMMIT('-a', '-m', 'This is a commit', '--author', 'John Doe <johndoe@example.com>');
DOLT_CONFLICTS_RESOLVE()
When a merge finds conflicting changes, it documents them in the dolt_conflicts table. A conflict is between two versions: ours (the rows at the destination branch head) and theirs (the rows at the source branch head). dolt conflicts resolve will automatically resolve the conflicts by taking either the ours or theirs versions for each row.
<table>: List of tables to be resolved. '.' can be used to resolve all tables.
--ours: For all conflicts, take the version from our branch and resolve the conflict.
--theirs: For all conflicts, take the version from their branch and resolve the conflict.
Output Schema
+--------+------+---------------------------+
| Field | Type | Description |
+--------+------+---------------------------+
| status | int | 0 if successful, 1 if not |
+--------+------+---------------------------+
Examples
-- Set the current database for the sessionUSE mydb;-- Attempt mergeSELECT DOLT_MERGE('feature-branch');-- Check for conflictsSELECT*FROM dolt_conflicts;-- Resolve conflicts for tables t1 and t2 with rows from our branch.SELECT DOLT_CONFLICTS_RESOLVE('--ours', 't1', 't2');
DOLT_FETCH()
Fetch refs, along with the objects necessary to complete their histories and update remote-tracking branches..
+--------+------+---------------------------+
| Field | Type | Description |
+--------+------+---------------------------+
| status | int | 0 if successful, 1 if not |
+--------+------+---------------------------+
Example
-- Get remote mainSELECT DOLT_FETCH('origin', 'main');-- Inspect the hash of the fetched remote branchSELECT HASHOF('origin/main');-- Merge remote main with current branchSELECT DOLT_MERGE('origin/main');
Notes
Dropping the second argument, or passing NULL, will result is using the default refspec.
DOLT_GC()
Cleans up unreferenced data from the database. Running the dolt_gc procedure on a Dolt sql-server will block all writes while garbage collection is in progress.
SELECT DOLT_GC();SELECT DOLT_GC('--shallow');
Options
--shallow Performs a faster but less thorough garbage collection.
Output Schema
+--------+------+---------------------------+
| Field | Type | Description |
+--------+------+---------------------------+
| status | int | 0 if successful, 1 if not |
+--------+------+---------------------------+
Notes
To prevent concurrent writes potentially referencing garbage collected chunks, running select dolt_gc() will break all open connections to the running server. In flight queries on those connections may fail and must be retried. Re-establishing connections after they are broken is safe.
At the end of the run, the connection which ran select dolt_gc() will be left open in order to deliver the results of the operation itself. The connection will be left in a terminally broken state where any attempt to run a query on it will result in the following error:
ERROR 1105 (HY000): this connection was established when this server performed an online
garbage collection. this connection can no longer be used. please reconnect.
The connection should be closed. In some connection pools it can be awkward to cause a single connection to actually close. If you need to run select dolt_gc() programmatically, one work around is to use a separate connection pool with a size of 1 which can be closed after the run is successful.
DOLT_MERGE()
Incorporates changes from the named commits (since the time their histories diverged from the current branch) into the current branch.
Any resulting merge conflicts must be resolved before the transaction can be committed or a new Dolt commit created. DOLT_MERGE() creates a new commit for any successful merge with auto-generated commit message if not defined.
SELECT DOLT_MERGE('feature-branch'); -- Optional --squash parameterSELECT DOLT_MERGE('feature-branch', '--no-ff', '-m', 'This is a msg for a non fast forward merge');SELECT DOLT_MERGE('--abort');
Notes
The dolt_merge() procedure implicitly commits the current transaction and begins a new one.
Options
--no-ff: Create a merge commit even when the merge resolves as a fast-forward.
--squash: Merges changes to the working set without updating the commit history
-m <msg>, --message=<msg>: Use the given as the commit message. This is only useful for --non-ff commits.
--abort: Abort the current conflict resolution process, and try to reconstruct the pre-merge state.
--author: Specify an explicit author using the standard A U Thor <author@example.com> format.
When merging a branch, your session state must be clean. COMMIT orROLLBACK any changes, then DOLT_COMMIT() to create a new dolt commit on the target branch.
If the merge causes conflicts or constraint violations, you must resolve them using the dolt_conflicts system tables before the transaction can be committed. See Dolt system tables for details.
Output Schema
+--------------+------+--------------------------------------+
| Field | Type | Description |
+--------------+------+--------------------------------------+
| hash | text | hash of the merge commit |
| fast_forward | int | whether the merge was a fast forward |
| conflicts | int | number of conflicts created |
| message | text | optional informational message |
+--------------+------+--------------------------------------+
Example
-- Set the current database for the sessionUSE mydb;-- Create and checkout to a new branch.SELECT DOLT_CHECKOUT('-b', 'feature-branch');-- Make modificationsUPDATEtableSET column ='new value'WHERE pk ='key';-- Stage and commit all changes.SELECT DOLT_COMMIT('-a', '-m', 'committing all changes');-- Go back to mainSELECT DOLT_MERGE('feature-branch', '--author', 'John Doe <johndoe@example.com>');
DOLT_PULL()
Fetch from and integrate with another database or a local branch. In its default mode, dolt pull is shorthand for dolt fetch followed by dolt merge <remote>/<branch>.
Any resulting merge conflicts must be resolved before the transaction can be committed or a new Dolt commit created.
--no-ff: Create a merge commit even when the merge resolves as a fast-forward.
--squash: Merges changes to the working set without updating the commit history
--force: Ignores any foreign key warnings and proceeds with the commit.
When merging a branch, your session state must be clean. COMMIT orROLLBACK any changes, then DOLT_COMMIT() to create a new Dolt commit on the target branch.
If the merge causes conflicts or constraint violations, you must resolve them using the dolt_conflicts system tables before the transaction can be committed. See Dolt system tables for details.
Output Schema
+--------------+------+-------------------------------------+
| Field | Type | Description |
+--------------+------+-------------------------------------+
| fast_forward | int | whether the pull was a fast forward |
| conflicts | int | number of conflicts created |
| message | text | optional informational message |
+--------------+------+-------------------------------------+
Example
-- Update local working set with remote changes-- Note: this requires upstream tracking information to be set in order for-- Dolt to know what remote branch to mergeSELECT DOLT_PULL('origin');-- Update local working set with remote changes from an explicit branchSELECT DOLT_PULL('origin', 'some-branch');-- View a log of new commitsSELECT*FROM dolt_log LIMIT5;
DOLT_PURGE_DROPPED_DATABASES()
Permanently deletes any dropped databases that are being held in a temporary holding area. When a Dolt database is dropped, it is moved to a temporary holding area where the dolt_undrop() stored procedure can restore it. The dolt_purge_dropped_databases() stored procedure clears this holding area and permanently deletes any data from those databases. This action is not reversible, so callers should be cautious about using it. The main benefit of using this function is to reclaim disk space used by the temporary holding area. Because this is a destructive operation, callers must have SUPER privileges in order to execute it.
Example
-- Create a database and populate a table in the working setCREATEDATABASEdatabase1;use database1;createtablet(pk intprimary key);-- Dropping the database will move it to a temporary holding areaDROPDATABASE database1;-- At this point, the database can be restored by calling dolt_undrop('database1'), but-- instead, we permanently delete it by calling dolt_purge_dropped_databases().SELECT dolt_purge_dropped_databases();
DOLT_PUSH()
Updates remote refs using local refs, while sending objects necessary to complete the given refs.
--force: Update the remote with local history, overwriting any conflicting history in the remote.
Output Schema
+---------+------+--------------------------------+
| Field | Type | Description |
+---------+------+--------------------------------+
| status | int | 0 if successful, 1 if not |
| message | text | optional informational message |
+---------+------+--------------------------------+
Example
-- Checkout new branchSELECT DOLT_CHECKOUT('-b', 'feature-branch');-- Add a tableCREATETABLEtest (a intprimary key);-- Create commitSELECT DOLT_COMMIT('-a', '-m', 'create table test');-- Push to remoteSELECT DOLT_PUSH('origin', 'feature-branch');
DOLT_REBASE()
Rewrites commit history for the current branch by replaying commits, allowing the commits to be reordered, squashed, or dropped. The commits included in the rebase plan are the commits reachable by the current branch, but NOT reachable from the branch specified as the argument when starting a rebase (also known as the upstream branch). This is the same as Git and Dolt's "two dot log" syntax, or |upstreamBranch|..|currentBranch|.
For example, consider the commit graph below, where a feature branch has branched off of a main branch, and both branches have added commits:
A → B → C → D → E → F main ↘ G → H → I feature
If we rebase from the feature branch using the main branch as our upstream, the default rebase plan will include commits G, H, and I, since those commits are reachable from our current branch, but NOT reachable from the upstream branch. By default, the changes from those same commits will be reapplied, in the same order, to the tip of the upstream branch main. The resulting commit graph will then look like:
A → B → C → D → E → F main ↘ G' → H' → I' feature
Rebasing is useful to clean and organize your commit history, especially before merging a feature branch back to a shared branch. For example, you can drop commits that contain debugging or test changes, or squash or fixup small commits into a single commit, or reorder commits so that related changes are adjacent in the new commit history.
Currently only interactive rebases are supported, and there is no support for resolving conflicts that arise while executing a rebase plan. If applying a commit creates a conflict, the rebase will be automatically aborted.
Options
--interactive or -i: Start an interactive rebase. Currently only interactive rebases are supported, so this option is required.
--continue: Continue an interactive rebase after adjusting the rebase plan stored in dolt_rebase.
--abort: Abort a rebase in progress.
Output Schema
+---------+------+-----------------------------+
| Field | Type | Description |
+---------+------+-----------------------------+
| status | int | 0 if successful, 1 if not |
| message | text | success/failure information |
+---------+------+-----------------------------+
Example
-- create a simple tablecreatetablet (pk intprimary key);select dolt_commit('-Am', 'creating table t');-- create a new branch that we'll add more commits to laterselect dolt_branch('branch1');-- create another commit on the main branch, right after where branch1 branched offinsert into t values (0);select dolt_commit('-am', 'inserting row 0');-- switch to branch1 and create three more commits that each insert one rowselect dolt_checkout('branch1');insert into t values (1);select dolt_commit('-am', 'inserting row 1');insert into t values (2);select dolt_commit('-am', 'inserting row 2');insert into t values (3);select dolt_commit('-am', 'inserting row 3');-- check out what our commit history on branch1 looks like before we rebaseselect commit_hash, messagefrom dolt_log; commit_hash | message----------------------------------+---------------------------- m2v3oajs9jesvvc44ihqlsu1uq2c8jf2 | inserting row3 qa1t5ieqs418s1b7mssqlmpn68ackq20 | inserting row2 tgltn67jjho1mp8a3jdl3jkip08jbbun | inserting row1 nof0lk6ufv031mddiahqfqfelqcpjdv5 | creating table t pfjaqljdrdn43877sbc2d2sla9g3eb8u | CREATEDATABASE k23mej9jdej41s0n7o2g8gp5rpgvrfdb | Initialize data repository(6rows)-- start an interactive rebase and check out the default rebase plan; this will rebase-- all the new commits on this branch and move them to the tip of the main branchselect dolt_rebase('-i', 'main');select*from dolt_rebase order by rebase_order; rebase_order | action | commit_hash | commit_message--------------+--------+----------------------------------+-----------------1.00 | pick | tgltn67jjho1mp8a3jdl3jkip08jbbun | inserting row12.00 | pick | qa1t5ieqs418s1b7mssqlmpn68ackq20 | inserting row23.00 | pick | m2v3oajs9jesvvc44ihqlsu1uq2c8jf2 | inserting row3(3rows)-- adjust the rebase plan to reword the first commit, drop the commit that inserted row 2,-- and combine the third commit into the previous commitupdate dolt_rebase setaction='reword', commit_message='insert rows'where rebase_order=1;update dolt_rebase setaction='drop'where rebase_order=2;update dolt_rebase setaction='fixup'where rebase_order=3;-- continue rebasing now that we've adjusted the rebase planselect dolt_rebase('--continue');-- check out the historyselect commit_hash, messagefrom dolt_log; commit_hash | message----------------------------------+---------------------------- 8jc1dpj25fv6f2kn3bd47uokc8hs1vp0 | insertrows gd5rnrmjvbf0fb6sb8dfaf5a344t68ei | inserting row0 nof0lk6ufv031mddiahqfqfelqcpjdv5 | creating table t pfjaqljdrdn43877sbc2d2sla9g3eb8u | CREATEDATABASE k23mej9jdej41s0n7o2g8gp5rpgvrfdb | Initialize data repository(5rows)
DOLT_REMOTE()
Adds a remote for a database at given url, or removes an existing remote with its remote-tracking branches and configuration settings. To list existing remotes, use the dolt_remotes system table.
+--------+------+---------------------------+
| Field | Type | Description |
+--------+------+---------------------------+
| status | int | 0 if successful, 1 if not |
+--------+------+---------------------------+
Example
-- Add a HTTP remoteSELECT DOLT_REMOTE('add','origin','https://doltremoteapi.dolthub.com/Dolthub/museum-collections');-- Add a HTTP remote with shorthand notation for the URLSELECT DOLT_REMOTE('add','origin1','Dolthub/museum-collections');-- Add a filesystem based remoteSELECT DOLT_REMOTE('add','origin2','file:///Users/jennifer/datasets/museum-collections');-- List remotes to check.SELECT*FROM dolt_remotes;+---------+--------------------------------------------------------------+-----------------------------------------+--------+| name | url | fetch_specs | params |+---------+--------------------------------------------------------------+-----------------------------------------+--------+| origin | https://doltremoteapi.dolthub.com/Dolthub/museum-collections | ["refs/heads/*:refs/remotes/origin/*"] | {} || origin1 | https://doltremoteapi.dolthub.com/Dolthub/museum-collections | ["refs/heads/*:refs/remotes/origin1/*"] | {} || origin2 | file:///Users/jennifer/datasets/museum-collections | ["refs/heads/*:refs/remotes/origin2/*"] | {} |+---------+--------------------------------------------------------------+-----------------------------------------+--------+-- Remove a remoteSELECT DOLT_REMOTE('remove','origin1');-- List remotes to check.SELECT*FROM dolt_remotes;+---------+--------------------------------------------------------------+-----------------------------------------+--------+| name | url | fetch_specs | params |+---------+--------------------------------------------------------------+-----------------------------------------+--------+| origin | https://doltremoteapi.dolthub.com/Dolthub/museum-collections | ["refs/heads/*:refs/remotes/origin/*"] | {} || origin2 | file:///Users/jennifer/datasets/museum-collections | ["refs/heads/*:refs/remotes/origin2/*"] | {} |+---------+--------------------------------------------------------------+-----------------------------------------+--------+
DOLT_RESET()
Default mode resets staged tables to their HEAD state. Can also be used to reset a database to a specific commit.
Like other data modifications, after a reset you must COMMIT the transaction for any changes to affected tables to be visible to other clients.
With the --hard option, the dolt_reset() procedure implicitly commits the current transaction and begins a new one.
Options
--hard: Resets the working tables and staged tables. Any changes to tracked tables in the working tree since are discarded.
--soft: Does not touch the working tables, but removes all tables staged to be committed. This is the default behavior.
Output Schema
+--------+------+---------------------------+
| Field | Type | Description |
+--------+------+---------------------------+
| status | int | 0 if successful, 1 if not |
+--------+------+---------------------------+
Example
-- Set the current database for the sessionUSE mydb;-- Make modificationsUPDATEtableSET column ='new value'WHERE pk ='key';-- Reset the changes permanently.SELECT DOLT_RESET('--hard');-- Makes some more changes.UPDATEtableSET column ='new value'WHERE pk ='key';-- Stage the table.SELECT DOLT_ADD('table')-- Unstage the table.SELECT DOLT_RESET('table')
DOLT_REVERT()
Reverts the changes introduced in a commit, or set of commits. Creates a new commit from the current HEAD that reverses the changes in all the specified commits. If multiple commits are given, they are applied in the order given.
--author=<author>: Specify an explicit author using the standard A U Thor <author@example.com> format.
Output Schema
+--------+------+---------------------------+
| Field | Type | Description |
+--------+------+---------------------------+
| status | int | 0 if successful, 1 if not |
+--------+------+---------------------------+
Example
-- Create a table and add data in multiple commitsCREATETABLEt1(pk INTPRIMARY KEY, c VARCHAR(255));SELECT dolt_add('t1')SELECT dolt_commit('-m', 'Creating table t1');INSERT INTO t1 VALUES(1, 'a'), (2, 'b'), (3, 'c');SELECT dolt_commit('-am', 'Adding some data');insert into t1 VALUES(10, 'aa'), (20, 'bb'), (30, 'cc');SELECT dolt_commit('-am', 'Adding some more data');-- Examine the changes made in the commit immediately before the current HEAD commitSELECT to_pk, to_c, to_commit, diff_type FROM dolt_diff_t1 WHERE to_commit=hashof('HEAD~1');+-------+------+----------------------------------+-----------+| to_pk | to_c | to_commit | diff_type |+-------+------+----------------------------------+-----------+| 1 | a | fc4fks6jutcnee9ka6458nmuot7rl1r2 | added || 2 | b | fc4fks6jutcnee9ka6458nmuot7rl1r2 | added || 3 | c | fc4fks6jutcnee9ka6458nmuot7rl1r2 | added |+-------+------+----------------------------------+-----------+-- Revert the commit immediately before the current HEAD commitSELECT dolt_revert('HEAD~1');-- Check out the new commit created by dolt_revertSELECT commit_hash, messageFROM dolt_log limit1;+----------------------------------+---------------------------+| commit_hash | message |+----------------------------------+---------------------------+| vbevrdghj3in3napcgdsch0mq7f8en4v | Revert"Adding some data" |+----------------------------------+---------------------------+-- View the exact changes made by the revert commitSELECT from_pk, from_c, to_commit, diff_type FROM dolt_diff_t1 WHERE to_commit=hashof('HEAD');+---------+--------+----------------------------------+-----------+| from_pk | from_c | to_commit | diff_type |+---------+--------+----------------------------------+-----------+| 1 | a | vbevrdghj3in3napcgdsch0mq7f8en4v | removed || 2 | b | vbevrdghj3in3napcgdsch0mq7f8en4v | removed || 3 | c | vbevrdghj3in3napcgdsch0mq7f8en4v | removed |+---------+--------+----------------------------------+-----------+
DOLT_TAG()
Creates a new tag that points at specified commit ref, or deletes an existing tag. To list existing tags, use dolt_tags system table.
--author: Specify an explicit author using the standard "A U Thor author@example.com" format.
Output Schema
+--------+------+---------------------------+
| Field | Type | Description |
+--------+------+---------------------------+
| status | int | 0 if successful, 1 if not |
+--------+------+---------------------------+
Example
-- Set the current database for the sessionUSE mydb;-- Make modificationsUPDATEtableSET column ='new value'WHERE pk ='key';-- Stage and commit all changes.SELECT DOLT_COMMIT('-am', 'committing all changes');-- Create a tag for the HEAD commit.SELECT DOLT_TAG('v1','head','-m','creating v1 tag');
dolt_undrop() takes a single argument – the name of the dropped database to restore. When called without any arguments, dolt_undrop() returns an error message that contains a list of all dropped databases that are available to be restored.
Example
-- Create a database and populate a table in the working setCREATEDATABASEdatabase1;use database1;createtablet(pk intprimary key);-- Dropping the database will move it to a temporary holding areaDROPDATABASE database1;-- calling dolt_undrop() with no arguments will return an error message that-- lists the dropped database that are available to be restoredSELECT dolt_undrop();-- Use dolt_undrop() to restore itSELECT dolt_undrop('database1');SELECT*FROM database1.t;
DOLT_VERIFY_CONSTRAINTS()
Verifies that working set changes (inserts, updates, and/or deletes) satisfy the defined table constraints. If any constraints are violated they are written to the DOLT_CONSTRAINT_VIOLATIONS table.
DOLT_VERIFY_CONSTRAINTS by default does not detect constraints for row changes that have been previously committed. The --all option can be specified if you wish to validate all rows in the database. If FOREIGN_KEY_CHECKS has been disabled in prior commits, you may want to use the --all option to ensure that the current state is consistent and no violated constraints are missed.
Arguments and Options
<table>: The table(s) to check constraints on. If omitted, checks all tables.
-a, --all: Verifies constraints against every row.
+------------+------+-----------------------------------------+
| Field | Type | Description |
+------------+------+-----------------------------------------+
| violations | int | 1 if violations were found, otherwise 0 |
+------------+------+-----------------------------------------+
Example
For the below examples consider the following schema:
-- enable dolt_force_transaction_commit so that we can inspect the-- violation in our working setSET dolt_force_transaction_commit =ON;SET FOREIGN_KEY_CHECKS =OFF;INSERT INTO PARENT VALUES (1);-- Violates child's foreign key constraintINSERT INTO CHILD VALUES (1, -1);SELECT DOLT_VERIFY_CONSTRAINTS();/*+------------+| violations |+------------+| 1 |+------------+*/SELECT*from dolt_constraint_violations;/*+-------+----------------+| table | num_violations |+-------+----------------+| child | 1 |+-------+----------------+*/SELECT violation_type, pk, parent_fk from dolt_constraint_violations_child;/*+----------------+----+-----------+| violation_type | pk | parent_fk |+----------------+----+-----------+| foreign key | 1 | -1 |+----------------+----+-----------+*/
Using --all to verify all rows:
SET DOLT_FORCE_TRANSACTION_COMMIT =ON;SET FOREIGN_KEY_CHECKS =OFF;INSERT INTO PARENT VALUES (1);INSERT INTO CHILD VALUES (1, -1);SELECT DOLT_COMMIT('-am', 'violating rows');SELECT DOLT_VERIFY_CONSTRAINTS();/*No violations are returned since there are no changes in the working set.+------------+| violations |+------------+| 0 |+------------+*/SELECT*from dolt_constraints_violations_child;/*+----------------+----+-----------+----------------+| violation_type | pk | parent_fk | violation_info |+----------------+----+-----------+----------------++----------------+----+-----------+----------------+*/SELECT DOLT_VERIFY_CONSTRAINTS('--all');/*When all rows are considered, constraint violations are found.+------------+| violations |+------------+| 1 |+------------+*/SELECT*from dolt_constraint_violations_child;/*+----------------+----+-----------+| violation_type | pk | parent_fk |+----------------+----+-----------+| foreign key | 1 | -1 |+----------------+----+-----------+*/
Dolt stored procedures are access controlled using the GRANT permissions system. Postgres database permissions trickle down to tables and procedures, someone who has Execute permission on a database would have Execute permission on all procedures related to that database. Dolt deviates moderately from this behavior for sensitive operations. See Administrative Procedures below.
Users who need common Dolt capability such as adding and committing to a branch will need Execute permission granted on the database in question. As a privileged user, you can grant access with the following command:
mydb>GRANTEXECUTEON mydb.*TO pat@localhost
This will give the user, pat, the ability run all stored procedures on the database. This includes Dolt procedures as well as user defined procedures. If you need to use fine grained permissions, you can grant them individually:
mydb>GRANTEXECUTEONPROCEDURE mydb.dolt_commit TO pat@localhost
If you need to remove access for a particular capability, REVOKE as follows:
mydb>REVOKEEXECUTEONPROCEDURE mydb.dolt_commit FROM pat@localhostmydb>REVOKEEXECUTEON mydb.*FROM pat@localhost
Administrative Procedures
The follow procedures are considered administrative, and as a result users are required to have explicit grants to use them.
dolt_backup
dolt_clone
dolt_fetch
dolt_undrop
dolt_purge_dropped_databases
dolt_gc
dolt_pull
dolt_push
dolt_remote
For example, if a service account requires the ability to start dolt_gc, then it must have specific permissions to do so:
database>GRANTEXECUTEONPROCEDURE mydb.dolt_gc TO service_account@localhost
dolt_push(), dolt_fetch(), and dolt_pull() are considered administrative operations currently because they all use a shared credential to talk to remote servers. User level access to remotes, and the ability to store user level credentials for them is on our roadmap.
The root user, or any other user with super privileges is allowed to select all procedures.