mysqldump-php
mysqldump-php copied to clipboard
Cannot specify specific views to dump
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
I'm not sure if this will fail if you request a view without its parent table. Did you test it?
IMHO if the user mistakenly provides a non-existing view, program should fail. So I will do some tests and merge this ASAP.
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
I think it's not possible to dump a view without its table, there would be no data neither structure.
El dom., 16 ago. 2020 16:56, smalos [email protected] escribió:
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
— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub https://github.com/ifsnop/mysqldump-php/issues/185#issuecomment-674536618, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAHMH2B4OIHW4FECQH2FIX3SA7XRXANCNFSM4KD5KMSA .
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.
Where does the code prevent that (only) views can be exported? How to remove the limitation?
Related to this.... is possible to exclude all the views?