Skip to content

Comments

Improve view support for pscale database dump / restore-dump#932

Merged
iheanyi merged 4 commits intomainfrom
improve-view-support
Nov 4, 2024
Merged

Improve view support for pscale database dump / restore-dump#932
iheanyi merged 4 commits intomainfrom
improve-view-support

Conversation

@orware
Copy link
Contributor

@orware orware commented Oct 25, 2024

This should address the problem described in the following two issues:
#921
#701

And adds support for exporting views with the -schema-view.sql suffix, avoids running the view queries and exporting data from them unnecessarily, and allows for restoring / overwriting the views when the --overwrite-tables flag is passed in.

The goal was to implement the desired functionality with minimal changes to the existing files but the new information_schema query that was added in dumper.go did lead to some required additions in the dumper_test.go file.

As I also have PR#910 open at the moment that includes other modifications to dumper.go and loader.go this one may be simpler to review / approve first and then I can update the other pull request afterward.

Currently, `dumper.go` is able to export view definitions without issue, but it unfortunately also runs the view and includes, or attempts to include, the data associated with the view too which is unnecessary.

The changes here add support for collecting the list of views so that processing can be slightly adjusted if a "table" is actually a view.

In that situation, the same `-schema-view.sql` file suffix is utilized that the MyDumper project uses for views and the step that unnecessarily runs the view query is skipped to avoid that issue.
The changes made to `loader.go` add support for collecting any files ending in the view suffix, `-schema-view.sql`, and processing them slightly differently than in `restoreTableSchema()`.

The main change within the new `restoreViews()` method, aside from some variable name adjustments and the use of the `viewSuffix`, is the change to using `DROP VIEW` during the overwrite step to properly allow for deleting the existing views.

Additionally, the creation of the views is set to occur after the creation of the tables to help avoid that dependency issue.
Some additional cases for the new `information_schema` query needed to be accounted for in the tests.
@orware orware requested a review from a team as a code owner October 25, 2024 18:11
@iheanyi iheanyi merged commit a9c9e81 into main Nov 4, 2024
@iheanyi iheanyi deleted the improve-view-support branch November 4, 2024 18:01
orware added a commit that referenced this pull request Nov 4, 2024
Now that #932 was merged in a little earlier I was able to incorporate some extra show details output specific for views into this PR now.

The current `canRestoreSchema()` has also been wrapped around the portion of code that restores the view definitions. In the future we may want to differentiate between restoring tables vs. views only but for now they are both considered to be part of the schema so I'm using the same check for both at the moment which should work ok for now.
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