r68758 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r68757‎ | r68758 | r68759 >
Date:01:32, 30 June 2010
Author:kaldari
Status:resolved (Comments)
Tags:
Comment:
adding SQL patch support for auto-updating
Modified paths:
  • /trunk/extensions/CentralNotice/CentralNotice.php (modified) (history)
  • /trunk/extensions/CentralNotice/CentralNotice.sql (modified) (history)
  • /trunk/extensions/CentralNotice/arrow.png (added) (history)
  • /trunk/extensions/CentralNotice/patch-add-preferred.sql (deleted) (history)
  • /trunk/extensions/CentralNotice/patches (added) (history)
  • /trunk/extensions/CentralNotice/patches/patch-add-preferred.sql (added) (history)
  • /trunk/extensions/CentralNotice/patches/patch-notice_languages.sql (added) (history)

Diff [purge]

Index: trunk/extensions/CentralNotice/patch-add-preferred.sql
@@ -1,6 +0,0 @@
2 -# Support for one notice to supercede all others. This allows one notice to
3 -# cancel out all the templates that a non preffered notice might have if they
4 -# overlap. Use case is to be able to use one all language and projects notice
5 -# and have it superceded by a specific one for en wikipedia.
6 -
7 -ALTER TABLE cn_notices ADD COLUMN not_preferred bool NOT NULL default '0';
Index: trunk/extensions/CentralNotice/CentralNotice.php
@@ -119,6 +119,7 @@
120120 $dir = dirname( __FILE__ ) . '/';
121121
122122 if ( $wgCentralNoticeLoader ) {
 123+ $wgHooks['LoadExtensionSchemaUpdates'][] = 'efCentralNoticeSchema';
123124 $wgHooks['BeforePageDisplay'][] = 'efCentralNoticeLoader';
124125 $wgHooks['MakeGlobalVariablesScript'][] = 'efCentralNoticeDefaults';
125126
@@ -147,6 +148,17 @@
148149 }
149150 }
150151
 152+function efCentralNoticeSchema() {
 153+ global $wgDBtype, $wgExtNewTables;
 154+
 155+ $base = dirname( __FILE__ );
 156+ if ( $wgDBtype == 'mysql' ) {
 157+ $wgExtNewTables[] = array( 'cn_notices', $base . '/CentralNotice.sql' );
 158+ $wgExtNewTables[] = array( 'cn_notice_languages', $base . '/patches/patch-notice_languages.sql' );
 159+ }
 160+ return true;
 161+}
 162+
151163 function efCentralNoticeLoader( $out, $skin ) {
152164 global $wgUser, $wgOut, $wgLang;
153165 global $wgNoticeProject, $wgNoticeCentralPath, $wgNoticeLocalPath, $wgNoticeUseLocalNotice;
Index: trunk/extensions/CentralNotice/patches/patch-add-preferred.sql
@@ -0,0 +1,6 @@
 2+# Support for one notice to supercede all others. This allows one notice to
 3+# cancel out all the templates that a non preffered notice might have if they
 4+# overlap. Use case is to be able to use one all language and projects notice
 5+# and have it superceded by a specific one for en wikipedia.
 6+
 7+ALTER TABLE cn_notices ADD COLUMN not_preferred bool NOT NULL default '0';
Property changes on: trunk/extensions/CentralNotice/patches/patch-add-preferred.sql
___________________________________________________________________
Name: svn:eol-style
18 + native
Index: trunk/extensions/CentralNotice/patches/patch-notice_languages.sql
@@ -0,0 +1,9 @@
 2+-- Update to allow for any number of languages per notice.
 3+
 4+CREATE TABLE IF NOT EXISTS /*$wgDBprefix*/cn_notice_languages (
 5+ `id` int unsigned NOT NULL auto_increment,
 6+ `not_id` int unsigned NOT NULL,
 7+ `not_language` varchar(32) NOT NULL,
 8+ PRIMARY KEY (`id`),
 9+ UNIQUE KEY `not_id_not_language` (`not_id`,`not_language`)
 10+) /*$wgDBTableOptions*/;
\ No newline at end of file
Index: trunk/extensions/CentralNotice/CentralNotice.sql
@@ -1,4 +1,4 @@
2 -CREATE TABLE `cn_notices` (
 2+CREATE TABLE IF NOT EXISTS /*$wgDBprefix*/cn_notices (
33 `not_id` int NOT NULL auto_increment,
44 `not_name` varchar(255) NOT NULL,
55 `not_start` char(14) NOT NULL,
@@ -11,7 +11,7 @@
1212 PRIMARY KEY (`not_id`)
1313 ) /*$wgDBTableOptions*/;
1414
15 -CREATE TABLE `cn_assignments` (
 15+CREATE TABLE IF NOT EXISTS /*$wgDBprefix*/cn_assignments (
1616 `asn_id` int NOT NULL auto_increment,
1717 `not_id` int NOT NULL,
1818 `tmp_id` int NOT NULL,
@@ -19,13 +19,13 @@
2020 PRIMARY KEY (`asn_id`)
2121 ) /*$wgDBTableOptions*/;
2222
23 -CREATE TABLE `cn_templates` (
 23+CREATE TABLE IF NOT EXISTS /*$wgDBprefix*/cn_templates (
2424 `tmp_id` int NOT NULL auto_increment,
2525 `tmp_name` varchar(255) default NULL,
2626 PRIMARY KEY (`tmp_id`)
2727 ) /*$wgDBTableOptions*/;
2828
29 -CREATE TABLE `cn_notice_languages` (
 29+CREATE TABLE IF NOT EXISTS /*$wgDBprefix*/cn_notice_languages (
3030 `id` int unsigned NOT NULL auto_increment,
3131 `not_id` int unsigned NOT NULL,
3232 `not_language` varchar(32) NOT NULL,
Index: trunk/extensions/CentralNotice/arrow.png
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes on: trunk/extensions/CentralNotice/arrow.png
___________________________________________________________________
Name: svn:mime-type
3333 + application/octet-stream

Follow-up revisions

RevisionCommit summaryAuthorDate
r70908adding patch-notice_preferred.sql to update hook per comment at r68758kaldari18:54, 11 August 2010
r70969Follow-up r68758: fixed SQLite compatibilitymaxsem16:39, 12 August 2010

Comments

#Comment by Catrope (talk | contribs)   08:24, 11 August 2010
+	if ( $wgDBtype == 'mysql' ) {
+		$wgExtNewTables[] = array( 'cn_notices', $base . '/CentralNotice.sql' );
+		$wgExtNewTables[] = array( 'cn_notice_languages', $base . '/patches/patch-notice_languages.sql' );
+	}

Why is patch-add-preferred.sql not in here?

+  PRIMARY KEY (`id`),
+  UNIQUE KEY `not_id_not_language` (`not_id`,`not_language`)
+) /*$wgDBTableOptions*/;

You should do the trivial work to make this SQLite compatible, by putting PRIMARY KEY in the definition of the id field and creating the index outside the CREATE TABLE statement with CREATE INDEX /*i*/cn_not_id_not_language ON /*_*/cn_notice_languages (not_id, not_language); (/*_*/ is a shortcut for /*$wgDBprefix*/).

#Comment by Kaldari (talk | contribs)   19:05, 11 August 2010

Just added preferred patch in r70908.

Made SQLite compatible in r70907. I have no idea if I did this correctly, so please review it and let me know if it needs to be changed. Thanks!

#Comment by MaxSem (talk | contribs)   16:41, 12 August 2010

No, it didn't work - fixed in r70969. See Manual:Database access#SQLite compatibility for details.

#Comment by Kaldari (talk | contribs)   23:29, 20 August 2010

Looks like the SQLite fix broke the mySQL functionality. Fixed in r71220.

Status & tagging log