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

Cannot specify specific views to dump #185

Open
bwmarkle opened this issue Jan 7, 2020 · 7 comments
Open

Cannot specify specific views to dump #185

bwmarkle opened this issue Jan 7, 2020 · 7 comments

Comments

@bwmarkle
Copy link
Contributor

bwmarkle commented Jan 7, 2020

Problem

The only way I can dump a view is if I DO NOT pass in an include-tables setting.

This dumps all tables and all views. But if I want to have only a set of tables and a set of views dumped, certain problems arise (as outlined below).

When you don't pass in include-tables...

When you don't pass in include-tables, it causes include-views to be set to an empty array:

// Dump the same views as tables, mimic mysqldump behaviour
$this->dumpSettings['include-views'] = $this->dumpSettings['include-tables'];

And when include-views is empty, the getDatabaseStructureViews method will default to getting all views:

    private function getDatabaseStructureViews()
    {
        // Listing all views from database
        if (empty($this->dumpSettings['include-views'])) {
            // include all views for now, blacklisting happens later
            foreach ($this->dbHandler->query($this->typeAdapter->show_views($this->dbName)) as $row) {
                array_push($this->views, current($row));
            }
        }

If you only want certain tables...

If I only want a certain set of tables and I pass it in as include-tables, the include-views is set to default to that same list

// Dump the same views as tables, mimic mysqldump behaviour
$this->dumpSettings['include-views'] = $this->dumpSettings['include-tables'];

As they're not actually tables, but views, $this->views remains empty after the getDatabaseStructureViews method is ran, and no views are backed up.

... you can pass in include-tables but not include-views

I can't actually pass in include-views because it's not listed in the $dumpSettingsDefault and results in this error:

$diff = array_diff(array_keys($this->dumpSettings), array_keys($dumpSettingsDefault));
if (count($diff) > 0) {
    throw new Exception("Unexpected value in dumpSettings: (".implode(",", $diff).")");
}

... but even if that is fixed, include-views will be overwritten by this declaration:

        // Dump the same views as tables, mimic mysqldump behaviour
        $this->dumpSettings['include-views'] = $this->dumpSettings['include-tables'];

I've spent a lot of time troubleshooting. Hopefully I didn't miss anything and the above makes sense too.

Thanks!
- Brad

bwmarkle added a commit to BoldGrid/mysqldump-php that referenced this issue Jan 9, 2020
@ifsnop ifsnop closed this as completed in 0931ad6 Feb 12, 2020
@ifsnop ifsnop reopened this Feb 12, 2020
@ifsnop
Copy link
Owner

ifsnop commented Feb 12, 2020

I'm not sure if this will fail if you request a view without its parent table. Did you test it?

@ifsnop
Copy link
Owner

ifsnop commented Jul 18, 2020

IMHO if the user mistakenly provides a non-existing view, program should fail. So I will do some tests and merge this ASAP.

@smalos
Copy link
Contributor

smalos commented Aug 16, 2020

I was also trying to export just one view "my_view" but didn't succeed. There are no tables in the output (as expected) but also not my view.

$dumpSettings['include-views'][] = 'my_view';
$dumpSettings['exclude-tables'][] = '/.*?/'; // exlude all tables

@ifsnop
Copy link
Owner

ifsnop commented Aug 16, 2020 via email

@smalos
Copy link
Contributor

smalos commented Aug 17, 2020

Let's take the case when the underlying table(s) of the view already exist in the destination database.
It would make perfect sense if you could just export a "CREATE VIEW" statement from the source db and run that on the destination db to create the same view.
phpMyAdmin also allows you to export just views.

@smalos
Copy link
Contributor

smalos commented Aug 30, 2020

Where does the code prevent that (only) views can be exported? How to remove the limitation?

@hectnandez
Copy link

Related to this.... is possible to exclude all the views?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants