View | Details | Raw Unified | Return to bug 7167
Collapse All | Expand All

(-)a/installer/data/mysql/versions/update_sample.pl.sample (+44 lines)
Line 0 Link Here
1
#!/usr/bin/perl
2
3
# You write good Perl, so you start with Modern::Perl, of course
4
use Modern::Perl;
5
6
# then you load Packages that could be usefull
7
use C4::Context;
8
# Loading this package is usefull if you need to check if a table exist (TableExists)
9
use C4::Update::Database;
10
11
# you *must* have the sub _get_queries
12
# it returns an array of all SQL that have to be executed
13
# this array will be stored "forever" in your Koha database
14
# thus, you will be able to know which SQL has been executed
15
# at the time of upgrade. Very handy, because since then
16
# your database configuration may have changed and you'll wonder
17
# what has really be executed, not what would be executed today !
18
19
# put in an array the SQL to execute
20
# put in an array the comments
21
sub _get_queries {
22
    my @queries;
23
    my @comments;
24
    push @comments, "Add sample feature";
25
    unless ( C4::Update::Database::TableExists('testtable') ) {
26
        push @queries, qq{
27
                CREATE TABLE `testtable` (
28
                  `id` int(11) NOT NULL AUTO_INCREMENT,
29
                  `source` text DEFAULT NULL,
30
                  `text` mediumtext NOT NULL,
31
                  `timestamp` datetime NOT NULL,
32
                  PRIMARY KEY (`id`)
33
                ) ENGINE=InnoDB DEFAULT CHARSET=utf8
34
            };
35
        push @comments, qq { * Added the table testtable that did not exist};
36
    }
37
    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')};
38
    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')};
39
    push @comments , qq{ * Added 2 sysprefs};
40
41
# return queries and comments
42
    return { queries => \@queries, comments => \@comments };
43
}
44
1;
(-)a/installer/data/mysql/versions/update_sample.sql.sample (-1 / +35 lines)
Line 0 Link Here
0
- 
1
-- This is an example for .sql file
2
-- all the comments (ie= what is after --) will be identified as comment
3
-- and displayed as such in Koha updatedatabase interface
4
-- the .sql is easy: just define a separator if you plan to have multi-line SQL
5
-- then, your sql
6
7
-- basic example, without delimiter defined:
8
UPDATE systempreferences SET value="something" WHERE variable="TestSysprefBasic";
9
INSERT INTO itemtypes (itemtype, description) VALUES ('SAMPLE','A description');
10
-- End of basic sample
11
12
13
-- more complex example, with delimiter defined:
14
DELIMITER //
15
-- I've defined a delimiter
16
-- so I can put SQL on many lines
17
-- Note that in this sample, the ; at the end of each query is not required.
18
CREATE TABLE `testtable1` (
19
                    `entry` varchar(255) NOT NULL default '',
20
                    `weight` bigint(20) NOT NULL default 0,
21
                    PRIMARY KEY  (`entry`)
22
                    ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
23
//
24
-- or on a single line, as previously
25
-- without ; just for the sample
26
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')
27
//
28
29
-- Note that you can even put more than 1 SQL query without DELIMITER
30
-- In this case, the updater will consider them as 1 query.
31
-- That can be usefull if you want to do a logical grouping
32
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');
33
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');
34
//
35
-- End of complex sample

Return to bug 7167