Permalink
Browse files

DB new upgrade system.

  • Loading branch information...
1 parent f0b2c1c commit 46bbbb4c850a221d9ba907780c02da66a8d11da7 ethem committed Feb 15, 2006
@@ -8,10 +8,13 @@ function authorize_upgrade($oldversion=0) {
$result = true;
- if ($oldversion == 0) {
- modify_database("$CFG->dirroot/enrol/authorize/db/mysql.sql");
+ if ($oldversion == 0) { // First time install
+ $result = modify_database("$CFG->dirroot/enrol/authorize/db/mysql.sql");
+ return $result; // RETURN, sql file contains last upgrades.
}
+ // Authorize module was installed before. Upgrades must be applied to SQL file.
+
if ($oldversion < 2005071600) {
// Be sure, only last 4 digit is inserted.
table_column('enrol_authorize', 'cclastfour', 'cclastfour', 'integer', '4', 'unsigned', '0', 'not null');
@@ -39,7 +42,7 @@ function authorize_upgrade($oldversion=0) {
// new fields for refund and sales reports.
$defaultcurrency = empty($CFG->enrol_currency) ? 'USD' : $CFG->enrol_currency;
table_column('enrol_authorize', '', 'amount', 'varchar', '10', '', '0', 'not null', 'timeupdated');
- table_column('enrol_authorize', '', 'currency', 'char', '3', '', $defaultcurrency, 'not null', 'amount');
+ table_column('enrol_authorize', '', 'currency', 'varchar', '3', '', $defaultcurrency, 'not null', 'amount');
modify_database("","CREATE TABLE prefix_enrol_authorize_refunds (
`id` int(10) unsigned NOT NULL auto_increment,
`orderid` int(10) unsigned NOT NULL default 0,
@@ -98,6 +101,10 @@ function authorize_upgrade($oldversion=0) {
}
}
+ if ($oldversion < 2006021500) { // transid is int
+ table_column('enrol_authorize', 'transid', 'transid', 'integer', '10', 'unsigned', '0', 'not null');
+ }
+
return $result;
}
@@ -1,12 +1,28 @@
-CREATE TABLE `prefix_enrol_authorize` (
- `id` int(10) unsigned NOT NULL auto_increment,
- `cclastfour` int(11) default '0',
- `ccexp` varchar(6) default '',
- `cvv` varchar(4) default '',
- `ccname` varchar(255) default '',
- `courseid` int(11) NOT NULL default '0',
- `userid` int(11) NOT NULL default '0',
- `avscode` char(1) default 'P',
- `transid` varchar(255) default '',
- PRIMARY KEY (`id`)
-) TYPE=MyISAM COMMENT='Holds all known information about authorize.net transactions';
+CREATE TABLE `prefix_enrol_authorize` (
+ `id` int(10) unsigned NOT NULL auto_increment,
+ `cclastfour` int(4) unsigned NOT NULL default '0',
+ `ccname` varchar(255) NOT NULL default '',
+ `courseid` int(10) unsigned NOT NULL default '0',
+ `userid` int(10) unsigned NOT NULL default '0',
+ `transid` int(10) unsigned NOT NULL default '0',
+ `status` int(10) unsigned NOT NULL default '0',
+ `timecreated` int(10) unsigned NOT NULL default '0',
+ `settletime` int(10) unsigned NOT NULL default '0',
+ `amount` varchar(10) NOT NULL default '',
+ `currency` varchar(3) NOT NULL default 'USD',
+ PRIMARY KEY (`id`),
+ KEY `courseid` (`courseid`),
+ KEY `userid` (`userid`),
+ KEY `status` (`status`)
+) ENGINE=MyISAM COMMENT='Holds all known information about authorize.net transactions';
+
+CREATE TABLE `prefix_enrol_authorize_refunds` (
+ `id` int(10) unsigned NOT NULL auto_increment,
+ `orderid` int(10) unsigned NOT NULL default '0',
+ `status` int(1) unsigned NOT NULL default '0',
+ `amount` varchar(10) NOT NULL default '',
+ `transid` int(10) unsigned default '0',
+ `settletime` int(10) unsigned NOT NULL default '0',
+ PRIMARY KEY (`id`),
+ KEY `orderid` (`orderid`)
+) ENGINE=MyISAM;
@@ -8,10 +8,13 @@ function authorize_upgrade($oldversion=0) {
$result = true;
- if ($oldversion == 0) {
- modify_database("$CFG->dirroot/enrol/authorize/db/postgres7.sql");
+ if ($oldversion == 0) { // First time install
+ $result = modify_database("$CFG->dirroot/enrol/authorize/db/postgres7.sql");
+ return $result; // RETURN, sql file contains last upgrades.
}
+ // Authorize module was installed before. Upgrades must be applied to SQL file.
+
if ($oldversion < 2005080200) {
// Be sure, only last 4 digit is inserted.
table_column('enrol_authorize', 'cclastfour', 'cclastfour', 'integer', '4', 'unsigned', '0', 'not null');
@@ -39,7 +42,7 @@ function authorize_upgrade($oldversion=0) {
// new fields for refund and sales reports.
$defaultcurrency = empty($CFG->enrol_currency) ? 'USD' : $CFG->enrol_currency;
table_column('enrol_authorize', '', 'amount', 'varchar', '10', '', '0', 'not null', 'timeupdated');
- table_column('enrol_authorize', '', 'currency', 'char', '3', '', $defaultcurrency, 'not null', 'amount');
+ table_column('enrol_authorize', '', 'currency', 'varchar', '3', '', $defaultcurrency, 'not null', 'amount');
modify_database("","CREATE TABLE prefix_enrol_authorize_refunds (
id SERIAL PRIMARY KEY,
orderid INTEGER NOT NULL default 0,
@@ -98,6 +101,10 @@ function authorize_upgrade($oldversion=0) {
}
}
+ if ($oldversion < 2006021500) { // transid is int
+ table_column('enrol_authorize', 'transid', 'transid', 'integer', '10', 'unsigned', '0', 'not null');
+ }
+
return $result;
}
@@ -1,11 +1,28 @@
CREATE TABLE prefix_enrol_authorize (
- id SERIAL PRIMARY KEY,
- cclastfour integer default '0',
- ccexp varchar(6) default '',
- cvv varchar(4) default '',
- ccname varchar(255) default '',
- courseid integer NOT NULL default '0',
- userid integer NOT NULL default '0',
- avscode varchar(1) default 'P',
- transid varchar(255) default ''
-);
+ id SERIAL PRIMARY KEY,
+ cclastfour integer DEFAULT 0 NOT NULL,
+ ccname varchar(255) DEFAULT '',
+ courseid integer DEFAULT 0 NOT NULL,
+ userid integer DEFAULT 0 NOT NULL,
+ transid integer DEFAULT 0 NOT NULL,
+ status integer DEFAULT 0 NOT NULL,
+ timecreated integer DEFAULT 0 NOT NULL,
+ settletime integer DEFAULT 0 NOT NULL,
+ amount varchar(10) DEFAULT '0',
+ currency varchar(3) DEFAULT 'USD' NOT NULL
+);
+
+CREATE INDEX prefix_enrol_authorize_courseid_idx ON prefix_enrol_authorize(courseid);
+CREATE INDEX prefix_enrol_authorize_userid_idx ON prefix_enrol_authorize(userid);
+CREATE INDEX prefix_enrol_authorize_status_idx ON prefix_enrol_authorize(status);
+
+CREATE TABLE prefix_enrol_authorize_refunds (
+ id SERIAL PRIMARY KEY,
+ orderid integer DEFAULT 0 NOT NULL,
+ status integer DEFAULT 0 NOT NULL,
+ amount varchar(10) DEFAULT '' NOT NULL,
+ transid integer DEFAULT 0,
+ settletime integer DEFAULT 0 NOT NULL
+);
+
+CREATE INDEX prefix_enrol_authorize_refunds_orderid_idx ON prefix_enrol_authorize_refunds(orderid);
@@ -1,6 +1,6 @@
<?PHP // $Id$
-$module->version = 2006020100;
+$module->version = 2006021500;
$module->requires = 2005072200;
?>

0 comments on commit 46bbbb4

Please sign in to comment.