Skip to content

jdatabase importer exporter#23320

Closed
twister65 wants to merge 42 commits intojoomla:stagingfrom
twister65:pgsql_transfer
Closed

jdatabase importer exporter#23320
twister65 wants to merge 42 commits intojoomla:stagingfrom
twister65:pgsql_transfer

Conversation

@twister65
Copy link
Contributor

@twister65 twister65 commented Dec 22, 2018

Retrieving PR #14272 (and #10991) to fix the PostgreSQL exporter and importer bugs.
This PR can be tested with any database driver supported by Joomla.
This is about exporting and importing any database with a command-line interface (it can be placed in cronjob to schedule the database backup).

Summary of Changes

  • Fix folder path.
  • Fix postgresql issues :
    • Fix the default value of the table.
    • Gets, sets the last_value and is_called sequence attributes.
    • Fix key query.
    • Fix text default value.
    • Apply changes to unit tests.
    • Fix the execution of queries (xmlToCreate) with the pgsql (PDO) driver.
    • Add unique constraints.
    • Convert PostgreSQL BLOB data (bytea).

Testing Instructions

  • Select a database driver and save it in System -> Global Configuration -> Server ->Database Type
  • Go to the cli folder of your website.
  • Export all tables and data to the folder :
    php exporter.php --all --folder <folder_path>
  • Delete and create an empty database with the same name.
  • Overwriting the database can also be done. Verify that changes are applied.
  • Import all from folder:
    php importer.php --all --folder <folder_path>

You can also :

  • Export all tables and data in zip file :
    php exporter.php --all --mode zip
  • Export a table :
    php exporter.php --table <table_name>
  • Export a table as a .zip file :
    php exporter.php --table <table_name> --mode zip
  • Import a table :
    php importer.php --table <table_name>

Expected result

Export/import tables with structure (keys, constraints, sequences) and data.

Actual result

Does not export/import views, stored procedures and triggers (optional for the Joomla database).

@twister65 twister65 changed the title Fix PostgreSQL exporter / importer [jdatabase] - importer exporter (PostgreSQL fix) Dec 23, 2018
@twister65
Copy link
Contributor Author

PostgreSQL automatically creates a unique index when a unique constraint or primary key is defined for a table. We need to modify table by adding a unique constraint on a column, instead of creating a unique index.
This query creates unique index:

return (string) $field['Query'];

Here, a unique constraint is defined for a table:
return 'ALTER TABLE ' . $this->db->quoteName($table) . ' ADD ' . $this->getKeySql($keys);

SharkyKZ and others added 3 commits February 27, 2019 20:03
Co-Authored-By: twister65 <olaverre@free.fr>
table_structure name
foreach ($this->from as $table)
{
// Replace the magic prefix if found.
$table = $this->getGenericTableName($table);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to be restored. The tables should be exported with magic prefix, I think. At least MySQLi does it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Completed. Do you also want a magic prefix for the sequence name and key index?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See lines:

<sequence Name="jos_dbtest_id_seq" Schema="public" Table="jos_dbtest" Column="id" Type="bigint" Start_Value="' .

and
<key Index="jos_dbtest_pkey" is_primary="TRUE" is_unique="TRUE" Key_name="id" Query=\'ALTER TABLE "jos_dbtest" ADD PRIMARY KEY (id)\' />

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think so. To my understanding, exported XML files should not contain real DB prefix. It should be replaced when importing. Maybe @alikon knows more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. However, the key query can't contain the magic prefix.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To my understanding, exported XML files should not contain real DB prefix. It should be replaced when importing.

correct

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In that case more changes are needed because Query and Default attributes contain it, e.g.:

<field Field="id" Type="integer" Null="NO" Default="nextval('pg39_action_logs_id_seq'::regclass)" Comments="" />

and

<key Index="#__action_logs_idx_user_id_extension" is_primary="f" is_unique="f" Key_name="user_id, extension" Query='CREATE INDEX pg39_action_logs_idx_user_id_extension ON pg39_action_logs USING btree (user_id, extension)' />

@alikon
Copy link
Contributor

alikon commented Mar 11, 2019

not so sure if this work can really have a chance to be merged on 3.X branch, i will hope so
i would like to hear some words from @joomla/maintainers

@ghost ghost added J3 Issue and removed J3 Issue labels Apr 5, 2019
@ghost ghost changed the title [jdatabase] - importer exporter (#14272 recovery) [jdatabase] - importer exporter Apr 19, 2019
@ghost ghost changed the title [jdatabase] - importer exporter jdatabase importer exporter Apr 19, 2019
@ghost ghost removed the J3 Issue label Apr 19, 2019
@ghost
Copy link

ghost commented Apr 24, 2019

@HLeithner comment on above Question by @alikon please?

@HLeithner
Copy link
Member

I'm sorry but this is a new feature and has to go into j4

@ghost ghost added the J4 Rebase label Apr 25, 2019
@ghost
Copy link

ghost commented Apr 25, 2019

@twister65 can you rebase this PR on J4?

@twister65
Copy link
Contributor Author

Yes, I can rebase this PR in the Joomla Framework Database Package:
https://github.com/joomla-framework/database

twister65 added a commit to twister65/joomla-cms that referenced this pull request Apr 25, 2019
@ghost
Copy link

ghost commented Apr 27, 2019

Closed as rebased on J4.

@ghost ghost closed this Apr 27, 2019
@ghost ghost removed the J4 Rebase label Apr 27, 2019
roland-d pushed a commit that referenced this pull request May 23, 2019
* Database exporter importer

Rebase PR #23320

* Classname

* Add Database Console Application

* Register Export and Import Commands

* Add commands paths

* Use Joomla Console

php cli/joomla.php

* Database Joomla/Console Application

To import in a new database

* Remove DatabaseConsole

* Sort in alpha order.
@twister65 twister65 deleted the pgsql_transfer branch July 28, 2019 13:52
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants