
# This is a fix for InnoDB in MySQL >= 4.1.x
# It "suspends judgement" for fkey relationships until are tables are set.
SET FOREIGN_KEY_CHECKS = 0;

#-----------------------------------------------------------------------------
#-- paypal_transaction
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `paypal_transaction`;


CREATE TABLE `paypal_transaction`
(
	`ptid` INTEGER(11)  NOT NULL AUTO_INCREMENT,
	`taid` INTEGER(11),
	`transaction_type` VARCHAR(255)  NOT NULL,
	`transaction_id` VARCHAR(255)  NOT NULL,
	`uid` INTEGER(11)  NOT NULL,
	`payer_id` VARCHAR(255)  NOT NULL,
	`payer_email` VARCHAR(255)  NOT NULL,
	`sum` DOUBLE(12,2) default 0 NOT NULL,
	`created_at` DATETIME  NOT NULL,
	PRIMARY KEY (`ptid`),
	KEY `pt_i_taid`(`taid`),
	KEY `pt_i_uid`(`uid`),
	CONSTRAINT `pt_fk_taid`
		FOREIGN KEY (`taid`)
		REFERENCES `payment_transaction_accounting` (`taid`),
	CONSTRAINT `pt_fk_uid`
		FOREIGN KEY (`uid`)
		REFERENCES `user` (`uid`)
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- paypal_ipn_queue
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `paypal_ipn_queue`;


CREATE TABLE `paypal_ipn_queue`
(
	`piqid` INTEGER(11)  NOT NULL AUTO_INCREMENT,
	`status` INTEGER(11) default 0 NOT NULL,
	`ipn_track_id` VARCHAR(255)  NOT NULL,
	`txn_type` VARCHAR(255)  NOT NULL,
	`subscriber_id` VARCHAR(255)  NOT NULL,
	`ipn_data` TEXT  NOT NULL,
	`created_at` DATETIME  NOT NULL,
	`updated_at` DATETIME  NOT NULL,
	PRIMARY KEY (`piqid`),
	KEY `piq_ipn_track_id`(`ipn_track_id`),
	KEY `piq_txn_type`(`txn_type`),
	KEY `piq_subscriber_id`(`subscriber_id`)
)Engine=InnoDB;

# This restores the fkey checks, after having unset them earlier
SET FOREIGN_KEY_CHECKS = 1;
