PDOException Object
(
    [message:protected] => SQLSTATE[42S21]: Column already exists: 1060 Duplicate column name 'affiliate_discount'
    [string:Exception:private] => 
    [code:protected] => 42S21
    [file:protected] => /home/herbalf/public_html/lib/Zend/Db/Statement/Pdo.php
    [line:protected] => 228
    [trace:Exception:private] => Array
        (
            [0] => Array
                (
                    [file] => /home/herbalf/public_html/lib/Zend/Db/Statement/Pdo.php
                    [line] => 228
                    [function] => execute
                    [class] => PDOStatement
                    [type] => ->
                    [args] => Array
                        (
                            [0] => Array
                                (
                                )

                        )

                )

            [1] => Array
                (
                    [file] => /home/herbalf/public_html/lib/Varien/Db/Statement/Pdo/Mysql.php
                    [line] => 110
                    [function] => _execute
                    [class] => Zend_Db_Statement_Pdo
                    [type] => ->
                    [args] => Array
                        (
                            [0] => Array
                                (
                                )

                        )

                )

            [2] => Array
                (
                    [file] => /home/herbalf/public_html/app/code/core/Zend/Db/Statement.php
                    [line] => 291
                    [function] => _execute
                    [class] => Varien_Db_Statement_Pdo_Mysql
                    [type] => ->
                    [args] => Array
                        (
                            [0] => Array
                                (
                                )

                        )

                )

            [3] => Array
                (
                    [file] => /home/herbalf/public_html/lib/Zend/Db/Adapter/Abstract.php
                    [line] => 479
                    [function] => execute
                    [class] => Zend_Db_Statement
                    [type] => ->
                    [args] => Array
                        (
                            [0] => Array
                                (
                                )

                        )

                )

            [4] => Array
                (
                    [file] => /home/herbalf/public_html/lib/Zend/Db/Adapter/Pdo/Abstract.php
                    [line] => 238
                    [function] => query
                    [class] => Zend_Db_Adapter_Abstract
                    [type] => ->
                    [args] => Array
                        (
                            [0] => ALTER TABLE mag_sales_flat_order
  ADD COLUMN `affiliate_discount` decimal(12,4) default NULL,
  ADD COLUMN `base_affiliate_discount` decimal(12,4) default NULL
                            [1] => Array
                                (
                                )

                        )

                )

            [5] => Array
                (
                    [file] => /home/herbalf/public_html/lib/Varien/Db/Adapter/Pdo/Mysql.php
                    [line] => 428
                    [function] => query
                    [class] => Zend_Db_Adapter_Pdo_Abstract
                    [type] => ->
                    [args] => Array
                        (
                            [0] => ALTER TABLE mag_sales_flat_order
  ADD COLUMN `affiliate_discount` decimal(12,4) default NULL,
  ADD COLUMN `base_affiliate_discount` decimal(12,4) default NULL
                            [1] => Array
                                (
                                )

                        )

                )

            [6] => Array
                (
                    [file] => /home/herbalf/public_html/lib/Varien/Db/Adapter/Pdo/Mysql.php
                    [line] => 347
                    [function] => query
                    [class] => Varien_Db_Adapter_Pdo_Mysql
                    [type] => ->
                    [args] => Array
                        (
                            [0] => ALTER TABLE mag_sales_flat_order
  ADD COLUMN `affiliate_discount` decimal(12,4) default NULL,
  ADD COLUMN `base_affiliate_discount` decimal(12,4) default NULL
                        )

                )

            [7] => Array
                (
                    [file] => /home/herbalf/public_html/lib/Varien/Db/Adapter/Pdo/Mysql.php
                    [line] => 617
                    [function] => raw_query
                    [class] => Varien_Db_Adapter_Pdo_Mysql
                    [type] => ->
                    [args] => Array
                        (
                            [0] => ALTER TABLE mag_sales_flat_order
  ADD COLUMN `affiliate_discount` decimal(12,4) default NULL,
  ADD COLUMN `base_affiliate_discount` decimal(12,4) default NULL
                        )

                )

            [8] => Array
                (
                    [file] => /home/herbalf/public_html/lib/Varien/Db/Adapter/Pdo/Mysql.php
                    [line] => 599
                    [function] => multi_query
                    [class] => Varien_Db_Adapter_Pdo_Mysql
                    [type] => ->
                    [args] => Array
                        (
                            [0] => 

DROP TABLE IF EXISTS mag_affiliate_referer;
DROP TABLE IF EXISTS mag_affiliate_payment_paypal;
DROP TABLE IF EXISTS mag_affiliate_payment;
DROP TABLE IF EXISTS mag_affiliate_transaction;
DROP TABLE IF EXISTS mag_affiliate_banner_value;
DROP TABLE IF EXISTS mag_affiliate_banner;
DROP TABLE IF EXISTS mag_affiliate_account_value;
DROP TABLE IF EXISTS mag_affiliate_account;

CREATE TABLE mag_affiliate_account(
  `account_id` int(10) unsigned NOT NULL auto_increment,
  `customer_id` int(10) unsigned NOT NULL,
  `address_id` int(10) unsigned NOT NULL default '0',
  `identify_code` varchar(63) NOT NULL default '',
  `name` varchar(255) NOT NULL default '',
  `email` varchar(255) NOT NULL default '',
  `balance` decimal(12,4) NOT NULL default '0',
  `total_commission_received` decimal(12,4) NOT NULL default '0',
  `total_paid` decimal(12,4) NOT NULL default '0',
  `total_clicks` int(11) NOT NULL default '0',
  `unique_clicks` int(11) NOT NULL default '0',
  `paypal_email` varchar(255) NOT NULL default '',
  `created_time` datetime NOT NULL default '0000-00-00 00:00:00',
  `status` tinyint(1) NOT NULL default '2',
  `approved` tinyint(1) NOT NULL default '2',
  UNIQUE(`customer_id`),
  UNIQUE(`identify_code`),
  INDEX(`customer_id`),
  FOREIGN KEY (`customer_id`) REFERENCES mag_customer_entity(`entity_id`) ON DELETE CASCADE ON UPDATE CASCADE,
  PRIMARY KEY (`account_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE mag_affiliate_account_value(
  `value_id` int(10) unsigned NOT NULL auto_increment,
  `account_id` int(10) unsigned NOT NULL,
  `store_id` smallint(5) unsigned  NOT NULL,
  `attribute_code` varchar(63) NOT NULL default '',
  `value` text NOT NULL,
  UNIQUE(`account_id`,`store_id`,`attribute_code`),
  INDEX (`account_id`),
  INDEX (`store_id`),
  FOREIGN KEY (`account_id`) REFERENCES mag_affiliate_account (`account_id`) ON DELETE CASCADE ON UPDATE CASCADE,
  FOREIGN KEY (`store_id`) REFERENCES mag_core_store (`store_id`) ON DELETE CASCADE ON UPDATE CASCADE,
  PRIMARY KEY (`value_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE mag_affiliate_banner(
  `banner_id` int(10) unsigned NOT NULL auto_increment,
  `title` varchar(255) NOT NULL default '',
  `type_id` tinyint(1) NOT NULL default '1',
  `source_file` varchar(255) NOT NULL default '',
  `width` int(11) NOT NULL,
  `height` int(11) NOT NULL,
  `link` varchar(255) NOT NULL,
  `status` tinyint(1) NOT NULL default '1',
  PRIMARY KEY (`banner_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE mag_affiliate_banner_value(
  `value_id` int(10) unsigned NOT NULL auto_increment,
  `banner_id` int(10) unsigned NOT NULL,
  `store_id` smallint(5) unsigned  NOT NULL,
  `attribute_code` varchar(63) NOT NULL default '',
  `value` text NOT NULL,
  UNIQUE(`banner_id`,`store_id`,`attribute_code`),
  INDEX (`banner_id`),
  INDEX (`store_id`),
  FOREIGN KEY (`banner_id`) REFERENCES mag_affiliate_banner (`banner_id`) ON DELETE CASCADE ON UPDATE CASCADE,
  FOREIGN KEY (`store_id`) REFERENCES mag_core_store (`store_id`) ON DELETE CASCADE ON UPDATE CASCADE,
  PRIMARY KEY (`value_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE mag_affiliate_transaction(
  `transaction_id` int(10) unsigned NOT NULL auto_increment,
  `account_id` int(10) unsigned NOT NULL,
  `account_name` varchar(255) NOT NULL default '',
  `account_email` varchar(255)  NOT NULL,
  `customer_id` int(10) unsigned  NOT NULL,
  `customer_email` varchar(255)  NOT NULL,
  `order_id` int(10) unsigned  NOT NULL,
  `order_number` varchar(50) default '',
  `order_item_ids` text default '',
  `order_item_names` text default '',
  `total_amount` decimal(12,4) NOT NULL default '0',
  `commission` decimal(12,4) NOT NULL default '0',
  `discount` decimal(12,4) NOT NULL default '0',
  `created_time` datetime NULL,
  `status` tinyint(1) NOT NULL default '1',
  `store_id` smallint(5) unsigned  NOT NULL,
  INDEX(`account_id`),
  INDEX(`store_id`),
  FOREIGN KEY (`account_id`) REFERENCES mag_affiliate_account (`account_id`) ON DELETE CASCADE ON UPDATE CASCADE,
  FOREIGN KEY (`store_id`) REFERENCES mag_core_store (`store_id`) ON DELETE CASCADE ON UPDATE CASCADE,
  PRIMARY KEY (`transaction_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE mag_affiliate_payment(
  `payment_id` int(10) unsigned NOT NULL auto_increment,
  `account_id` int(10) unsigned  NOT NULL,
  `account_name` varchar(255) NOT NULL,
  `account_email` varchar(255) NOT NULL,
  `payment_method` varchar(63) NOT NULL default '',
  `amount` decimal(12,4) NOT NULL default '0',
  `fee` decimal(12,4) NOT NULL default '0',
  `request_time` datetime NULL,
  `status` tinyint(1) NOT NULL default '1',
  `description` text NOT NULL,
  `store_ids` text NOT NULL,
  `is_request` tinyint(1) NOT NULL default '1',
  `is_payer_fee` tinyint(1) NOT NULL default '1',
  INDEX(`account_id`),
  FOREIGN KEY (`account_id`) REFERENCES mag_affiliate_account (`account_id`) ON DELETE CASCADE ON UPDATE CASCADE,
  PRIMARY KEY (`payment_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE mag_affiliate_payment_paypal(
  `payment_paypal_id` int(10) unsigned NOT NULL auto_increment,
  `payment_id` int(10) unsigned NOT NULL,
  `email` varchar(255) NOT NULL default '',
  `transaction_id` varchar(255) NOT NULL default '',
  `description` text NOT NULL default '',
  INDEX(`payment_id`),
  FOREIGN KEY (`payment_id`) REFERENCES mag_affiliate_payment (`payment_id`) ON DELETE CASCADE ON UPDATE CASCADE,
  PRIMARY KEY (`payment_paypal_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE mag_affiliate_referer(
  `referer_id` int(10) unsigned NOT NULL auto_increment,
  `account_id` int(10) unsigned NOT NULL,
  `referer` varchar(255) NOT NULL default '',
  `url_path` varchar(255) NOT NULL default '/',
  `total_clicks` int(11) NOT NULL default '0',
  `unique_clicks` int(11) NOT NULL default '0',
  `ip_list` longtext NOT NULL default '',
  `store_id` smallint(5) unsigned  NOT NULL,
  INDEX(`account_id`),
  INDEX(`store_id`),
  FOREIGN KEY (`account_id`) REFERENCES mag_affiliate_account (`account_id`) ON DELETE CASCADE ON UPDATE CASCADE,
  FOREIGN KEY (`store_id`) REFERENCES mag_core_store (`store_id`) ON DELETE CASCADE ON UPDATE CASCADE,
  PRIMARY KEY (`referer_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

ALTER TABLE mag_sales_flat_order
  ADD COLUMN `affiliate_discount` decimal(12,4) default NULL,
  ADD COLUMN `base_affiliate_discount` decimal(12,4) default NULL;


                        )

                )

            [9] => Array
                (
                    [file] => /home/herbalf/public_html/app/code/core/Mage/Core/Model/Resource/Setup.php
                    [line] => 933
                    [function] => multiQuery
                    [class] => Varien_Db_Adapter_Pdo_Mysql
                    [type] => ->
                    [args] => Array
                        (
                            [0] => 

DROP TABLE IF EXISTS mag_affiliate_referer;
DROP TABLE IF EXISTS mag_affiliate_payment_paypal;
DROP TABLE IF EXISTS mag_affiliate_payment;
DROP TABLE IF EXISTS mag_affiliate_transaction;
DROP TABLE IF EXISTS mag_affiliate_banner_value;
DROP TABLE IF EXISTS mag_affiliate_banner;
DROP TABLE IF EXISTS mag_affiliate_account_value;
DROP TABLE IF EXISTS mag_affiliate_account;

CREATE TABLE mag_affiliate_account(
  `account_id` int(10) unsigned NOT NULL auto_increment,
  `customer_id` int(10) unsigned NOT NULL,
  `address_id` int(10) unsigned NOT NULL default '0',
  `identify_code` varchar(63) NOT NULL default '',
  `name` varchar(255) NOT NULL default '',
  `email` varchar(255) NOT NULL default '',
  `balance` decimal(12,4) NOT NULL default '0',
  `total_commission_received` decimal(12,4) NOT NULL default '0',
  `total_paid` decimal(12,4) NOT NULL default '0',
  `total_clicks` int(11) NOT NULL default '0',
  `unique_clicks` int(11) NOT NULL default '0',
  `paypal_email` varchar(255) NOT NULL default '',
  `created_time` datetime NOT NULL default '0000-00-00 00:00:00',
  `status` tinyint(1) NOT NULL default '2',
  `approved` tinyint(1) NOT NULL default '2',
  UNIQUE(`customer_id`),
  UNIQUE(`identify_code`),
  INDEX(`customer_id`),
  FOREIGN KEY (`customer_id`) REFERENCES mag_customer_entity(`entity_id`) ON DELETE CASCADE ON UPDATE CASCADE,
  PRIMARY KEY (`account_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE mag_affiliate_account_value(
  `value_id` int(10) unsigned NOT NULL auto_increment,
  `account_id` int(10) unsigned NOT NULL,
  `store_id` smallint(5) unsigned  NOT NULL,
  `attribute_code` varchar(63) NOT NULL default '',
  `value` text NOT NULL,
  UNIQUE(`account_id`,`store_id`,`attribute_code`),
  INDEX (`account_id`),
  INDEX (`store_id`),
  FOREIGN KEY (`account_id`) REFERENCES mag_affiliate_account (`account_id`) ON DELETE CASCADE ON UPDATE CASCADE,
  FOREIGN KEY (`store_id`) REFERENCES mag_core_store (`store_id`) ON DELETE CASCADE ON UPDATE CASCADE,
  PRIMARY KEY (`value_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE mag_affiliate_banner(
  `banner_id` int(10) unsigned NOT NULL auto_increment,
  `title` varchar(255) NOT NULL default '',
  `type_id` tinyint(1) NOT NULL default '1',
  `source_file` varchar(255) NOT NULL default '',
  `width` int(11) NOT NULL,
  `height` int(11) NOT NULL,
  `link` varchar(255) NOT NULL,
  `status` tinyint(1) NOT NULL default '1',
  PRIMARY KEY (`banner_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE mag_affiliate_banner_value(
  `value_id` int(10) unsigned NOT NULL auto_increment,
  `banner_id` int(10) unsigned NOT NULL,
  `store_id` smallint(5) unsigned  NOT NULL,
  `attribute_code` varchar(63) NOT NULL default '',
  `value` text NOT NULL,
  UNIQUE(`banner_id`,`store_id`,`attribute_code`),
  INDEX (`banner_id`),
  INDEX (`store_id`),
  FOREIGN KEY (`banner_id`) REFERENCES mag_affiliate_banner (`banner_id`) ON DELETE CASCADE ON UPDATE CASCADE,
  FOREIGN KEY (`store_id`) REFERENCES mag_core_store (`store_id`) ON DELETE CASCADE ON UPDATE CASCADE,
  PRIMARY KEY (`value_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE mag_affiliate_transaction(
  `transaction_id` int(10) unsigned NOT NULL auto_increment,
  `account_id` int(10) unsigned NOT NULL,
  `account_name` varchar(255) NOT NULL default '',
  `account_email` varchar(255)  NOT NULL,
  `customer_id` int(10) unsigned  NOT NULL,
  `customer_email` varchar(255)  NOT NULL,
  `order_id` int(10) unsigned  NOT NULL,
  `order_number` varchar(50) default '',
  `order_item_ids` text default '',
  `order_item_names` text default '',
  `total_amount` decimal(12,4) NOT NULL default '0',
  `commission` decimal(12,4) NOT NULL default '0',
  `discount` decimal(12,4) NOT NULL default '0',
  `created_time` datetime NULL,
  `status` tinyint(1) NOT NULL default '1',
  `store_id` smallint(5) unsigned  NOT NULL,
  INDEX(`account_id`),
  INDEX(`store_id`),
  FOREIGN KEY (`account_id`) REFERENCES mag_affiliate_account (`account_id`) ON DELETE CASCADE ON UPDATE CASCADE,
  FOREIGN KEY (`store_id`) REFERENCES mag_core_store (`store_id`) ON DELETE CASCADE ON UPDATE CASCADE,
  PRIMARY KEY (`transaction_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE mag_affiliate_payment(
  `payment_id` int(10) unsigned NOT NULL auto_increment,
  `account_id` int(10) unsigned  NOT NULL,
  `account_name` varchar(255) NOT NULL,
  `account_email` varchar(255) NOT NULL,
  `payment_method` varchar(63) NOT NULL default '',
  `amount` decimal(12,4) NOT NULL default '0',
  `fee` decimal(12,4) NOT NULL default '0',
  `request_time` datetime NULL,
  `status` tinyint(1) NOT NULL default '1',
  `description` text NOT NULL,
  `store_ids` text NOT NULL,
  `is_request` tinyint(1) NOT NULL default '1',
  `is_payer_fee` tinyint(1) NOT NULL default '1',
  INDEX(`account_id`),
  FOREIGN KEY (`account_id`) REFERENCES mag_affiliate_account (`account_id`) ON DELETE CASCADE ON UPDATE CASCADE,
  PRIMARY KEY (`payment_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE mag_affiliate_payment_paypal(
  `payment_paypal_id` int(10) unsigned NOT NULL auto_increment,
  `payment_id` int(10) unsigned NOT NULL,
  `email` varchar(255) NOT NULL default '',
  `transaction_id` varchar(255) NOT NULL default '',
  `description` text NOT NULL default '',
  INDEX(`payment_id`),
  FOREIGN KEY (`payment_id`) REFERENCES mag_affiliate_payment (`payment_id`) ON DELETE CASCADE ON UPDATE CASCADE,
  PRIMARY KEY (`payment_paypal_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE mag_affiliate_referer(
  `referer_id` int(10) unsigned NOT NULL auto_increment,
  `account_id` int(10) unsigned NOT NULL,
  `referer` varchar(255) NOT NULL default '',
  `url_path` varchar(255) NOT NULL default '/',
  `total_clicks` int(11) NOT NULL default '0',
  `unique_clicks` int(11) NOT NULL default '0',
  `ip_list` longtext NOT NULL default '',
  `store_id` smallint(5) unsigned  NOT NULL,
  INDEX(`account_id`),
  INDEX(`store_id`),
  FOREIGN KEY (`account_id`) REFERENCES mag_affiliate_account (`account_id`) ON DELETE CASCADE ON UPDATE CASCADE,
  FOREIGN KEY (`store_id`) REFERENCES mag_core_store (`store_id`) ON DELETE CASCADE ON UPDATE CASCADE,
  PRIMARY KEY (`referer_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

ALTER TABLE mag_sales_flat_order
  ADD COLUMN `affiliate_discount` decimal(12,4) default NULL,
  ADD COLUMN `base_affiliate_discount` decimal(12,4) default NULL;


                        )

                )

            [10] => Array
                (
                    [file] => /home/herbalf/public_html/app/code/local/Magegiant/Affiliate/sql/affiliate_setup/mysql4-install-0.1.0.php
                    [line] => 155
                    [function] => run
                    [class] => Mage_Core_Model_Resource_Setup
                    [type] => ->
                    [args] => Array
                        (
                            [0] => 

DROP TABLE IF EXISTS mag_affiliate_referer;
DROP TABLE IF EXISTS mag_affiliate_payment_paypal;
DROP TABLE IF EXISTS mag_affiliate_payment;
DROP TABLE IF EXISTS mag_affiliate_transaction;
DROP TABLE IF EXISTS mag_affiliate_banner_value;
DROP TABLE IF EXISTS mag_affiliate_banner;
DROP TABLE IF EXISTS mag_affiliate_account_value;
DROP TABLE IF EXISTS mag_affiliate_account;

CREATE TABLE mag_affiliate_account(
  `account_id` int(10) unsigned NOT NULL auto_increment,
  `customer_id` int(10) unsigned NOT NULL,
  `address_id` int(10) unsigned NOT NULL default '0',
  `identify_code` varchar(63) NOT NULL default '',
  `name` varchar(255) NOT NULL default '',
  `email` varchar(255) NOT NULL default '',
  `balance` decimal(12,4) NOT NULL default '0',
  `total_commission_received` decimal(12,4) NOT NULL default '0',
  `total_paid` decimal(12,4) NOT NULL default '0',
  `total_clicks` int(11) NOT NULL default '0',
  `unique_clicks` int(11) NOT NULL default '0',
  `paypal_email` varchar(255) NOT NULL default '',
  `created_time` datetime NOT NULL default '0000-00-00 00:00:00',
  `status` tinyint(1) NOT NULL default '2',
  `approved` tinyint(1) NOT NULL default '2',
  UNIQUE(`customer_id`),
  UNIQUE(`identify_code`),
  INDEX(`customer_id`),
  FOREIGN KEY (`customer_id`) REFERENCES mag_customer_entity(`entity_id`) ON DELETE CASCADE ON UPDATE CASCADE,
  PRIMARY KEY (`account_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE mag_affiliate_account_value(
  `value_id` int(10) unsigned NOT NULL auto_increment,
  `account_id` int(10) unsigned NOT NULL,
  `store_id` smallint(5) unsigned  NOT NULL,
  `attribute_code` varchar(63) NOT NULL default '',
  `value` text NOT NULL,
  UNIQUE(`account_id`,`store_id`,`attribute_code`),
  INDEX (`account_id`),
  INDEX (`store_id`),
  FOREIGN KEY (`account_id`) REFERENCES mag_affiliate_account (`account_id`) ON DELETE CASCADE ON UPDATE CASCADE,
  FOREIGN KEY (`store_id`) REFERENCES mag_core_store (`store_id`) ON DELETE CASCADE ON UPDATE CASCADE,
  PRIMARY KEY (`value_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE mag_affiliate_banner(
  `banner_id` int(10) unsigned NOT NULL auto_increment,
  `title` varchar(255) NOT NULL default '',
  `type_id` tinyint(1) NOT NULL default '1',
  `source_file` varchar(255) NOT NULL default '',
  `width` int(11) NOT NULL,
  `height` int(11) NOT NULL,
  `link` varchar(255) NOT NULL,
  `status` tinyint(1) NOT NULL default '1',
  PRIMARY KEY (`banner_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE mag_affiliate_banner_value(
  `value_id` int(10) unsigned NOT NULL auto_increment,
  `banner_id` int(10) unsigned NOT NULL,
  `store_id` smallint(5) unsigned  NOT NULL,
  `attribute_code` varchar(63) NOT NULL default '',
  `value` text NOT NULL,
  UNIQUE(`banner_id`,`store_id`,`attribute_code`),
  INDEX (`banner_id`),
  INDEX (`store_id`),
  FOREIGN KEY (`banner_id`) REFERENCES mag_affiliate_banner (`banner_id`) ON DELETE CASCADE ON UPDATE CASCADE,
  FOREIGN KEY (`store_id`) REFERENCES mag_core_store (`store_id`) ON DELETE CASCADE ON UPDATE CASCADE,
  PRIMARY KEY (`value_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE mag_affiliate_transaction(
  `transaction_id` int(10) unsigned NOT NULL auto_increment,
  `account_id` int(10) unsigned NOT NULL,
  `account_name` varchar(255) NOT NULL default '',
  `account_email` varchar(255)  NOT NULL,
  `customer_id` int(10) unsigned  NOT NULL,
  `customer_email` varchar(255)  NOT NULL,
  `order_id` int(10) unsigned  NOT NULL,
  `order_number` varchar(50) default '',
  `order_item_ids` text default '',
  `order_item_names` text default '',
  `total_amount` decimal(12,4) NOT NULL default '0',
  `commission` decimal(12,4) NOT NULL default '0',
  `discount` decimal(12,4) NOT NULL default '0',
  `created_time` datetime NULL,
  `status` tinyint(1) NOT NULL default '1',
  `store_id` smallint(5) unsigned  NOT NULL,
  INDEX(`account_id`),
  INDEX(`store_id`),
  FOREIGN KEY (`account_id`) REFERENCES mag_affiliate_account (`account_id`) ON DELETE CASCADE ON UPDATE CASCADE,
  FOREIGN KEY (`store_id`) REFERENCES mag_core_store (`store_id`) ON DELETE CASCADE ON UPDATE CASCADE,
  PRIMARY KEY (`transaction_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE mag_affiliate_payment(
  `payment_id` int(10) unsigned NOT NULL auto_increment,
  `account_id` int(10) unsigned  NOT NULL,
  `account_name` varchar(255) NOT NULL,
  `account_email` varchar(255) NOT NULL,
  `payment_method` varchar(63) NOT NULL default '',
  `amount` decimal(12,4) NOT NULL default '0',
  `fee` decimal(12,4) NOT NULL default '0',
  `request_time` datetime NULL,
  `status` tinyint(1) NOT NULL default '1',
  `description` text NOT NULL,
  `store_ids` text NOT NULL,
  `is_request` tinyint(1) NOT NULL default '1',
  `is_payer_fee` tinyint(1) NOT NULL default '1',
  INDEX(`account_id`),
  FOREIGN KEY (`account_id`) REFERENCES mag_affiliate_account (`account_id`) ON DELETE CASCADE ON UPDATE CASCADE,
  PRIMARY KEY (`payment_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE mag_affiliate_payment_paypal(
  `payment_paypal_id` int(10) unsigned NOT NULL auto_increment,
  `payment_id` int(10) unsigned NOT NULL,
  `email` varchar(255) NOT NULL default '',
  `transaction_id` varchar(255) NOT NULL default '',
  `description` text NOT NULL default '',
  INDEX(`payment_id`),
  FOREIGN KEY (`payment_id`) REFERENCES mag_affiliate_payment (`payment_id`) ON DELETE CASCADE ON UPDATE CASCADE,
  PRIMARY KEY (`payment_paypal_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE mag_affiliate_referer(
  `referer_id` int(10) unsigned NOT NULL auto_increment,
  `account_id` int(10) unsigned NOT NULL,
  `referer` varchar(255) NOT NULL default '',
  `url_path` varchar(255) NOT NULL default '/',
  `total_clicks` int(11) NOT NULL default '0',
  `unique_clicks` int(11) NOT NULL default '0',
  `ip_list` longtext NOT NULL default '',
  `store_id` smallint(5) unsigned  NOT NULL,
  INDEX(`account_id`),
  INDEX(`store_id`),
  FOREIGN KEY (`account_id`) REFERENCES mag_affiliate_account (`account_id`) ON DELETE CASCADE ON UPDATE CASCADE,
  FOREIGN KEY (`store_id`) REFERENCES mag_core_store (`store_id`) ON DELETE CASCADE ON UPDATE CASCADE,
  PRIMARY KEY (`referer_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

ALTER TABLE mag_sales_flat_order
  ADD COLUMN `affiliate_discount` decimal(12,4) default NULL,
  ADD COLUMN `base_affiliate_discount` decimal(12,4) default NULL;


                        )

                )

            [11] => Array
                (
                    [file] => /home/herbalf/public_html/app/code/core/Mage/Core/Model/Resource/Setup.php
                    [line] => 624
                    [args] => Array
                        (
                            [0] => /home/herbalf/public_html/app/code/local/Magegiant/Affiliate/sql/affiliate_setup/mysql4-install-0.1.0.php
                        )

                    [function] => include
                )

            [12] => Array
                (
                    [file] => /home/herbalf/public_html/app/code/core/Mage/Core/Model/Resource/Setup.php
                    [line] => 421
                    [function] => _modifyResourceDb
                    [class] => Mage_Core_Model_Resource_Setup
                    [type] => ->
                    [args] => Array
                        (
                            [0] => install
                            [1] => 
                            [2] => 0.4.0
                        )

                )

            [13] => Array
                (
                    [file] => /home/herbalf/public_html/app/code/core/Mage/Core/Model/Resource/Setup.php
                    [line] => 327
                    [function] => _installResourceDb
                    [class] => Mage_Core_Model_Resource_Setup
                    [type] => ->
                    [args] => Array
                        (
                            [0] => 0.4.0
                        )

                )

            [14] => Array
                (
                    [file] => /home/herbalf/public_html/app/code/core/Mage/Core/Model/Resource/Setup.php
                    [line] => 235
                    [function] => applyUpdates
                    [class] => Mage_Core_Model_Resource_Setup
                    [type] => ->
                    [args] => Array
                        (
                        )

                )

            [15] => Array
                (
                    [file] => /home/herbalf/public_html/app/code/core/Mage/Core/Model/App.php
                    [line] => 417
                    [function] => applyAllUpdates
                    [class] => Mage_Core_Model_Resource_Setup
                    [type] => ::
                    [args] => Array
                        (
                        )

                )

            [16] => Array
                (
                    [file] => /home/herbalf/public_html/app/code/core/Mage/Core/Model/App.php
                    [line] => 343
                    [function] => _initModules
                    [class] => Mage_Core_Model_App
                    [type] => ->
                    [args] => Array
                        (
                        )

                )

            [17] => Array
                (
                    [file] => /home/herbalf/public_html/app/Mage.php
                    [line] => 683
                    [function] => run
                    [class] => Mage_Core_Model_App
                    [type] => ->
                    [args] => Array
                        (
                            [0] => Array
                                (
                                    [scope_code] => 
                                    [scope_type] => store
                                    [options] => Array
                                        (
                                        )

                                )

                        )

                )

            [18] => Array
                (
                    [file] => /home/herbalf/public_html/index.php
                    [line] => 87
                    [function] => run
                    [class] => Mage
                    [type] => ::
                    [args] => Array
                        (
                            [0] => 
                            [1] => store
                        )

                )

        )

    [previous:Exception:private] => 
    [errorInfo] => Array
        (
            [0] => 42S21
            [1] => 1060
            [2] => Duplicate column name 'affiliate_discount'
        )

)