From 07812be170a9f6a1e4cd1f7a2c2478cb767bcc6b Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Tue, 31 Jul 2012 11:03:25 +0200 Subject: [PATCH] Bug 7167: Add .pl and .sql examples Content-Type: text/plain; charset="utf-8" Those files are in version directory, so will never be executed by the updater If you want to provide an update, do it in a 3.09/ directory (if your update is expected for 3.10 version) Note that the updater use a md5sum checker. So, if the same update is in 2 different places, it will be detected. That will be handy for changes made on both stable and master: a library running stable will get the update when updating. When upgrading to the next major release, Koha will detect the patch has already been applied, and no error will be thrown. With the previous mechanism, a DBRev ported to stable was re-executed when upgrading to master, resulting in a nasty (but usually harmless) error message Signed-off-by: Paul Poulain Signed-off-by: Chris Nighswonger --- .../data/mysql/versions/update_sample.pl.sample | 44 ++++++++++++++++++++ .../data/mysql/versions/update_sample.sql.sample | 35 ++++++++++++++++ 2 files changed, 79 insertions(+) create mode 100644 installer/data/mysql/versions/update_sample.pl.sample create mode 100644 installer/data/mysql/versions/update_sample.sql.sample diff --git a/installer/data/mysql/versions/update_sample.pl.sample b/installer/data/mysql/versions/update_sample.pl.sample new file mode 100644 index 0000000..49e62b3 --- /dev/null +++ b/installer/data/mysql/versions/update_sample.pl.sample @@ -0,0 +1,44 @@ +#!/usr/bin/perl + +# You write good Perl, so you start with Modern::Perl, of course +use Modern::Perl; + +# then you load Packages that could be usefull +use C4::Context; +# Loading this package is usefull if you need to check if a table exist (TableExists) +use C4::Update::Database; + +# you *must* have the sub _get_queries +# it returns an array of all SQL that have to be executed +# this array will be stored "forever" in your Koha database +# thus, you will be able to know which SQL has been executed +# at the time of upgrade. Very handy, because since then +# your database configuration may have changed and you'll wonder +# what has really be executed, not what would be executed today ! + +# put in an array the SQL to execute +# put in an array the comments +sub _get_queries { + my @queries; + my @comments; + push @comments, "Add sample feature"; + unless ( C4::Update::Database::TableExists('testtable') ) { + push @queries, qq{ + CREATE TABLE `testtable` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `source` text DEFAULT NULL, + `text` mediumtext NOT NULL, + `timestamp` datetime NOT NULL, + PRIMARY KEY (`id`) + ) ENGINE=InnoDB DEFAULT CHARSET=utf8 + }; + push @comments, qq { * Added the table testtable that did not exist}; + } + push @queries, qq{INSERT IGNORE INTO `systempreferences` (variable,value,explanation,options,type) VALUES('testsyspref1',0,'Enable or disable display of Quote of the Day on the OPAC home page',NULL,'YesNo')}; + push @queries, qq{INSERT IGNORE INTO `systempreferences` (variable,value,explanation,options,type) VALUES('testsyspref2',0,'Enable or disable display of Quote of the Day on the OPAC home page',NULL,'YesNo')}; + push @comments , qq{ * Added 2 sysprefs}; + +# return queries and comments + return { queries => \@queries, comments => \@comments }; +} +1; diff --git a/installer/data/mysql/versions/update_sample.sql.sample b/installer/data/mysql/versions/update_sample.sql.sample new file mode 100644 index 0000000..ac83c0b --- /dev/null +++ b/installer/data/mysql/versions/update_sample.sql.sample @@ -0,0 +1,35 @@ +-- This is an example for .sql file +-- all the comments (ie= what is after --) will be identified as comment +-- and displayed as such in Koha updatedatabase interface +-- the .sql is easy: just define a separator if you plan to have multi-line SQL +-- then, your sql + +-- basic example, without delimiter defined: +UPDATE systempreferences SET value="something" WHERE variable="TestSysprefBasic"; +INSERT INTO itemtypes (itemtype, description) VALUES ('SAMPLE','A description'); +-- End of basic sample + + +-- more complex example, with delimiter defined: +DELIMITER // +-- I've defined a delimiter +-- so I can put SQL on many lines +-- Note that in this sample, the ; at the end of each query is not required. +CREATE TABLE `testtable1` ( + `entry` varchar(255) NOT NULL default '', + `weight` bigint(20) NOT NULL default 0, + PRIMARY KEY (`entry`) + ) ENGINE=InnoDB DEFAULT CHARSET=utf8; +// +-- or on a single line, as previously +-- without ; just for the sample +INSERT INTO `systempreferences` VALUES ('TestSyspref1','2','set the level of error info sent to the browser. 0=none, 1=some, 2=most','0|1|2','Choice') +// + +-- Note that you can even put more than 1 SQL query without DELIMITER +-- In this case, the updater will consider them as 1 query. +-- That can be usefull if you want to do a logical grouping +INSERT INTO `systempreferences` VALUES ('TestSyspref2','2','set the level of error info sent to the browser. 0=none, 1=some, 2=most','0|1|2','Choice'); +INSERT INTO `systempreferences` VALUES ('TestSyspref3','2','set the level of error info sent to the browser. 0=none, 1=some, 2=most','0|1|2','Choice'); +// +-- End of complex sample -- 1.7.9.5