Repository navigation
Conversation
pstaabp
reviewed
Oct 6, 2026
drgrice1
force-pushed
the
archive-to-json
branch
from
October 6, 2026 13:53
85fda8f to
2e97f71
Compare
Instead of using `mysqldump` use a JSON format for database dump files in the course archive. Each table has its own dump file as before. Each line of a table dump file is a valid JSON array, however, the lines of the file are not separated by commas nor contained in a parent array (so not quite valid JSON for the file as a whole). The first line of each table dump file is an array of fields in the table at the time that the archive is created. The second line is an array of the types of those fields in the same order as on the first line. The remaining lines of the file are arrays data stored in the table also in the same order as the first two rows. When unarchiving a table dump file, first the table is created according to the schema of the current release. A prepared statement for a fixed number of rows is created and used to insert batches of rows from the table, and then any extra rows are inserted with a final specially prepared statement. This gives a considerable speed improvement over inserting a single row at a time. If a table's structure has changed from the time the archive was made, then upgrades are made in place. This is detected by considering the first two lines of the file and comparing those to the schema of the current release. The upgrades are handled per table. Each database record can override the `upgrade_data` method to perform custom data upgrades for the table. The default method defined in `WeBWorK::DB::Record` will take care of dropping removed columns or adding new ones, but more complicated data migration (such as moving data from one field to another) will require an override method. Note that the default `upgrade_data` method is not called unless a change is detected, but an override method will always be called. That is another efficiency improvement as that detection is done once for the entire table. These new format database dump files will be in the `dbdump` directory in the course archive tar ball instead of the `mysqldump` directory. Course archive files that are unarchived and have the old `mysqldump` directory will use the old `mysqldump` backwards compatibility methods. Note that those courses will need to be upgraded once the unarchival process is complete as before. The point of this change is to get away from using `mydqldump`, to have a format that can be worked with without an actual database instance, and to have a format that is not tied to a specific type of database (such as mysql).
drgrice1
force-pushed
the
archive-to-json
branch
from
October 6, 2026 18:58
2e97f71 to
c0f8254
Compare
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Instead of using
mysqldumpuse a JSON format for database dump files in the course archive. Each table has its own dump file as before. Each line of a table dump file is a valid JSON array, however, the lines of the file are not separated by commas nor contained in a parent array (so not quite valid JSON for the file as a whole). The first line of each table dump file is an array of fields in the table at the time that the archive is created. The second line is an array of the types of those fields in the same order as on the first line. The remaining lines of the file are arrays data stored in the table also in the same order as the first two rows.When unarchiving a table dump file, first the table is created according to the schema of the current release.
A prepared statement for a fixed number of rows is created and used to insert batches of rows from the table, and then any extra rows are inserted with a final specially prepared statement. This gives a considerable speed improvement over inserting a single row at a time.
If a table's structure has changed from the time the archive was made, then upgrades are made in place. This is detected by considering the first two lines of the file and comparing those to the schema of the current release. The upgrades are handled per table. Each database record can override the
upgrade_datamethod to perform custom data upgrades for the table. The default method defined inWeBWorK::DB::Recordwill take care of dropping removed columns or adding new ones, but more complicated data migration (such as moving data from one field to another) will require an override method. Note that the defaultupgrade_datamethod is not called unless a change is detected, but an override method will always be called. That is another efficiency improvement as that detection is done once for the entire table.These new format database dump files will be in the
dbdumpdirectory in the course archive tar ball instead of themysqldumpdirectory. Course archive files that are unarchived and have the oldmysqldumpdirectory will use the oldmysqldumpbackwards compatibility methods. Note that those courses will need to be upgraded once the unarchival process is complete as before.The point of this change is to get away from using
mydqldump, to have a format that can be worked with without an actual database instance, and to have a format that is not tied to a specific type of database (such as mysql).