GithubHelp home page GithubHelp logo

Comments (1)

fulghum avatar fulghum commented on June 9, 2024

In the event of a schema conflict like in scenario 1 above that prevents using a rebase workflow, you can still use a merge workflow to update the branch. (Using rebase to try and squash the commits on the dev branch into a single commit that can then be rebased onto the tip of main, will still currently hit a schema conflict.)

1 – Bring the schema into sync with the upstream branch

We can use the dolt_patch() table function to easily find the SQL statements needed to migrate the schema to match main:

-- find the schema differences using dolt_patch()
select statement_order, statement from dolt_patch('branch1', 'main') where diff_type="schema";
+-----------------+-------------------------------+
| statement_order | statement                     |
+-----------------+-------------------------------+
| 1               | ALTER TABLE `t` DROP `c1`;    |
| 2               | ALTER TABLE `t` ADD `c1` int; |
+-----------------+-------------------------------+

-- apply the schema changes
ALTER TABLE `t` DROP `c1`;
ALTER TABLE `t` ADD `c1` int;

-- create a Dolt commit
call dolt_commit('-am', 'updating schemas to match main');

2 – Merge the latest changes from the upstream branch into the dev branch.

-- before merging main to branch1, we can look at the current log for branch1 to see the reachable commits
select * from dolt_log;
+----------------------------------+-----------+-------------------------+---------------------+--------------------------------+
| commit_hash                      | committer | email                   | date                | message                        |
+----------------------------------+-----------+-------------------------+---------------------+--------------------------------+
| 314crgv3oj20o2blsjcin3g50nld258j | root      | root@localhost          | 2024-05-07 23:35:43 | updating schemas to match main |
| jmstip9r3d992h80ik5v95a76d4l7rnc | root      | root@localhost          | 2024-05-07 23:34:48 | inserting row 100 on branch1   |
| 38lpgag8jkbjo7l5gsmnfks4vgjqo6h3 | root      | root@localhost          | 2024-05-07 23:34:48 | adding row 1 on main           |
| df42kstlos2i84c7vujnv6kofrudn332 | root      | root@localhost          | 2024-05-07 23:34:48 | adding table t on main         |
| d0ltbo8su41muhftfg3gm6jr6re19jpt | jfulghum  | jason.fulghum@gmail.com | 2024-05-07 23:29:01 | Initіаlіze datа rеpоsitory     |
+----------------------------------+-----------+-------------------------+---------------------+--------------------------------+

-- merge the main branch into branch1
call dolt_merge('main');
+----------------------------------+--------------+-----------+------------------+
| hash                             | fast_forward | conflicts | message          |
+----------------------------------+--------------+-----------+------------------+
| bjjli2hp9jti0vc9djdkss7gtceenuof | 0            | 0         | merge successful |
+----------------------------------+--------------+-----------+------------------+

-- now examine the commit log for branch1 and we can see new commits from main are now reachable
-- on branch1 (e.g. "adding row 2 on main")
rebaseSchemaConflictResolution/branch1> select * from dolt_log;
+----------------------------------+-----------+-------------------------+---------------------+------------------------------------+
| commit_hash                      | committer | email                   | date                | message                            |
+----------------------------------+-----------+-------------------------+---------------------+------------------------------------+
| bjjli2hp9jti0vc9djdkss7gtceenuof | root      | root@localhost          | 2024-05-07 23:53:07 | Merge branch 'main' into branch1   |
| 314crgv3oj20o2blsjcin3g50nld258j | root      | root@localhost          | 2024-05-07 23:35:43 | updating schemas to match main     |
| jp0kv3re8ltafhef1k0a4g7p66t4gu53 | root      | root@localhost          | 2024-05-07 23:34:48 | dropping and readding t.c1 on main |
| jmstip9r3d992h80ik5v95a76d4l7rnc | root      | root@localhost          | 2024-05-07 23:34:48 | inserting row 100 on branch1       |
| bohjglronlvql4ltdkekloqbrdcp2m21 | root      | root@localhost          | 2024-05-07 23:34:48 | adding row 2 on main               |
| 38lpgag8jkbjo7l5gsmnfks4vgjqo6h3 | root      | root@localhost          | 2024-05-07 23:34:48 | adding row 1 on main               |
| df42kstlos2i84c7vujnv6kofrudn332 | root      | root@localhost          | 2024-05-07 23:34:48 | adding table t on main             |
| d0ltbo8su41muhftfg3gm6jr6re19jpt | jfulghum  | jason.fulghum@gmail.com | 2024-05-07 23:29:01 | Initіаlіze datа rеpоsitory         |
+----------------------------------+-----------+-------------------------+---------------------+------------------------------------+

from dolt.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.