I am working on automated test with SemanticMediaWiki, I encountered "CREATE TABLE" error on duplication of table name. The immediate code in
https://github.com/wikimedia/mediawiki/blob/master/includes/db/CloneDatabase.php#L91-L102
Why?
I am working on automated test with SemanticMediaWiki, I encountered "CREATE TABLE" error on duplication of table name. The immediate code in
https://github.com/wikimedia/mediawiki/blob/master/includes/db/CloneDatabase.php#L91-L102
Why?
Subject | Repo | Branch | Lines +/- | |
---|---|---|---|---|
Remove exception and drop cloned tables in PostgresSQL too | mediawiki/core | master | +3 -1 |
Hi @Yoonghm, thanks for taking the time to report this!
(For future reference, a more useful and complete description is welcome).
Do 91307ea896bcc29019b0382d253d2c6ea35a00f3 and 5933586266e5530d491cf0e518abfe0ed56e1c0a answer your question?
Hi @Aklapper,
I am not sure besides Semantic MediaWiki, which extension needs to use cloneTableStructure(). I performed automated tests, the process stopped due to
Error: 42P07 ERROR: relation "sunittest_smw_di_coords" already exists
I believe the error was caused by running multiple automated test jobs in one session.
From http://www.postgresql.org/docs/9.2/static/sql-createtable.html#AEN70273
Temporary tables are automatically dropped at the end of a session, or optionally at the end of the current transaction (see ON COMMIT below). Existing permanent tables with the same name are not visible to the current session while the temporary table exists, unless they are referenced with schema-qualified names. Any indexes created on a temporary table are automatically temporary as well.
In other words,
So the code should be fixed (at least with postgres):
/** * Clone the table structure */ public function cloneTableStructure() { global $wgSharedTables, $wgSharedDB; foreach ( $this->tablesToClone as $tbl ) { if ( $wgSharedDB && in_array( $tbl, $wgSharedTables, true ) ) { // Shared tables don't work properly when cloning due to // how prefixes are handled (bug 65654) throw new MWException( "Cannot clone shared table $tbl." ); } # Clean up from previous aborted run. So that table escaping # works correctly across DB engines, we need to change the pre- # fix back and forth so tableName() works right. self::changePrefix( $this->oldTablePrefix ); $oldTableName = $this->db->tableName( $tbl, 'raw' ); self::changePrefix( $this->newTablePrefix ); $newTableName = $this->db->tableName( $tbl, 'raw' ); if ( $this->dropCurrentTables && !in_array( $this->db->getType(), array( 'oracle' ) ) ) { if ( $oldTableName === $newTableName ) { // Last ditch check to avoid data loss throw new MWException( "Not dropping new table, as '$newTableName'" . " is name of both the old and the new table." ); } $this->db->dropTable( $tbl, __METHOD__ ); wfDebug( __METHOD__ . " dropping {$newTableName}\n" ); //Dropping the oldTable because the prefix was changed } # Create new table wfDebug( __METHOD__ . " duplicating $oldTableName to $newTableName\n" ); $this->db->duplicateTableStructure( $oldTableName, $newTableName, $this->useTemporaryTables ); } }
Ah, thanks for taking a look!
You are very welcome to use developer access to submit this as a Git branch directly into Gerrit.
If you don't want to set up Git/Gerrit, you can also use the Gerrit Patch Uploader. Thanks again!
Hi @Akalapper:
I have submitted the fix in https://gerrit.wikimedia.org/r/#/c/241489/
@Yoonghm: Awesome! Could you update your commit message as per https://www.mediawiki.org/wiki/Gerrit/Commit_message_guidelines to summarize the change in the first line, plus link to this very Phabricator task? (You can edit direct in the web browser interface of Gerrit.)
Change 241489 had a related patch set uploaded (by Nemo bis; owner: Yoonghm):
[mediawiki/core@master] Remove exception and drop cloned tables in PostgresSQL too
Change 241489 merged by jenkins-bot:
[mediawiki/core@master] Remove exception and drop cloned tables in PostgresSQL too