-
Notifications
You must be signed in to change notification settings - Fork 65
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
Issue #302: Sequenced sql files #354
Issue #302: Sequenced sql files #354
Conversation
Additionally, I should point out that you should not merge #351 if you choose to merge this. #351 has a lot of changes to the However, I did move the |
@queryluke This works really well. I've tested both an upgrade from a 2.0.1 database as well as a fresh install. One thing it doesn't address, and a bunch of us discussed it once before, though I'm not sure you were involved in this project yet, was an idea of a database or schema version that is independent of the code version. I don't know if this PR is the best place to be bringing up this issue, but we can continue the discussion elsewhere if needed. Where this idea becomes relevant is during development between releases when we don't want to lose database content. For example, if I am testing a PR that has a schema change (a new In my ideal world we would be able to run a database update script that would be based on a schema version that indicates which SQL updates have already been applied. That way, any database content that has been added to tables that were already updated in previous schema update does not have to be lost when reverting the entire schema to the previous code version. I do understand that we can manually run the SQL files as needed, but I do think an independent schema version could make the developer experience easier. |
@t4k @jcuenod Have you ever worked with database migrations? Not sure which language started it, but my first experience with them was in Rails. The Laravel framework (in PHP) also uses them. I'm pretty partial to Laravel's setup, which I'll outline, but if it's not clear, feel free to read the docs I've linked. Each DB change is it's own script stored in a file named When you proc the migrations to start, with a command line or other script (like the installer), it queries the database and then runs all migrations that have yet to be added. Once a migration is added, it stores the name of the migration file in the database as well, so it won't be run again. It also applies an incremental number to the group of migrations that were run. The beauty is that you can then run a 'rollback' command which finds the latest group number and runs the 'down' function for each script within that group, then removes them from the database. Using this setup also makes working with different branches a cinch. Checkout branch A, The only downside, (extremely minor, IMHO), is that this takes slightly more developer time because they need to write a reverse of all db changes they make. |
I should also say that Laravel's migration structure uses a lot of other Laravel classes. This code base couldn't easily plug it in. But the workflow might be accomplished by putting SQL code in the up/down functions of the migration file. |
I seem to remember the discussion about rollbacks but maybe I had it with @jeffnm in person. I think it's probably not a good idea because of the extra work it requires from whoever is building the sql files. I haven't used laravel but with Rails, the migrations are being constructed using black(box) magic so it just doesn't require the same kind of work from people building updates. I speak as a non-module developer though so I am quite open to correction on this. |
I'm happy to table this discussion for later or move it back to #285. Sorry about the confusion. The functionality in this PR works great and as expected for me! |
This seems to be working. I'd like to go ahead and merge it if there are no objections. |
Information
Fixes #302. db_tools.php script now uses information about the installation/upgrade version to process any sql files that are > the current version and <= the target version.
Example 1: Moving from 2.1.0 => 2.4.0, the db_tools script would sequentially process any files within:
$MODULE_NAME/install/protected/2.2.0/*.sql
$MODULE_NAME/install/protected/2.3.0/*.sql
$MODULE_NAME/install/protected/2.4.0/*.sql
Example 2: On a fresh install, it will process all version files. If Coral was up to 2.4, the install script would run the following files:
$MODULE_NAME/install/protected/test_create.sql
$MODULE_NAME/install/protected/install.sql
$MODULE_NAME/install/protected/2.0.0/*.sql
$MODULE_NAME/install/protected/2.1.0/*.sql
$MODULE_NAME/install/protected/2.2.0/*.sql
$MODULE_NAME/install/protected/2.3.0/*.sql
$MODULE_NAME/install/protected/2.4.0/*.sql
Workflow Moving Forward
(Based on information from #302)
$MODULE_NAME/install/protected/$VERSION/
, with a sequence number and issue number$SEQ_NUM-$ISS_NUM
install.sql
files anymore. Those represents a < 2.0 installation. All other updates should be processed sequentially in there own files.Testing
Test an upgrade
your.coral.url/
$MODULE_NAME/install/protected/2.1.0
Test a fresh install
$MODULE_NAME/install/protected/2.1.0