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

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

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
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.

1 participant