Jjanes has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/288341

Change subject: Add PostgreSQL support to HitCounters
......................................................................

Add PostgreSQL support to HitCounters

This adds support for PostgreSQL to the HitCounters extension.

When upgrading from a pre-1.25 version, the existing counts are dropped
before the extension update hook gets access to them, so existing counts
are lost.  Fixing that would require changes to the core code
rather than to just this extension.

Bug: T110655
Change-Id: I56a7ed3b30a7d0438bf5da6675f3bde52fcae8b9
---
M HCUpdater.php
A postgres/drop_field.sql
A postgres/hit_counter_extension.sql
A postgres/initial_count.sql
A postgres/page_counter.sql
A postgres/rename_table.sql
6 files changed, 25 insertions(+), 4 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/HitCounters 
refs/changes/41/288341/1

diff --git a/HCUpdater.php b/HCUpdater.php
index 331f2fa..1de6b39 100644
--- a/HCUpdater.php
+++ b/HCUpdater.php
@@ -9,16 +9,24 @@
 /* hack to get at protected member */
 class HCUpdater extends DatabaseUpdater {
        public static function getDBUpdates ( DatabaseUpdater $updater ) {
+
+               $base = __DIR__;
+               switch ( $updater->getDB()->getType() ) {
+               case 'postgres':
+                       $base = __DIR__ . '/postgres/';
+                       break;
+               }
+
                /* This is an ugly abuse to rename a table. */
                $updater->modifyExtensionField( 'hitcounter',
                        'hc_id',
-                       __DIR__ . '/rename_table.sql' );
+                       $base . '/rename_table.sql' );
                $updater->addExtensionTable( 'hit_counter_extension',
-                       __DIR__ . '/hit_counter_extension.sql', true );
+                       $base . '/hit_counter_extension.sql', true );
                $updater->addExtensionTable( 'hit_counter',
-                       __DIR__ . '/page_counter.sql', true );
+                       $base . '/page_counter.sql', true );
                $updater->dropExtensionField( 'page', 'page_counter',
-                       __DIR__ . '/drop_field.sql' );
+                       $base . '/drop_field.sql' );
        }
 
        public function clearExtensionUpdates() {
diff --git a/postgres/drop_field.sql b/postgres/drop_field.sql
new file mode 100644
index 0000000..d4159e3
--- /dev/null
+++ b/postgres/drop_field.sql
@@ -0,0 +1,2 @@
+INSERT INTO /*_*/hit_counter (page_id, page_counter) SELECT /*_*/page.page_id, 
/*_*/page.page_counter FROM /*_*/page;
+ALTER TABLE /*_*/page DROP page_counter;
diff --git a/postgres/hit_counter_extension.sql 
b/postgres/hit_counter_extension.sql
new file mode 100644
index 0000000..b5e3193
--- /dev/null
+++ b/postgres/hit_counter_extension.sql
@@ -0,0 +1,3 @@
+CREATE unlogged TABLE /*_*/hit_counter_extension (
+  hc_id integer NOT NULL
+);
diff --git a/postgres/initial_count.sql b/postgres/initial_count.sql
new file mode 100644
index 0000000..003e0a1
--- /dev/null
+++ b/postgres/initial_count.sql
@@ -0,0 +1 @@
+INSERT INTO /*_*/hit_counter (page_id, page_counter) SELECT /*_*/page.page_id, 
/*_*/page.page_counter FROM /*_*/page;
diff --git a/postgres/page_counter.sql b/postgres/page_counter.sql
new file mode 100644
index 0000000..5ec8ad5
--- /dev/null
+++ b/postgres/page_counter.sql
@@ -0,0 +1,6 @@
+CREATE TABLE /*_*/hit_counter (
+  page_id serial primary key,
+  page_counter BIGINT NOT NULL DEFAULT '0'
+) /*$wgDBTableOptions*/;
+
+CREATE INDEX /*i*/page_counter ON /*_*/hit_counter (page_counter);
diff --git a/postgres/rename_table.sql b/postgres/rename_table.sql
new file mode 100644
index 0000000..56d8e42
--- /dev/null
+++ b/postgres/rename_table.sql
@@ -0,0 +1 @@
+RENAME TABLE /*_*/hitcounter TO /*_*/hit_counter_extension;

-- 
To view, visit https://gerrit.wikimedia.org/r/288341
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I56a7ed3b30a7d0438bf5da6675f3bde52fcae8b9
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/HitCounters
Gerrit-Branch: master
Gerrit-Owner: Jjanes <jeff.ja...@gmail.com>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to