jenkins-bot has submitted this change and it was merged.

Change subject: Added the db_patch files for renaming rev_id and user_id column
......................................................................


Added the db_patch files for renaming rev_id and user_id column

user_id column was already renamed to annotation_user_id in the
patchset https://gerrit.wikimedia.org/r/#/c/75645/ but the patch file
is added here. This renames rev_id to annotation_rev_id, as well as
includes the patch file.

Change-Id: Ibf45c14312ecc191c629ea7fb532b6e93c555063
---
M AnnotationRepository.php
M Annotator.hooks.php
M api/ApiAnnotatorCreate.php
M sql/annotator.sql
A sql/db_patches/patch-rev_id-rename.sql
A sql/db_patches/patch-rev_id-rename.sqlite.sql
A sql/db_patches/patch-user_id-rename.sql
A sql/db_patches/patch-user_id-rename.sqlite.sql
8 files changed, 60 insertions(+), 5 deletions(-)

Approvals:
  Mattflaschen: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/AnnotationRepository.php b/AnnotationRepository.php
index 770570d..6f9c4fe 100644
--- a/AnnotationRepository.php
+++ b/AnnotationRepository.php
@@ -47,7 +47,7 @@
                                'userName' => 'user_name'
                                ),
                        array(
-                               'rev_id' => $revid
+                               'annotation_rev_id' => $revid
                                ),
                        __METHOD__,
                        array(),
diff --git a/Annotator.hooks.php b/Annotator.hooks.php
index 1364833..7132464 100755
--- a/Annotator.hooks.php
+++ b/Annotator.hooks.php
@@ -12,14 +12,23 @@
        public static function loadExtensionSchemaUpdates( $updater = null ) {
                $updater->addExtensionTable(
                        'annotator',
-                       dirname( __FILE__ ) . '/sql/annotator.sql'
+                       __DIR__ . '/sql/annotator.sql'
                );
 
                $updater->addExtensionIndex(
                        'annotator',
                        'annotator_rev_id',
-                       dirname( __FILE__ ) . '/sql/index_rev_id.sql'
+                       __DIR__ . '/sql/index_rev_id.sql'
                );
+
+               if( $updater->getDB()->getType() === 'sqlite' ) {
+                       $updater->modifyExtensionField( 'annotator', 'user_id', 
__DIR__ . "/sql/db_patches/patch-user_id-rename.sqlite.sql" );
+                       $updater->modifyExtensionField( 'annotator', 'rev_id', 
__DIR__ . "/sql/db_patches/patch-rev_id-rename.sqlite.sql" );
+               }
+               else {
+                       $updater->modifyExtensionField( 'annotator', 'user_id', 
__DIR__ . "/sql/db_patches/patch-user_id-rename.sql" );
+                       $updater->modifyExtensionField( 'annotator', 'rev_id', 
__DIR__ . "/sql/db_patches/patch-rev_id-rename.sql" );
+               }
                return true;
        }
        /*adds the annotator js and css
diff --git a/api/ApiAnnotatorCreate.php b/api/ApiAnnotatorCreate.php
index 8a0fbda..1bf9a56 100755
--- a/api/ApiAnnotatorCreate.php
+++ b/api/ApiAnnotatorCreate.php
@@ -40,7 +40,7 @@
                        'annotator',
                        array(
                                'annotation_json' => $annotation,
-                               'rev_id' => $revid,
+                               'annotation_rev_id' => $revid,
                                'annotation_user_id' => $user_id
                                )
                        );
diff --git a/sql/annotator.sql b/sql/annotator.sql
index 47ee692..34f713e 100644
--- a/sql/annotator.sql
+++ b/sql/annotator.sql
@@ -5,7 +5,7 @@
 CREATE TABLE IF NOT EXISTS /*_*/annotator (
   annotation_id int(10) unsigned NOT NULL PRIMARY KEY AUTO_INCREMENT,
   annotation_json text NOT NULL,
-  rev_id int(10) unsigned NOT NULL,
+  annotation_rev_id int(10) unsigned NOT NULL,
   annotation_user_id int(10) unsigned NOT NULL
 ) /*$wgDBTableOptions*/;
 
diff --git a/sql/db_patches/patch-rev_id-rename.sql 
b/sql/db_patches/patch-rev_id-rename.sql
new file mode 100644
index 0000000..1894dab
--- /dev/null
+++ b/sql/db_patches/patch-rev_id-rename.sql
@@ -0,0 +1 @@
+ALTER TABLE annotator CHANGE COLUMN rev_id annotation_rev_id int(10) unsigned 
NOT NULL;
\ No newline at end of file
diff --git a/sql/db_patches/patch-rev_id-rename.sqlite.sql 
b/sql/db_patches/patch-rev_id-rename.sqlite.sql
new file mode 100644
index 0000000..92a7fcc
--- /dev/null
+++ b/sql/db_patches/patch-rev_id-rename.sqlite.sql
@@ -0,0 +1,22 @@
+-- Rename current table to temporary name
+ALTER TABLE /*_*/annotator RENAME TO /*_*/temp_annotator_rename_rev_id;
+
+CREATE TABLE IF NOT EXISTS /*_*/annotator (
+  annotation_id int(10) unsigned NOT NULL PRIMARY KEY AUTO_INCREMENT,
+  annotation_json text NOT NULL,
+  annotation_rev_id int(10) unsigned NOT NULL,
+  annotation_user_id int(10) unsigned NOT NULL
+) /*$wgDBTableOptions*/;
+
+INSERT INTO /*_*/annotator
+       ( annotation_id, annotation_json, annotation_rev_id, annotation_user_id 
)
+SELECT
+       annotation_id, annotation_json, rev_id, annotation_user_id
+FROM
+       /*_*/temp_annotator_rename_rev_id;
+
+--Drop the original table--
+DROP TABLE /*_*/temp_annotator_rename_rev_id;
+
+--recreate indexes--
+CREATE INDEX /*i*/annotator_rev_id ON /*_*/annotator (annotation_rev_id);
\ No newline at end of file
diff --git a/sql/db_patches/patch-user_id-rename.sql 
b/sql/db_patches/patch-user_id-rename.sql
new file mode 100644
index 0000000..5445c46
--- /dev/null
+++ b/sql/db_patches/patch-user_id-rename.sql
@@ -0,0 +1 @@
+ALTER TABLE annotator CHANGE COLUMN user_id annotation_user_id int(10) 
unsigned NOT NULL;
\ No newline at end of file
diff --git a/sql/db_patches/patch-user_id-rename.sqlite.sql 
b/sql/db_patches/patch-user_id-rename.sqlite.sql
new file mode 100644
index 0000000..3b2db73
--- /dev/null
+++ b/sql/db_patches/patch-user_id-rename.sqlite.sql
@@ -0,0 +1,22 @@
+-- Rename current table to temporary name
+ALTER TABLE /*_*/annotator RENAME TO /*_*/temp_annotator_rename_user_id;
+
+CREATE TABLE IF NOT EXISTS /*_*/annotator (
+  annotation_id int(10) unsigned NOT NULL PRIMARY KEY AUTO_INCREMENT,
+  annotation_json text NOT NULL,
+  rev_id int(10) unsigned NOT NULL,
+  annotation_user_id int(10) unsigned NOT NULL
+) /*$wgDBTableOptions*/;
+
+INSERT INTO /*_*/annotator
+       ( annotation_id, annotation_json, rev_id, annotation_user_id )
+SELECT
+       annotation_id, annotation_json, rev_id, user_id
+FROM
+       /*_*/temp_annotator_rename_user_id;
+
+--Drop the original table--
+DROP TABLE /*_*/temp_annotator_rename_user_id;
+
+--recreate indexes--
+CREATE INDEX /*i*/annotator_rev_id ON /*_*/annotator (rev_id);
\ No newline at end of file

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

Gerrit-MessageType: merged
Gerrit-Change-Id: Ibf45c14312ecc191c629ea7fb532b6e93c555063
Gerrit-PatchSet: 5
Gerrit-Project: mediawiki/extensions/Annotator
Gerrit-Branch: master
Gerrit-Owner: Rjain <[email protected]>
Gerrit-Reviewer: Mattflaschen <[email protected]>
Gerrit-Reviewer: Parent5446 <[email protected]>
Gerrit-Reviewer: Rjain <[email protected]>
Gerrit-Reviewer: jenkins-bot

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to