@@ -, +, @@ --- .../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 --- a/installer/data/mysql/versions/update_sample.pl.sample +++ a/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; --- a/installer/data/mysql/versions/update_sample.sql.sample +++ a/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 --