· 7 years ago · Oct 29, 2018, 03:36 PM
1DROP TABLE subscription_addons;
2CREATE TABLE `subscription_addons` (
3 `id` bigint(20) NOT NULL AUTO_INCREMENT,
4 `external_id` varchar(127) NOT NULL,
5 `name` varchar(100) NOT NULL,
6 `amount` float(6,2) NOT NULL,
7 `amount_gbp` float(9,2) unsigned NOT NULL DEFAULT '0.00',
8 `type` tinyint(3) unsigned NOT NULL,
9 `managed` tinyint(4) NOT NULL,
10 `recurring` tinyint(1) NOT NULL,
11 `months_per_billing_cycle` int(10) unsigned NOT NULL,
12 `number_of_billing_cycles` int(10) unsigned NOT NULL,
13 `workload_hours` tinyint(3) unsigned NOT NULL,
14 `description` text NOT NULL,
15 `created_at` datetime NOT NULL,
16 `updated_at` datetime NOT NULL,
17 PRIMARY KEY (`id`),
18 KEY `recurring` (`recurring`),
19 KEY `months_per_billing_cycle` (`months_per_billing_cycle`)
20) DEFAULT CHARSET=utf8
21
22DROP TABLE IF EXISTS `user_subscription_addons`;
23CREATE TABLE IF NOT EXISTS `user_subscription_addons` (
24 `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT,
25 `inherited_from_id` bigint(20) UNSIGNED NOT NULL,
26 `user_id` bigint(20) UNSIGNED NOT NULL,
27 `user_subscription_id` bigint(20) UNSIGNED NOT NULL,
28 `number_of_billing_cycles` int(10) UNSIGNED NOT NULL,
29 `current_billing_cycle` int(10) UNSIGNED NOT NULL,
30 `amount` float(10,2) UNSIGNED NOT NULL,
31 `status` tinyint(3) UNSIGNED NOT NULL,
32 `quantity` int(4) UNSIGNED NOT NULL,
33 `created_at` datetime NOT NULL,
34 PRIMARY KEY (`id`),
35 KEY `user_id` (`user_id`),
36 KEY `inherited_from_id` (`inherited_from_id`),
37 KEY `user_subscription_id` (`user_subscription_id`)
38) DEFAULT CHARSET=utf8;
39
40ALTER TABLE `user_subscription_discounts` ADD `user_id` BIGINT NOT NULL AFTER `discount_id`, ADD INDEX (`user_id`);
41
42DROP TABLE IF EXISTS `merchant_accounts`;
43CREATE TABLE IF NOT EXISTS `merchant_accounts` (
44 `id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT,
45 `external_id` varchar(127) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
46 `currency` char(3) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
47 `is_default` tinyint(1) UNSIGNED NOT NULL,
48 PRIMARY KEY (`id`),
49 UNIQUE KEY `external_id` (`external_id`)
50) ENGINE=InnoDB DEFAULT CHARSET=utf8;
51
52INSERT INTO `merchant_accounts` (`id`, `external_id`, `currency`, `is_default`) VALUES
53(1, 'BrandYourself', 'USD', 1),
54(2, 'BrandYourselfcom_GBP', 'GBP', 0);
55
56ALTER TABLE `subscriptions`
57ADD `cost_gbp` FLOAT(9,2) UNSIGNED NOT NULL DEFAULT '0.00' AFTER `cost`;
58
59ALTER TABLE `subscription_transactions`
60ADD `currency` CHAR(3) NOT NULL DEFAULT 'USD' AFTER `status`,
61ADD `merchant_account_id` INT UNSIGNED NOT NULL AFTER `user_subscription_id`,
62ADD `value_settled` FLOAT(9,2) UNSIGNED NOT NULL AFTER `value`;
63
64ALTER TABLE `user_subscriptions`
65ADD `merchant_account_id` INT UNSIGNED NOT NULL,
66ADD `currency` CHAR(3) NOT NULL DEFAULT 'USD';