If you have a already installed PostGreSQL based Drupal site without prefixes, export the database to a SQL dump with INSERTs and execute prefix.sh on it, not all table names are prefixed correctly.

First of all this is due to the fact that PostGreSQL exports some specific table names with quotes since the words are reserved, f.e. "roles". prefix.sh currently converts them to myprefix_"roles".

Also, PostGreSQL dumps use the SQL statement "ALTER TABLE ONLY <db_table>" instead of "ALTER TABLE <db_table>" to build constraints which currently leads to "ALTER TABLE myprefix_ONLY <db_table>". These statements actually only apply to PostGreSQL dumps, so it should be OK to add "ONLY" to prefix.sh in CVS.

Furthermore, PostGreSQL dumps include SQL statements to build database sequences. These do not affect other databases, but should be converted by prefix.sh, too.

I'm attaching a patch to prefix.sh which solves all stated problems here. For the first topic of my list it made sense to me to change the invokation of prefix.sh from

prefix.sh prefix dumpfile > outfile

into

prefix.sh prefix dumpfile outfile

This is because the wrong table names (i.e. like myprefix_"roles") can only be searched & replaced when the prefix replacement already took place.

Comments

Cvbge’s picture

Title: prefix.sh not completely converting postgresql export dumps » make prefix.sh convert postgresql export dumps
Category: bug » feature

Hi,

prefix.sh is intended to work with schema files provided by drupal, not with sql dumps. It should also work with both mysql and postgres database schemes...

I think it is impossibile to do it easily/cleanly, probably it'd be better to write separate script just for that [or just use schemas...]

sun’s picture

StatusFileSize
new1.72 KB

Added deletion of COMMENT, REVOKE and GRANT statements, which are included in PostGreSQL dumps. Import of dumps with these statements may fail since the actual importing database user does not have the required permissions for altering the database description or permissions. New patch attached.

@Cvbge: My extensions to prefix.sh do not affect the functionality to work with schema files provided by drupal. They do not contain any of the added statements. In addition, MySQL dumps do not contain these statements. So it should be safe to patch prefix.sh for HEAD.

sammys’s picture

Version: x.y.z » 4.7.3

prefix.sh has been removed from the repository. I'm not sure if it means the script won't exist in 4.8+. I've modified the version to reflect this change. We'll patch 4.7 once this is tested. I'll review it as soon as I can.

--
Sammy Spets
Synerger
http://www.synerger.com

sammys’s picture

Status: Needs review » Needs work

This patch no longer applies to 4.7 branch. Please update.

magico’s picture

Version: 4.7.3 » 4.7.x-dev

I don't think this will enter the 4.7.x-dev branch...
Anyway reroll a patch for the most recent file version

smk-ka’s picture

Status: Needs work » Needs review
StatusFileSize
new1.62 KB

Updated patch against 4.7.x-dev. Please test.

--
Stefan Kudwien
www.unleashedmind.com

Jaza’s picture

Category: feature » bug
Status: Needs review » Needs work

Take out the syntax change (i.e. changing file1 > file2 to file1 file2), and this is a bug fix, not a feature request. This should still be able to get into the 4.7 branch.

sun’s picture

Status: Needs work » Needs review
StatusFileSize
new1.65 KB

Identical patch without third argument attached.

sun’s picture

Version: 4.7.x-dev » 6.x-dev
Category: bug » task
Status: Needs review » Reviewed & tested by the community

prefix.sh no more exists. However, this modified version is still very useful for anyone in the need to convert table prefixes of an exported database in front of an import. Where could it be stored / committed?

gábor hojtsy’s picture

Status: Reviewed & tested by the community » Closed (won't fix)

Contribs/tricks could possibly be a place to host this. I am won't fixing this, because it should not take our attention in the D6 RTBC queue.