From 91eb34756ec3eef7c0def2ade0e586b02789ea39 Mon Sep 17 00:00:00 2001 From: saper Date: Fri, 13 Apr 2012 20:55:14 +0200 Subject: [PATCH] Fix broken merge by 0a792a1dcba26dd70d64e307b301c6 Changeset 1 of https://gerrit.wikimedia.org/r/#change,3365: 763b57f9f2af131a2d8e65f520a23c00109be0e1 got mis-merged in changeset 2: f752cf80423615b380cf5612a3f1f68a6b9d0173 And introduced into master wth 0a792a1dcba26dd70d64e307b301c6773279cfc9 Also, marking all new functions as @since 1.19 since we want to have them there later. Patchset 2: whitespace fixes Patchset 3: Fix deferrable = ( $row->deferrable == 't' ); $n->deferred = ( $row->deferred == 't' ); $n->conname = $row->conname; + $n->has_default = ( $row->atthasdef === 't' ); + $n->default = $row->adsrc; return $n; } @@ -94,6 +98,16 @@ SQL; function conname() { return $this->conname; } + /** + * @since 1.19 + */ + function defaultValue() { + if( $this->has_default ) { + return $this->default; + } else { + return false; + } + } } @@ -101,7 +115,7 @@ SQL; * Used to debug transaction processing * Only used if $wgDebugDBTransactions is true * - * @since 1.20 + * @since 1.19 * @ingroup Database */ class PostgresTransactionState { @@ -317,7 +331,6 @@ class DatabasePostgres extends DatabaseBase { } protected function doQuery( $sql ) { - global $wgDebugDBTransactions; if ( function_exists( 'mb_convert_encoding' ) ) { $sql = mb_convert_encoding( $sql, 'UTF-8' ); } @@ -526,6 +539,68 @@ class DatabasePostgres extends DatabaseBase { return false; } + /** + * Returns is of attributes used in index + * + * @since 1.19 + * @return Array + */ + function indexAttributes ( $index, $schema = false ) { + if ( $schema === false ) + $schema = $this->getCoreSchema(); + /* + * A subquery would be not needed if we didn't care about the order + * of attributes, but we do + */ + $sql = <<<__INDEXATTR__ + + SELECT opcname, + attname, + i.indoption[s.g] as option, + pg_am.amname + FROM + (SELECT generate_subscripts(isub.indkey, 1) AS g + FROM + pg_index isub + JOIN pg_class cis + ON cis.oid=isub.indexrelid + JOIN pg_namespace ns + ON cis.relnamespace = ns.oid + WHERE cis.relname='$index' AND ns.nspname='$schema') AS s, + pg_attribute, + pg_opclass opcls, + pg_am, + pg_class ci + JOIN pg_index i + ON ci.oid=i.indexrelid + JOIN pg_class ct + ON ct.oid = i.indrelid + JOIN pg_namespace n + ON ci.relnamespace = n.oid + WHERE + ci.relname='$index' AND n.nspname='$schema' + AND attrelid = ct.oid + AND i.indkey[s.g] = attnum + AND i.indclass[s.g] = opcls.oid + AND pg_am.oid = opcls.opcmethod +__INDEXATTR__; + $res = $this->query($sql, __METHOD__); + $a = array(); + if ( $res ) { + foreach ( $res as $row ) { + $a[] = array( + $row->attname, + $row->opcname, + $row->amname, + $row->option); + } + } else { + return null; + } + return $a; + } + + function indexUnique( $table, $index, $fname = 'DatabasePostgres::indexUnique' ) { $sql = "SELECT indexname FROM pg_indexes WHERE tablename='{$table}'". " AND indexdef LIKE 'CREATE UNIQUE%(" . @@ -750,14 +825,19 @@ class DatabasePostgres extends DatabaseBase { # Replace reserved words with better ones switch( $name ) { case 'user': - return 'mwuser'; + return $this->realTableName( 'mwuser', $format ); case 'text': - return 'pagecontent'; + return $this->realTableName( 'pagecontent', $format ); default: - return parent::tableName( $name, $format ); + return $this->realTableName( $name, $format ); } } + /* Don't cheat on installer */ + function realTableName( $name, $format = 'quoted' ) { + return parent::tableName( $name, $format ); + } + /** * Return the next in a sequence, save the value for retrieval via insertId() * @return null @@ -844,7 +924,7 @@ class DatabasePostgres extends DatabaseBase { * * This should really be handled by PHP PostgreSQL module * - * @since 1.20 + * @since 1.19 * @param $text string: postgreql array returned in a text form like {a,b} * @param $output string * @param $limit int @@ -896,7 +976,7 @@ class DatabasePostgres extends DatabaseBase { * Return current schema (executes SELECT current_schema()) * Needs transaction * - * @since 1.20 + * @since 1.19 * @return string return default schema for the current session */ function getCurrentSchema() { @@ -912,7 +992,7 @@ class DatabasePostgres extends DatabaseBase { * * @seealso getSearchPath() * @seealso setSearchPath() - * @since 1.20 + * @since 1.19 * @return array list of actual schemas for the current sesson */ function getSchemas() { @@ -929,7 +1009,7 @@ class DatabasePostgres extends DatabaseBase { * (like "$user"). * Needs transaction * - * @since 1.20 + * @since 1.19 * @return array how to search for table names schemas for the current user */ function getSearchPath() { @@ -942,7 +1022,7 @@ class DatabasePostgres extends DatabaseBase { /** * Update search_path, values should already be sanitized * Values may contain magic keywords like "$user" - * @since 1.20 + * @since 1.19 * * @param $search_path array list of schemas to be searched by default */ @@ -960,7 +1040,7 @@ class DatabasePostgres extends DatabaseBase { * * This will be also called by the installer after the schema is created * - * @since 1.20 + * @since 1.19 * @param desired_schema string */ function determineCoreSchema( $desired_schema ) { @@ -993,7 +1073,7 @@ class DatabasePostgres extends DatabaseBase { /** * Return schema name fore core MediaWiki tables * - * @since 1.20 + * @since 1.19 * @return string core schema name */ function getCoreSchema() { @@ -1032,7 +1112,7 @@ class DatabasePostgres extends DatabaseBase { if ( !$schema ) { $schema = $this->getCoreSchema(); } - $table = $this->tableName( $table, 'raw' ); + $table = $this->realTableName( $table, 'raw' ); $etable = $this->addQuotes( $table ); $eschema = $this->addQuotes( $schema ); $SQL = "SELECT 1 FROM pg_catalog.pg_class c, pg_catalog.pg_namespace n " diff --git a/includes/installer/PostgresUpdater.php b/includes/installer/PostgresUpdater.php index 1bb3b9bfb0..0d27c5a1ab 100644 --- a/includes/installer/PostgresUpdater.php +++ b/includes/installer/PostgresUpdater.php @@ -35,10 +35,6 @@ class PostgresUpdater extends DatabaseUpdater { array( 'renameIndex', 'mwuser', 'user_user_name_key', 'mwuser_user_name_key' ), array( 'renameIndex', 'pagecontent','text_pkey', 'pagecontent_pkey' ), - # new sequences - array( 'addSequence', 'logging_log_id_seq' ), - array( 'addSequence', 'page_restrictions_pr_id_seq' ), - # renamed sequences array( 'renameSequence', 'ipblocks_ipb_id_val', 'ipblocks_ipb_id_seq' ), array( 'renameSequence', 'rev_rev_id_val', 'revision_rev_id_seq' ), @@ -79,7 +75,7 @@ class PostgresUpdater extends DatabaseUpdater { array( 'addTable', 'uploadstash', 'patch-uploadstash.sql' ), array( 'addTable', 'user_former_groups','patch-user_former_groups.sql' ), array( 'addTable', 'config', 'patch-config.sql' ), - array( 'addTable', 'external_user','patch-external_user.sql' ), + array( 'addTable', 'external_user', 'patch-external_user.sql' ), # Needed before new field array( 'convertArchive2' ), @@ -152,7 +148,7 @@ class PostgresUpdater extends DatabaseUpdater { array( 'changeField', 'image', 'img_size', 'integer', '' ), array( 'changeField', 'image', 'img_width', 'integer', '' ), array( 'changeField', 'image', 'img_height', 'integer', '' ), - array( 'changeField', 'interwiki', 'iw_local', 'smallint', 'iw_local::smallint DEFAULT 0' ), + array( 'changeField', 'interwiki', 'iw_local', 'smallint', 'iw_local::smallint' ), array( 'changeField', 'interwiki', 'iw_trans', 'smallint', 'iw_trans::smallint DEFAULT 0' ), array( 'changeField', 'ipblocks', 'ipb_auto', 'smallint', 'ipb_auto::smallint DEFAULT 0' ), array( 'changeField', 'ipblocks', 'ipb_anon_only', 'smallint', "CASE WHEN ipb_anon_only=' ' THEN 0 ELSE ipb_anon_only::smallint END DEFAULT 0" ), diff --git a/maintenance/postgres/archives/patch-external_user.sql b/maintenance/postgres/archives/patch-external_user.sql index 242e4fafa4..6058a70617 100644 --- a/maintenance/postgres/archives/patch-external_user.sql +++ b/maintenance/postgres/archives/patch-external_user.sql @@ -4,11 +4,3 @@ CREATE TABLE external_user ( ); CREATE UNIQUE INDEX eu_external_id ON external_user (eu_external_id); - -CREATE TABLE external_user ( - eu_local_id INTEGER NOT NULL PRIMARY KEY, - eu_external_id TEXT -); - -CREATE UNIQUE INDEX eu_external_id ON external_user (eu_external_id); - -- 2.20.1