CREATE TABLE IF NOT EXISTS `softline_subscriptions_$mid` (
	`id` INT auto_increment NOT NULL,
	`productId` INT NOT NULL,
	`contractId` int(10) unsigned NOT NULL,
	`status` INT NOT NULL,
	`suspendReason` INT NULL,
	`periodType` INT NOT NULL,
	`periodCount` INT NULL,
	`startDate` TIMESTAMP NOT NULL,
	`lastModifyDate` TIMESTAMP NULL,
	`endDate` TIMESTAMP NULL,
	`downloadData` text null,
	CONSTRAINT `softline_subscriptions_$mid_PK` PRIMARY KEY (`id`),
	CONSTRAINT `softline_subscriptions_$mid_contract_FK` FOREIGN KEY (`contractId`) REFERENCES `contract` (`id`) ON DELETE CASCADE
);

CREATE TABLE IF NOT EXISTS `softline_subscriptions_history_$mid` (
	`subscriptionId` INT NOT NULL,
	`status` INT DEFAULT 0 NOT NULL,
	`suspendReason` INT NULL,
	`modifyDate` TIMESTAMP NULL,
	`contractId` INT NULL,
	`productId` INT NULL,
	`dateFrom` TIMESTAMP NULL,
	`dateTo` TIMESTAMP NULL,
	CONSTRAINT softline_subscriptions_history_$mid_FK FOREIGN KEY (`subscriptionId`) REFERENCES `softline_subscriptions_$mid`(`id`) ON DELETE CASCADE
);

CREATE TABLE IF NOT EXISTS `softline_product_$mid` (
	`id` INT auto_increment NOT NULL,
	`title` varchar(100) NULL,
	`description` TEXT NULL,
	`softLineCode` varchar(100) NULL,
	`price` DECIMAL NULL,
	`serviceId` INT NOT NULL,
	`periodType` INT NOT NULL,
	CONSTRAINT `softline_product_PK` PRIMARY KEY (`id`)
);

CREATE TABLE IF NOT EXISTS `softline_product_category_$mid` (
    `id` INT auto_increment NOT NULL,
    `title` varchar(100) NULL,
    `description` TEXT NULL,
    PRIMARY KEY (`id`)
);

ALTER TABLE `softline_product_$mid` ADD COLUMN `periodCount` INT DEFAULT 0;
ALTER TABLE `softline_product_$mid` ADD COLUMN `product_category_id` INT DEFAULT 0;
ALTER TABLE `softline_product_$mid` MODIFY price decimal(10,2);

ALTER TABLE `filestorage_files_list_products_pictures` ADD COLUMN `uuid` VARCHAR(50) NOT NULL AFTER `comment`;
ALTER TABLE `filestorage_files_list_product_categories_pictures` ADD COLUMN `uuid` VARCHAR(50) NOT NULL AFTER `comment`;

-- #BLOCK#
DELETE FROM script_event_type WHERE mid=$mid;
-- #ENDB#
