X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Finstaller%2FPostgresUpdater.php;h=ff9e2717cc99bf9439d875226e68e59164c246a8;hb=3f92a5672e7dbc3bfee16dd90a0c8c8e881c4b7d;hp=9ad91b78a0ab4691d61d47771dc050163abdea35;hpb=22aeca2dfeb7efd3f15036cbb869d6e0b90bc3d8;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/installer/PostgresUpdater.php b/includes/installer/PostgresUpdater.php index 9ad91b78a0..ff9e2717cc 100644 --- a/includes/installer/PostgresUpdater.php +++ b/includes/installer/PostgresUpdater.php @@ -89,8 +89,8 @@ class PostgresUpdater extends DatabaseUpdater { array( 'addTable', 'module_deps', 'patch-module_deps.sql' ), 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', 'sites', 'patch-sites.sql' ), # Needed before new field array( 'convertArchive2' ), @@ -116,6 +116,7 @@ class PostgresUpdater extends DatabaseUpdater { array( 'addPgField', 'ipblocks', 'ipb_enable_autoblock', 'SMALLINT NOT NULL DEFAULT 1' ), array( 'addPgField', 'ipblocks', 'ipb_parent_block_id', 'INTEGER DEFAULT NULL REFERENCES ipblocks(ipb_id) ON DELETE SET NULL DEFERRABLE INITIALLY DEFERRED' ), array( 'addPgField', 'filearchive', 'fa_deleted', 'SMALLINT NOT NULL DEFAULT 0' ), + array( 'addPgField', 'filearchive', 'fa_sha1', "TEXT NOT NULL DEFAULT ''" ), array( 'addPgField', 'logging', 'log_deleted', 'SMALLINT NOT NULL DEFAULT 0' ), array( 'addPgField', 'logging', 'log_id', "INTEGER NOT NULL PRIMARY KEY DEFAULT nextval('logging_log_id_seq')" ), array( 'addPgField', 'logging', 'log_params', 'TEXT' ), @@ -154,6 +155,11 @@ class PostgresUpdater extends DatabaseUpdater { array( 'addPgField', 'archive', 'ar_sha1', "TEXT NOT NULL DEFAULT ''" ), array( 'addPgField', 'uploadstash', 'us_chunk_inx', "INTEGER NULL" ), array( 'addPgField', 'job', 'job_timestamp', "TIMESTAMPTZ" ), + array( 'addPgField', 'job', 'job_random', "INTEGER NOT NULL DEFAULT 0" ), + array( 'addPgField', 'job', 'job_attempts', "INTEGER NOT NULL DEFAULT 0" ), + array( 'addPgField', 'job', 'job_token', "TEXT NOT NULL DEFAULT ''" ), + array( 'addPgField', 'job', 'job_token_timestamp', "TIMESTAMPTZ" ), + array( 'addPgField', 'job', 'job_sha1', "TEXT NOT NULL DEFAULT ''" ), # type changes array( 'changeField', 'archive', 'ar_deleted', 'smallint', '' ), @@ -227,64 +233,68 @@ class PostgresUpdater extends DatabaseUpdater { array( 'addPgIndex', 'logging', 'logging_page_id_time', '(log_page,log_timestamp)' ), array( 'addPgIndex', 'iwlinks', 'iwl_prefix_title_from', '(iwl_prefix, iwl_title, iwl_from)' ), array( 'addPgIndex', 'job', 'job_timestamp_idx', '(job_timestamp)' ), + array( 'addPgIndex', 'job', 'job_sha1', '(job_sha1)' ), + array( 'addPgIndex', 'job', 'job_cmd_token', '(job_cmd, job_token, job_random)' ), + array( 'addPgIndex', 'job', 'job_cmd_token_id', '(job_cmd, job_token, job_id)' ), + array( 'addPgIndex', 'filearchive', 'fa_sha1', '(fa_sha1)' ), array( 'checkIndex', 'pagelink_unique', array( - array('pl_from', 'int4_ops', 'btree', 0), - array('pl_namespace', 'int2_ops', 'btree', 0), - array('pl_title', 'text_ops', 'btree', 0), + array( 'pl_from', 'int4_ops', 'btree', 0 ), + array( 'pl_namespace', 'int2_ops', 'btree', 0 ), + array( 'pl_title', 'text_ops', 'btree', 0 ), ), 'CREATE UNIQUE INDEX pagelink_unique ON pagelinks (pl_from,pl_namespace,pl_title)' ), array( 'checkIndex', 'cl_sortkey', array( - array('cl_to', 'text_ops', 'btree', 0), - array('cl_sortkey', 'text_ops', 'btree', 0), - array('cl_from', 'int4_ops', 'btree', 0), + array( 'cl_to', 'text_ops', 'btree', 0 ), + array( 'cl_sortkey', 'text_ops', 'btree', 0 ), + array( 'cl_from', 'int4_ops', 'btree', 0 ), ), 'CREATE INDEX cl_sortkey ON "categorylinks" USING "btree" ("cl_to", "cl_sortkey", "cl_from")' ), array( 'checkIndex', 'logging_times', array( - array('log_timestamp', 'timestamptz_ops', 'btree', 0), + array( 'log_timestamp', 'timestamptz_ops', 'btree', 0 ), ), 'CREATE INDEX "logging_times" ON "logging" USING "btree" ("log_timestamp")' ), array( 'dropIndex', 'oldimage', 'oi_name' ), array( 'checkIndex', 'oi_name_archive_name', array( - array('oi_name', 'text_ops', 'btree', 0), - array('oi_archive_name', 'text_ops', 'btree', 0), + array( 'oi_name', 'text_ops', 'btree', 0 ), + array( 'oi_archive_name', 'text_ops', 'btree', 0 ), ), 'CREATE INDEX "oi_name_archive_name" ON "oldimage" USING "btree" ("oi_name", "oi_archive_name")' ), array( 'checkIndex', 'oi_name_timestamp', array( - array('oi_name', 'text_ops', 'btree', 0), - array('oi_timestamp', 'timestamptz_ops', 'btree', 0), + array( 'oi_name', 'text_ops', 'btree', 0 ), + array( 'oi_timestamp', 'timestamptz_ops', 'btree', 0 ), ), 'CREATE INDEX "oi_name_timestamp" ON "oldimage" USING "btree" ("oi_name", "oi_timestamp")' ), array( 'checkIndex', 'page_main_title', array( - array('page_title', 'text_pattern_ops', 'btree', 0), + array( 'page_title', 'text_pattern_ops', 'btree', 0 ), ), 'CREATE INDEX "page_main_title" ON "page" USING "btree" ("page_title" "text_pattern_ops") WHERE ("page_namespace" = 0)' ), array( 'checkIndex', 'page_mediawiki_title', array( - array('page_title', 'text_pattern_ops', 'btree', 0), + array( 'page_title', 'text_pattern_ops', 'btree', 0 ), ), 'CREATE INDEX "page_mediawiki_title" ON "page" USING "btree" ("page_title" "text_pattern_ops") WHERE ("page_namespace" = 8)' ), array( 'checkIndex', 'page_project_title', array( - array('page_title', 'text_pattern_ops', 'btree', 0), + array( 'page_title', 'text_pattern_ops', 'btree', 0 ), ), 'CREATE INDEX "page_project_title" ON "page" USING "btree" ("page_title" "text_pattern_ops") WHERE ("page_namespace" = 4)' ), array( 'checkIndex', 'page_talk_title', array( - array('page_title', 'text_pattern_ops', 'btree', 0), + array( 'page_title', 'text_pattern_ops', 'btree', 0 ), ), 'CREATE INDEX "page_talk_title" ON "page" USING "btree" ("page_title" "text_pattern_ops") WHERE ("page_namespace" = 1)' ), array( 'checkIndex', 'page_user_title', array( - array('page_title', 'text_pattern_ops', 'btree', 0), + array( 'page_title', 'text_pattern_ops', 'btree', 0 ), ), 'CREATE INDEX "page_user_title" ON "page" USING "btree" ("page_title" "text_pattern_ops") WHERE ("page_namespace" = 2)' ), array( 'checkIndex', 'page_utalk_title', array( - array('page_title', 'text_pattern_ops', 'btree', 0), + array( 'page_title', 'text_pattern_ops', 'btree', 0 ), ), 'CREATE INDEX "page_utalk_title" ON "page" USING "btree" ("page_title" "text_pattern_ops") WHERE ("page_namespace" = 3)' ), array( 'checkIndex', 'ts2_page_text', array( - array('textvector', 'tsvector_ops', 'gist', 0), + array( 'textvector', 'tsvector_ops', 'gist', 0 ), ), 'CREATE INDEX "ts2_page_text" ON "pagecontent" USING "gist" ("textvector")' ), array( 'checkIndex', 'ts2_page_title', array( - array('titlevector', 'tsvector_ops', 'gist', 0), + array( 'titlevector', 'tsvector_ops', 'gist', 0 ), ), 'CREATE INDEX "ts2_page_title" ON "page" USING "gist" ("titlevector")' ), @@ -293,10 +303,10 @@ class PostgresUpdater extends DatabaseUpdater { array( 'checkRevUserFkey' ), array( 'dropIndex', 'ipblocks', 'ipb_address'), array( 'checkIndex', 'ipb_address_unique', array( - array('ipb_address', 'text_ops', 'btree', 0), - array('ipb_user', 'int4_ops', 'btree', 0), - array('ipb_auto', 'int2_ops', 'btree', 0), - array('ipb_anon_only', 'int2_ops', 'btree', 0), + array( 'ipb_address', 'text_ops', 'btree', 0 ), + array( 'ipb_user', 'int4_ops', 'btree', 0 ), + array( 'ipb_auto', 'int2_ops', 'btree', 0 ), + array( 'ipb_anon_only', 'int2_ops', 'btree', 0 ), ), 'CREATE UNIQUE INDEX ipb_address_unique ON ipblocks (ipb_address,ipb_user,ipb_auto,ipb_anon_only)' ), @@ -499,7 +509,7 @@ END; $this->output( "Creating sequence $ns\n" ); $this->db->query( "CREATE SEQUENCE $ns" ); if( $pkey !== false ) { - $this->setDefault( $table, $pkey, '"nextval"(\'"' . $ns . '"\'::"regclass")' ); + $this->setDefault( $table, $pkey, '"nextval"(\'"' . $ns . '"\'::"regclass")' ); } } } @@ -527,11 +537,34 @@ END; } } - protected function renameIndex( $table, $old, $new ) { - if ( $this->db->indexExists( $table, $old ) ) { - $this->output( "Renaming index $old to $new\n" ); - $this->db->query( "ALTER INDEX $old RENAME TO $new" ); + protected function renameIndex( + $table, $old, $new, $skipBothIndexExistWarning = false, $a = false, $b = false + ) { + // First requirement: the table must exist + if ( !$this->db->tableExists( $table, __METHOD__ ) ) { + $this->output( "...skipping: '$table' table doesn't exist yet.\n" ); + return; + } + + // Second requirement: the new index must be missing + if ( $this->db->indexExists( $table, $new, __METHOD__ ) ) { + $this->output( "...index $new already set on $table table.\n" ); + if ( !$skipBothIndexExistWarning + && $this->db->indexExists( $table, $old, __METHOD__ ) ) + { + $this->output( "...WARNING: $old still exists, despite it has been renamed into $new (which also exists).\n" . + " $old should be manually removed if not needed anymore.\n" ); + } + return; } + + // Third requirement: the old index must exist + if ( !$this->db->indexExists( $table, $old, __METHOD__ ) ) { + $this->output( "...skipping: index $old doesn't exist.\n" ); + return; + } + + $this->db->query( "ALTER INDEX $old RENAME TO $new" ); } protected function addPgField( $table, $field, $type ) {