Skip to content
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

Implement CSV output mode #92

Merged
merged 6 commits into from
Sep 16, 2022
Merged

Implement CSV output mode #92

merged 6 commits into from
Sep 16, 2022

Conversation

FabianSchmick
Copy link
Member

@FabianSchmick FabianSchmick commented Sep 1, 2022

This PR implements a new output mode for CSV files.

The new command option --output-csv=... enables CSV output mode, and must be given the path to a directory. The output mode will create .csv files in the given directory, named according to the dumped tables.

This output format does not support output redirection from stdout as the default MySQL SQL format does.

CSV files will be created only for tables that contain data. In other words, schema type dumps will skip the table in question. Also, dumping views/triggers makes no sense for CSV files, they will be skipped as well.

How to best write binary (BLOB) data and/or NULL values in CSV files is probably highly controversial. For now, we'll just go with the 0x... hex literals supported by MySQL. Maybe having binary data in CSV files is not a sane idea in the first place.

Co-authored-by: Matthias Pigulla mp@webfactory.de

@mpdude mpdude changed the base branch from master to refactor-dumper-simple September 2, 2022 09:57
@mpdude mpdude changed the title Implement a CsvOutputFormatDriver (wip) Implement CSV output mode Sep 2, 2022
Base automatically changed from refactor-dumper-simple to master September 2, 2022 12:18
@mpdude mpdude marked this pull request as ready for review September 2, 2022 12:29
@mpdude mpdude merged commit 6d6bab7 into master Sep 16, 2022
@mpdude mpdude deleted the 145919_csv_dumper branch September 16, 2022 10:05
mpdude added a commit that referenced this pull request Dec 21, 2022
When the new CSV output mode with the concept of "output drivers" was added in #92, dumping `TRIGGER` definitions was made an implementation detail of the MySQL output driver. This caused `TRIGGER` definitions to be dumped right after the `CREATE TABLE ...` commands, before the actual data `INSERT` statements.

This potentially breaks the generated SQL files, since a newly created trigger may be relevant for the subsequent `INSERT` statements; however, MySQL requires that tables used in the trigger are also included in the `LOCK TABLES` statements.

The aim of this PR is to revert that change, i. e. to dump trigger definitions for a table _after_ the data insert statements for it.

I think it is not necessary to move all trigger definitions to the very end of the output – that is, after _all_ tables have been created and filled with data: A trigger depends on insert/update/deletes for a particular table and is executed only on these events. So, it is not a problem if a trigger refers to a table that has not been created/loaded yet as long as the trigger is not run (and avoiding to run it is the aim of this PR).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants