| 1 | CREATE TABLE `billing_categories` ( |
| 2 | `id` varchar(36 |
| 3 | `name` varchar(255 |
| 4 | `description` text, |
| 5 | `slug` varchar(255 |
| 6 | `icon` text, |
| 7 | `cover_image` text, |
| 8 | `is_active` boolean NOT NULL |
| 9 | `sort_order` int NOT NULL |
| 10 | `created_at` timestamp(3 |
| 11 | `updated_at` timestamp(3 |
| 12 | CONSTRAINT `billing_categories_id` PRIMARY KEY |
| 13 | CONSTRAINT `billing_categories_slug_unique` UNIQUE |
| 14 | ); |
| 15 | --> statement-breakpoint |
| 16 | CREATE TABLE `billing_coupon_redemptions` ( |
| 17 | `id` varchar(36 |
| 18 | `coupon_id` varchar(36 |
| 19 | `user_id` varchar(36 |
| 20 | `invoice_id` varchar(36 |
| 21 | `discount_amount_cents` int NOT NULL |
| 22 | `currency` varchar(3 |
| 23 | `redeemed_at` timestamp(3 |
| 24 | `created_at` timestamp(3 |
| 25 | `updated_at` timestamp(3 |
| 26 | CONSTRAINT `billing_coupon_redemptions_id` PRIMARY KEY |
| 27 | CONSTRAINT `billing_coupon_redemptions_couponId_userId_unique` UNIQUE |
| 28 | ); |
| 29 | --> statement-breakpoint |
| 30 | CREATE TABLE `billing_coupons` ( |
| 31 | `id` varchar(36 |
| 32 | `code` varchar(100 |
| 33 | `description` text, |
| 34 | `discount_type` enum('percentage',' |
| 35 | `discount_value` int NOT NULL |
| 36 | `currency` varchar(3 |
| 37 | `max_redemptions` int, |
| 38 | `times_redeemed` int NOT NULL |
| 39 | `redeem_by` timestamp(3 |
| 40 | `is_active` boolean NOT NULL |
| 41 | `plan_id` varchar(36 |
| 42 | `provider_coupon_id` varchar(255 |
| 43 | `created_at` timestamp(3 |
| 44 | `updated_at` timestamp(3 |
| 45 | CONSTRAINT `billing_coupons_id` PRIMARY KEY |
| 46 | CONSTRAINT `billing_coupons_code_unique` UNIQUE |
| 47 | ); |
| 48 | --> statement-breakpoint |
| 49 | CREATE TABLE `billing_invoice_items` ( |
| 50 | `id` varchar(36 |
| 51 | `invoice_id` varchar(36 |
| 52 | `description` varchar(500 |
| 53 | `quantity` int NOT NULL |
| 54 | `unit_amount_cents` int NOT NULL |
| 55 | `total_cents` int NOT NULL |
| 56 | `currency` varchar(3 |
| 57 | `period_start` timestamp(3 |
| 58 | `period_end` timestamp(3 |
| 59 | `created_at` timestamp(3 |
| 60 | `updated_at` timestamp(3 |
| 61 | CONSTRAINT `billing_invoice_items_id` PRIMARY KEY |
| 62 | ); |
| 63 | --> statement-breakpoint |
| 64 | CREATE TABLE `billing_invoices` ( |
| 65 | `id` varchar(36 |
| 66 | `user_id` varchar(36 |
| 67 | `subscription_id` varchar(36 |
| 68 | `gateway_id` varchar(36 |
| 69 | `invoice_number` varchar(100 |
| 70 | `status` enum('draft',' |
| 71 | `currency` varchar(3 |
| 72 | `subtotal_cents` int NOT NULL |
| 73 | `tax_cents` int NOT NULL |
| 74 | `discount_cents` int NOT NULL |
| 75 | `total_cents` int NOT NULL |
| 76 | `amount_paid_cents` int NOT NULL |
| 77 | `amount_due_cents` int NOT NULL |
| 78 | `vat_number` varchar(50 |
| 79 | `vat_rate` int, |
| 80 | `billing_address` json, |
| 81 | `due_date` timestamp(3 |
| 82 | `paid_at` timestamp(3 |
| 83 | `notes` text, |
| 84 | `provider_invoice_id` varchar(255 |
| 85 | `created_at` timestamp(3 |
| 86 | `updated_at` timestamp(3 |
| 87 | CONSTRAINT `billing_invoices_id` PRIMARY KEY |
| 88 | CONSTRAINT `billing_invoices_invoiceNumber_unique` UNIQUE |
| 89 | ); |
| 90 | --> statement-breakpoint |
| 91 | CREATE TABLE `billing_payment_gateways` ( |
| 92 | `id` varchar(36 |
| 93 | `name` varchar(255 |
| 94 | `provider` varchar(100 |
| 95 | `config` json NOT NULL DEFAULT |
| 96 | `is_active` boolean NOT NULL |
| 97 | `is_default` boolean NOT NULL |
| 98 | `sort_order` int NOT NULL |
| 99 | `created_at` timestamp(3 |
| 100 | `updated_at` timestamp(3 |
| 101 | CONSTRAINT `billing_payment_gateways_id` PRIMARY KEY |
| 102 | ); |
| 103 | --> statement-breakpoint |
| 104 | CREATE TABLE `billing_payment_methods` ( |
| 105 | `id` varchar(36 |
| 106 | `user_id` varchar(36 |
| 107 | `gateway_id` varchar(36 |
| 108 | `type` enum('card',' |
| 109 | `card_brand` varchar(50 |
| 110 | `card_last4` varchar(4 |
| 111 | `card_exp_month` int, |
| 112 | `card_exp_year` int, |
| 113 | `is_default` boolean NOT NULL |
| 114 | `provider_payment_method_id` varchar(255 |
| 115 | `provider_customer_id` varchar(255 |
| 116 | `created_at` timestamp(3 |
| 117 | `updated_at` timestamp(3 |
| 118 | CONSTRAINT `billing_payment_methods_id` PRIMARY KEY |
| 119 | ); |
| 120 | --> statement-breakpoint |
| 121 | CREATE TABLE `billing_plan_prices` ( |
| 122 | `id` varchar(36 |
| 123 | `plan_id` varchar(36 |
| 124 | `duration` enum('7day',' |
| 125 | `price_cents` int NOT NULL |
| 126 | `is_active` boolean NOT NULL |
| 127 | `provider_price_id` varchar(255 |
| 128 | `created_at` timestamp(3 |
| 129 | `updated_at` timestamp(3 |
| 130 | CONSTRAINT `billing_plan_prices_id` PRIMARY KEY |
| 131 | CONSTRAINT `billing_plan_prices_planId_duration_unique` UNIQUE |
| 132 | ); |
| 133 | --> statement-breakpoint |
| 134 | CREATE TABLE `billing_plans` ( |
| 135 | `id` varchar(36 |
| 136 | `product_id` varchar(36 |
| 137 | `name` varchar(255 |
| 138 | `description` text, |
| 139 | `currency` varchar(3 |
| 140 | `resource_limits` json NOT NULL DEFAULT |
| 141 | `is_active` boolean NOT NULL |
| 142 | `is_public` boolean NOT NULL |
| 143 | `sort_order` int NOT NULL |
| 144 | `provider_plan_id` varchar(255 |
| 145 | `created_at` timestamp(3 |
| 146 | `updated_at` timestamp(3 |
| 147 | CONSTRAINT `billing_plans_id` PRIMARY KEY |
| 148 | ); |
| 149 | --> statement-breakpoint |
| 150 | CREATE TABLE `billing_products` ( |
| 151 | `id` varchar(36 |
| 152 | `category_id` varchar(36 |
| 153 | `name` varchar(255 |
| 154 | `description` text, |
| 155 | `slug` varchar(255 |
| 156 | `icon` text, |
| 157 | `cover_image` text, |
| 158 | `inherit_icon` boolean NOT NULL |
| 159 | `inherit_cover_image` boolean NOT NULL |
| 160 | `is_featured` boolean NOT NULL |
| 161 | `is_active` boolean NOT NULL |
| 162 | `sort_order` int NOT NULL |
| 163 | `created_at` timestamp(3 |
| 164 | `updated_at` timestamp(3 |
| 165 | CONSTRAINT `billing_products_id` PRIMARY KEY |
| 166 | CONSTRAINT `billing_products_slug_unique` UNIQUE |
| 167 | ); |
| 168 | --> statement-breakpoint |
| 169 | CREATE TABLE `billing_referral_codes` ( |
| 170 | `id` varchar(36 |
| 171 | `user_id` varchar(36 |
| 172 | `code` varchar(50 |
| 173 | `usage_count` int NOT NULL |
| 174 | `is_active` boolean NOT NULL |
| 175 | `created_at` timestamp(3 |
| 176 | `updated_at` timestamp(3 |
| 177 | CONSTRAINT `billing_referral_codes_id` PRIMARY KEY |
| 178 | CONSTRAINT `billing_referral_codes_user_id_unique` UNIQUE |
| 179 | CONSTRAINT `billing_referral_codes_code_unique` UNIQUE |
| 180 | ); |
| 181 | --> statement-breakpoint |
| 182 | CREATE TABLE `billing_referral_redemptions` ( |
| 183 | `id` varchar(36 |
| 184 | `code_id` varchar(36 |
| 185 | `referee_id` varchar(36 |
| 186 | `referrer_id` varchar(36 |
| 187 | `first_topup_at` timestamp(3 |
| 188 | `created_at` timestamp(3 |
| 189 | `updated_at` timestamp(3 |
| 190 | CONSTRAINT `billing_referral_redemptions_id` PRIMARY KEY |
| 191 | CONSTRAINT `billing_referral_redemptions_referee_id_unique` UNIQUE |
| 192 | ); |
| 193 | --> statement-breakpoint |
| 194 | CREATE TABLE `billing_subscriptions` ( |
| 195 | `id` varchar(36 |
| 196 | `user_id` varchar(36 |
| 197 | `plan_id` varchar(36 |
| 198 | `gateway_id` varchar(36 |
| 199 | `price_id` varchar(36 |
| 200 | `status` enum('active',' |
| 201 | `currency` varchar(3 |
| 202 | `current_period_start` timestamp(3 |
| 203 | `current_period_end` timestamp(3 |
| 204 | `trial_start` timestamp(3 |
| 205 | `trial_end` timestamp(3 |
| 206 | `cancel_at_period_end` boolean NOT NULL |
| 207 | `canceled_at` timestamp(3 |
| 208 | `provider_subscription_id` varchar(255 |
| 209 | `provider_customer_id` varchar(255 |
| 210 | `created_at` timestamp(3 |
| 211 | `updated_at` timestamp(3 |
| 212 | CONSTRAINT `billing_subscriptions_id` PRIMARY KEY |
| 213 | ); |
| 214 | --> statement-breakpoint |
| 215 | CREATE TABLE `billing_transactions` ( |
| 216 | `id` varchar(36 |
| 217 | `user_id` varchar(36 |
| 218 | `invoice_id` varchar(36 |
| 219 | `payment_method_id` varchar(36 |
| 220 | `gateway_id` varchar(36 |
| 221 | `type` enum('payment',' |
| 222 | `status` enum('pending',' |
| 223 | `amount_cents` int NOT NULL |
| 224 | `currency` varchar(3 |
| 225 | `description` text, |
| 226 | `failure_message` text, |
| 227 | `provider_transaction_id` varchar(255 |
| 228 | `provider_charge_id` varchar(255 |
| 229 | `created_at` timestamp(3 |
| 230 | `updated_at` timestamp(3 |
| 231 | CONSTRAINT `billing_transactions_id` PRIMARY KEY |
| 232 | ); |
| 233 | --> statement-breakpoint |
| 234 | CREATE TABLE `billing_wallet` ( |
| 235 | `id` varchar(36 |
| 236 | `user_id` varchar(36 |
| 237 | `balance_cents` int NOT NULL |
| 238 | `currency` varchar(3 |
| 239 | `auto_top_up_enabled` boolean NOT NULL |
| 240 | `auto_top_up_threshold_cents` int NOT NULL |
| 241 | `auto_top_up_amount_cents` int NOT NULL |
| 242 | `created_at` timestamp(3 |
| 243 | `updated_at` timestamp(3 |
| 244 | CONSTRAINT `billing_wallet_id` PRIMARY KEY |
| 245 | CONSTRAINT `billing_wallet_user_id_unique` UNIQUE |
| 246 | ); |
| 247 | --> statement-breakpoint |
| 248 | CREATE TABLE `billing_wallet_transactions` ( |
| 249 | `id` varchar(36 |
| 250 | `user_id` varchar(36 |
| 251 | `invoice_id` varchar(36 |
| 252 | `amount_cents` int NOT NULL |
| 253 | `balance_after_cents` int NOT NULL |
| 254 | `currency` varchar(3 |
| 255 | `type` enum('topup',' |
| 256 | `description` text, |
| 257 | `created_at` timestamp(3 |
| 258 | `updated_at` timestamp(3 |
| 259 | CONSTRAINT `billing_wallet_transactions_id` PRIMARY KEY |
| 260 | ); |
| 261 | --> statement-breakpoint |
| 262 | ALTER TABLE `servers` ADD |
| 263 | ALTER TABLE `billing_coupon_redemptions` ADD |
| 264 | ALTER TABLE `billing_coupon_redemptions` ADD |
| 265 | ALTER TABLE `billing_coupon_redemptions` ADD |
| 266 | ALTER TABLE `billing_coupons` ADD |
| 267 | ALTER TABLE `billing_invoice_items` ADD |
| 268 | ALTER TABLE `billing_invoices` ADD |
| 269 | ALTER TABLE `billing_invoices` ADD |
| 270 | ALTER TABLE `billing_invoices` ADD |
| 271 | ALTER TABLE `billing_payment_methods` ADD |
| 272 | ALTER TABLE `billing_payment_methods` ADD |
| 273 | ALTER TABLE `billing_plan_prices` ADD |
| 274 | ALTER TABLE `billing_plans` ADD |
| 275 | ALTER TABLE `billing_products` ADD |
| 276 | ALTER TABLE `billing_referral_codes` ADD |
| 277 | ALTER TABLE `billing_referral_redemptions` ADD |
| 278 | ALTER TABLE `billing_referral_redemptions` ADD |
| 279 | ALTER TABLE `billing_referral_redemptions` ADD |
| 280 | ALTER TABLE `billing_subscriptions` ADD |
| 281 | ALTER TABLE `billing_subscriptions` ADD |
| 282 | ALTER TABLE `billing_subscriptions` ADD |
| 283 | ALTER TABLE `billing_subscriptions` ADD |
| 284 | ALTER TABLE `billing_transactions` ADD |
| 285 | ALTER TABLE `billing_transactions` ADD |
| 286 | ALTER TABLE `billing_transactions` ADD |
| 287 | ALTER TABLE `billing_transactions` ADD |
| 288 | ALTER TABLE `billing_wallet` ADD |
| 289 | ALTER TABLE `billing_wallet_transactions` ADD |
| 290 | ALTER TABLE `billing_wallet_transactions` ADD |
| 291 | CREATE INDEX `billing_coupon_redemptions_couponId_idx` ON |
| 292 | CREATE INDEX `billing_coupon_redemptions_userId_idx` ON |
| 293 | CREATE INDEX `billing_coupon_redemptions_invoiceId_idx` ON |
| 294 | CREATE INDEX `billing_coupons_planId_idx` ON |
| 295 | CREATE INDEX `billing_invoice_items_invoiceId_idx` ON |
| 296 | CREATE INDEX `billing_invoices_userId_idx` ON |
| 297 | CREATE INDEX `billing_invoices_subscriptionId_idx` ON |
| 298 | CREATE INDEX `billing_invoices_providerInvoiceId_idx` ON |
| 299 | CREATE INDEX `billing_payment_methods_userId_idx` ON |
| 300 | CREATE INDEX `billing_payment_methods_providerPaymentMethodId_idx` ON |
| 301 | CREATE INDEX `billing_plan_prices_planId_idx` ON |
| 302 | CREATE INDEX `billing_plans_productId_idx` ON |
| 303 | CREATE INDEX `billing_products_categoryId_idx` ON |
| 304 | CREATE INDEX `brr_code_id_idx` ON |
| 305 | CREATE INDEX `brr_referrer_id_idx` ON |
| 306 | CREATE INDEX `billing_subscriptions_userId_idx` ON |
| 307 | CREATE INDEX `billing_subscriptions_planId_idx` ON |
| 308 | CREATE INDEX `billing_subscriptions_providerSubscriptionId_idx` ON |
| 309 | CREATE INDEX `billing_transactions_userId_idx` ON |
| 310 | CREATE INDEX `billing_transactions_invoiceId_idx` ON |
| 311 | CREATE INDEX `billing_transactions_providerTransactionId_idx` ON |
| 312 | CREATE INDEX `billing_wallet_transactions_userId_idx` ON |
| 313 | CREATE INDEX `billing_wallet_transactions_invoiceId_idx` ON |
| 314 | CREATE INDEX `servers_subscriptionId_idx` ON |