Skip to content

📈 Open source, privacy-first web analytics — a cookie-less Google Analytics alternative with built-in error tracking and performance monitoring. Self-host it or use our cloud. Get started for free!

2.2 KB
Raw Blame
CREATE TABLE `user_addon` (
  `id` varchar(36) NOT NULL,
  `userId` varchar(36) NOT NULL,
  `code` enum('websites') NOT NULL,
  `quantity` int NOT NULL DEFAULT '0',
  `pendingQuantity` int DEFAULT NULL,
  `billingInterval` enum('monthly','yearly') NOT NULL DEFAULT 'monthly',
  `pendingBillingInterval` enum('monthly','yearly') DEFAULT NULL,
  `currency` varchar(3) NOT NULL DEFAULT 'USD',
  `periodStart` timestamp NULL DEFAULT NULL,
  `periodEnd` timestamp NULL DEFAULT NULL,
  `nextChargeDate` timestamp NULL DEFAULT NULL,
  `status` enum('active','past_due','cancelled') NOT NULL DEFAULT 'active',
  `failedChargeAttempts` int NOT NULL DEFAULT '0',
  `lastChargeFailedAt` timestamp NULL DEFAULT NULL,
  `cancelledAt` timestamp NULL DEFAULT NULL,
  `createdAt` datetime(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6),
  `updatedAt` datetime(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6),
  PRIMARY KEY (`id`),
  UNIQUE KEY `IDX_user_addon_user_code` (`userId`,`code`),
  KEY `IDX_user_addon_next_charge_status` (`nextChargeDate`,`status`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

CREATE TABLE `user_addon_charge` (
  `id` varchar(36) NOT NULL,
  `addonId` varchar(36) NOT NULL,
  `userId` varchar(36) NOT NULL,
  `kind` enum('initial','prorated','renewal') NOT NULL,
  `status` enum('pending','succeeded','failed') NOT NULL DEFAULT 'pending',
  `quantity` int NOT NULL,
  `previousQuantity` int DEFAULT NULL,
  `billingInterval` enum('monthly','yearly') NOT NULL,
  `amount` decimal(10,2) NOT NULL,
  `currency` varchar(3) NOT NULL,
  `periodStart` timestamp NULL DEFAULT NULL,
  `periodEnd` timestamp NULL DEFAULT NULL,
  `paddleInvoiceId` int DEFAULT NULL,
  `paddleOrderId` varchar(80) DEFAULT NULL,
  `paddleStatus` varchar(80) DEFAULT NULL,
  `paddleReceiptUrl` varchar(300) DEFAULT NULL,
  `paddleResponse` json DEFAULT NULL,
  `failureReason` text,
  `createdAt` datetime(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6),
  `updatedAt` datetime(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6),
  PRIMARY KEY (`id`),
  KEY `IDX_user_addon_charge_addon_created` (`addonId`,`createdAt`),
  KEY `IDX_user_addon_charge_user` (`userId`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;