X-Git-Url: https://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=blobdiff_plain;f=includes%2Finstaller%2FPostgresUpdater.php;h=1f17fecc2b5ae976af73ff2d6c619d38cb5b0ba0;hp=e5a5c9445c16a688a196d4c322232d527c548255;hb=5fa4cdf860c79b32ab6ef034c6d9420c2727f695;hpb=9bd7c7f66058fe26e130759090e7a73beee4d3d0 diff --git a/includes/installer/PostgresUpdater.php b/includes/installer/PostgresUpdater.php index e5a5c9445c..1f17fecc2b 100644 --- a/includes/installer/PostgresUpdater.php +++ b/includes/installer/PostgresUpdater.php @@ -454,7 +454,7 @@ class PostgresUpdater extends DatabaseUpdater { [ 'addPgIndex', 'user_groups', 'user_groups_expiry', '( ug_expiry )' ], // 1.30 - [ 'modifyField', 'image', 'img_media_type', 'patch-add-3d.sql' ], + [ 'addPgEnumValue', 'media_type', '3D' ], [ 'setDefault', 'revision', 'rev_comment', '' ], [ 'changeNullableField', 'revision', 'rev_comment', 'NOT NULL', true ], [ 'setDefault', 'archive', 'ar_comment', '' ], @@ -481,6 +481,7 @@ class PostgresUpdater extends DatabaseUpdater { [ 'changeNullableField', 'protected_titles', 'pt_reason', 'NOT NULL', true ], [ 'addPgField', 'protected_titles', 'pt_reason_id', 'INTEGER NOT NULL DEFAULT 0' ], [ 'addTable', 'comment', 'patch-comment-table.sql' ], + [ 'addIndex', 'site_stats', 'PRIMARY', 'patch-site_stats-pk.sql' ], ]; } @@ -783,7 +784,8 @@ END; $info = $this->db->fieldInfo( $table, $field ); if ( $info->defaultValue() !== $default ) { $this->output( "Changing '$table.$field' default value\n" ); - $this->db->query( "ALTER TABLE $table ALTER $field SET DEFAULT " . $default ); + $this->db->query( "ALTER TABLE $table ALTER $field SET DEFAULT " + . $this->db->addQuotes( $default ) ); } } @@ -837,6 +839,46 @@ END; } } + /** + * Add a value to an existing PostgreSQL enum type + * @since 1.31 + * @param string $type Type name. Must be in the core schema. + * @param string $value Value to add. + */ + public function addPgEnumValue( $type, $value ) { + $row = $this->db->selectRow( + [ + 't' => 'pg_catalog.pg_type', + 'n' => 'pg_catalog.pg_namespace', + 'e' => 'pg_catalog.pg_enum', + ], + [ 't.typname', 't.typtype', 'e.enumlabel' ], + [ + 't.typname' => $type, + 'n.nspname' => $this->db->getCoreSchema(), + ], + __METHOD__, + [], + [ + 'n' => [ 'JOIN', 't.typnamespace = n.oid' ], + 'e' => [ 'LEFT JOIN', [ 'e.enumtypid = t.oid', 'e.enumlabel' => $value ] ], + ] + ); + + if ( !$row ) { + $this->output( "...Type $type does not exist, skipping modify enum.\n" ); + } elseif ( $row->typtype !== 'e' ) { + $this->output( "...Type $type does not seem to be an enum, skipping modify enum.\n" ); + } elseif ( $row->enumlabel === $value ) { + $this->output( "...Enum type $type already contains value '$value'.\n" ); + } else { + $this->output( "...Adding value '$value' to enum type $type.\n" ); + $etype = $this->db->addIdentifierQuotes( $type ); + $evalue = $this->db->addQuotes( $value ); + $this->db->query( "ALTER TYPE $etype ADD VALUE $evalue" ); + } + } + protected function dropFkey( $table, $field ) { $fi = $this->db->fieldInfo( $table, $field ); if ( is_null( $fi ) ) {