CREATE TABLE `activations` (
	`id` int AUTO_INCREMENT NOT NULL,
	`license_id` int NOT NULL,
	`hardware_id` varchar(255) NOT NULL,
	`meta` text,
	`activated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
	`deactivated_at` timestamp,
	`created_at` timestamp DEFAULT CURRENT_TIMESTAMP,
	`updated_at` timestamp ON UPDATE CURRENT_TIMESTAMP,
	CONSTRAINT `activations_id` PRIMARY KEY(`id`)
);
--> statement-breakpoint
CREATE TABLE `buy_requests` (
	`id` int AUTO_INCREMENT NOT NULL,
	`customer_name` varchar(255) NOT NULL,
	`customer_email` varchar(255) NOT NULL,
	`plan_id` varchar(50),
	`message` text,
	`status` varchar(50) NOT NULL DEFAULT 'pending',
	`email_sent_at` timestamp,
	`custom_price` int,
	`custom_license_duration_days` int,
	`custom_max_activations` int,
	`manual_receipt_url` text,
	`transaction_id` varchar(255),
	`submission_at` timestamp,
	`payment_token` varchar(100),
	`created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
	`updated_at` timestamp ON UPDATE CURRENT_TIMESTAMP,
	CONSTRAINT `buy_requests_id` PRIMARY KEY(`id`)
);
--> statement-breakpoint
CREATE TABLE `changelog_items` (
	`id` int AUTO_INCREMENT NOT NULL,
	`version_id` int NOT NULL,
	`category` varchar(20) NOT NULL,
	`description` text NOT NULL,
	`order` int NOT NULL DEFAULT 0,
	`created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
	CONSTRAINT `changelog_items_id` PRIMARY KEY(`id`)
);
--> statement-breakpoint
CREATE TABLE `changelog_versions` (
	`id` int AUTO_INCREMENT NOT NULL,
	`version` varchar(50) NOT NULL,
	`release_date` timestamp NOT NULL,
	`type` varchar(20) NOT NULL DEFAULT 'minor',
	`is_stable` boolean NOT NULL DEFAULT true,
	`published` boolean NOT NULL DEFAULT true,
	`created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
	`updated_at` timestamp DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
	CONSTRAINT `changelog_versions_id` PRIMARY KEY(`id`),
	CONSTRAINT `changelog_versions_version_unique` UNIQUE(`version`)
);
--> statement-breakpoint
CREATE TABLE `demos` (
	`id` int AUTO_INCREMENT NOT NULL,
	`title` varchar(255) NOT NULL,
	`url` varchar(500) NOT NULL,
	`type` varchar(20) NOT NULL DEFAULT 'image',
	`order` int NOT NULL DEFAULT 0,
	`created_at` timestamp DEFAULT CURRENT_TIMESTAMP,
	`updated_at` timestamp ON UPDATE CURRENT_TIMESTAMP,
	CONSTRAINT `demos_id` PRIMARY KEY(`id`)
);
--> statement-breakpoint
CREATE TABLE `email_verifications` (
	`id` int AUTO_INCREMENT NOT NULL,
	`email` varchar(255) NOT NULL,
	`code` varchar(6) NOT NULL,
	`expires_at` timestamp NOT NULL,
	`verified_at` timestamp,
	`created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
	CONSTRAINT `email_verifications_id` PRIMARY KEY(`id`)
);
--> statement-breakpoint
CREATE TABLE `features` (
	`id` int AUTO_INCREMENT NOT NULL,
	`title` varchar(255) NOT NULL,
	`description` text NOT NULL,
	`icon` varchar(50) NOT NULL,
	`created_at` timestamp DEFAULT CURRENT_TIMESTAMP,
	`updated_at` timestamp ON UPDATE CURRENT_TIMESTAMP,
	CONSTRAINT `features_id` PRIMARY KEY(`id`)
);
--> statement-breakpoint
CREATE TABLE `issue_comments` (
	`id` int AUTO_INCREMENT NOT NULL,
	`issue_id` int NOT NULL,
	`subtask_id` int,
	`content` text NOT NULL,
	`author` varchar(255) DEFAULT 'Admin',
	`created_at` timestamp DEFAULT CURRENT_TIMESTAMP,
	CONSTRAINT `issue_comments_id` PRIMARY KEY(`id`)
);
--> statement-breakpoint
CREATE TABLE `issue_subtasks` (
	`id` int AUTO_INCREMENT NOT NULL,
	`issue_id` int NOT NULL,
	`title` varchar(255) NOT NULL,
	`is_completed` boolean DEFAULT false,
	`created_at` timestamp DEFAULT CURRENT_TIMESTAMP,
	CONSTRAINT `issue_subtasks_id` PRIMARY KEY(`id`)
);
--> statement-breakpoint
CREATE TABLE `issue_work_logs` (
	`id` int AUTO_INCREMENT NOT NULL,
	`issue_id` int NOT NULL,
	`subtask_id` int,
	`time_spent` int NOT NULL,
	`description` text,
	`author` varchar(255) DEFAULT 'Admin',
	`logged_at` timestamp DEFAULT CURRENT_TIMESTAMP,
	CONSTRAINT `issue_work_logs_id` PRIMARY KEY(`id`)
);
--> statement-breakpoint
CREATE TABLE `issues` (
	`id` int AUTO_INCREMENT NOT NULL,
	`title` varchar(255) NOT NULL,
	`description` text NOT NULL,
	`version` varchar(50) NOT NULL,
	`email` varchar(255) NOT NULL,
	`attachment_url` varchar(500),
	`category` varchar(50) NOT NULL DEFAULT 'OTHER',
	`type` varchar(50) NOT NULL DEFAULT 'BUG',
	`status` varchar(50) NOT NULL DEFAULT 'OPEN',
	`assignee_id` int,
	`assigned_by_id` int,
	`source` varchar(20) NOT NULL DEFAULT 'CLIENT',
	`created_at` timestamp DEFAULT CURRENT_TIMESTAMP,
	`updated_at` timestamp ON UPDATE CURRENT_TIMESTAMP,
	CONSTRAINT `issues_id` PRIMARY KEY(`id`)
);
--> statement-breakpoint
CREATE TABLE `licenses` (
	`id` int AUTO_INCREMENT NOT NULL,
	`key` varchar(700) NOT NULL,
	`type` varchar(50) NOT NULL,
	`status` varchar(50) NOT NULL DEFAULT 'ACTIVE',
	`client_email` varchar(255) NOT NULL,
	`product_version` varchar(50) NOT NULL DEFAULT '1.0',
	`max_activations` int NOT NULL DEFAULT 1,
	`activation_count` int NOT NULL DEFAULT 0,
	`expires_at` timestamp NOT NULL,
	`created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
	CONSTRAINT `licenses_id` PRIMARY KEY(`id`),
	CONSTRAINT `licenses_key_unique` UNIQUE(`key`)
);
--> statement-breakpoint
CREATE TABLE `partners` (
	`id` int AUTO_INCREMENT NOT NULL,
	`name` varchar(255) NOT NULL,
	`logo_url` varchar(500),
	`icon` varchar(50),
	`created_at` timestamp DEFAULT CURRENT_TIMESTAMP,
	`updated_at` timestamp ON UPDATE CURRENT_TIMESTAMP,
	CONSTRAINT `partners_id` PRIMARY KEY(`id`)
);
--> statement-breakpoint
CREATE TABLE `payments` (
	`id` int AUTO_INCREMENT NOT NULL,
	`customer_name` varchar(255),
	`customer_email` varchar(255) NOT NULL,
	`plan_id` varchar(50) NOT NULL,
	`amount` int NOT NULL,
	`status` varchar(50) DEFAULT 'pending',
	`gateway` varchar(20) DEFAULT 'stripe',
	`payment_id` varchar(255),
	`license_key` varchar(700),
	`metadata` json,
	`created_at` timestamp DEFAULT CURRENT_TIMESTAMP,
	`updated_at` timestamp ON UPDATE CURRENT_TIMESTAMP,
	CONSTRAINT `payments_id` PRIMARY KEY(`id`)
);
--> statement-breakpoint
CREATE TABLE `pricing_plans` (
	`id` int AUTO_INCREMENT NOT NULL,
	`code` varchar(50) NOT NULL,
	`price` varchar(50) NOT NULL,
	`discount_price` varchar(50),
	`sale_label` varchar(50),
	`period` varchar(50),
	`description` text,
	`popular` boolean NOT NULL DEFAULT false,
	`max_activations` int NOT NULL DEFAULT 1,
	`features` text,
	`created_at` timestamp DEFAULT CURRENT_TIMESTAMP,
	`updated_at` timestamp ON UPDATE CURRENT_TIMESTAMP,
	CONSTRAINT `pricing_plans_id` PRIMARY KEY(`id`),
	CONSTRAINT `pricing_plans_code_unique` UNIQUE(`code`)
);
--> statement-breakpoint
CREATE TABLE `product_keys` (
	`id` int AUTO_INCREMENT NOT NULL,
	`version` int NOT NULL,
	`private_key` text NOT NULL,
	`public_key` text NOT NULL,
	`created_at` timestamp DEFAULT CURRENT_TIMESTAMP,
	`updated_at` timestamp ON UPDATE CURRENT_TIMESTAMP,
	CONSTRAINT `product_keys_id` PRIMARY KEY(`id`),
	CONSTRAINT `product_keys_version_unique` UNIQUE(`version`)
);
--> statement-breakpoint
CREATE TABLE `role_permissions` (
	`id` int AUTO_INCREMENT NOT NULL,
	`role` varchar(20) NOT NULL,
	`permission` varchar(255) NOT NULL,
	`created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
	CONSTRAINT `role_permissions_id` PRIMARY KEY(`id`)
);
--> statement-breakpoint
CREATE TABLE `settings` (
	`id` int AUTO_INCREMENT NOT NULL,
	`key` varchar(255) NOT NULL,
	`value` text NOT NULL,
	`created_at` timestamp DEFAULT CURRENT_TIMESTAMP,
	`updated_at` timestamp ON UPDATE CURRENT_TIMESTAMP,
	CONSTRAINT `settings_id` PRIMARY KEY(`id`),
	CONSTRAINT `settings_key_unique` UNIQUE(`key`)
);
--> statement-breakpoint
CREATE TABLE `site_settings` (
	`id` int AUTO_INCREMENT NOT NULL,
	`key` varchar(255) NOT NULL,
	`value` text,
	`created_at` timestamp DEFAULT CURRENT_TIMESTAMP,
	`updated_at` timestamp ON UPDATE CURRENT_TIMESTAMP,
	CONSTRAINT `site_settings_id` PRIMARY KEY(`id`),
	CONSTRAINT `site_settings_key_unique` UNIQUE(`key`)
);
--> statement-breakpoint
CREATE TABLE `softwares` (
	`id` int AUTO_INCREMENT NOT NULL,
	`version` varchar(50) NOT NULL,
	`version_type` varchar(20) NOT NULL DEFAULT 'minor',
	`release_date` timestamp DEFAULT CURRENT_TIMESTAMP,
	`is_latest` boolean DEFAULT false,
	`is_stable` boolean DEFAULT true,
	`description` text,
	`platforms` json,
	`created_at` timestamp DEFAULT CURRENT_TIMESTAMP,
	`updated_at` timestamp ON UPDATE CURRENT_TIMESTAMP,
	CONSTRAINT `softwares_id` PRIMARY KEY(`id`)
);
--> statement-breakpoint
CREATE TABLE `testimonials` (
	`id` int AUTO_INCREMENT NOT NULL,
	`name` varchar(255) NOT NULL,
	`role` varchar(255) NOT NULL,
	`company` varchar(255),
	`content` text NOT NULL,
	`rating` int NOT NULL DEFAULT 5,
	`avatar_url` varchar(500),
	`created_at` timestamp DEFAULT CURRENT_TIMESTAMP,
	`updated_at` timestamp ON UPDATE CURRENT_TIMESTAMP,
	CONSTRAINT `testimonials_id` PRIMARY KEY(`id`)
);
--> statement-breakpoint
CREATE TABLE `users` (
	`id` int AUTO_INCREMENT NOT NULL,
	`email` varchar(255) NOT NULL,
	`password` text NOT NULL,
	`name` varchar(255),
	`role` varchar(20) NOT NULL DEFAULT 'USER',
	`created_at` timestamp DEFAULT CURRENT_TIMESTAMP,
	`updated_at` timestamp ON UPDATE CURRENT_TIMESTAMP,
	CONSTRAINT `users_id` PRIMARY KEY(`id`),
	CONSTRAINT `users_email_unique` UNIQUE(`email`)
);
--> statement-breakpoint
ALTER TABLE `activations` ADD CONSTRAINT `activations_license_id_licenses_id_fk` FOREIGN KEY (`license_id`) REFERENCES `licenses`(`id`) ON DELETE no action ON UPDATE no action;--> statement-breakpoint
ALTER TABLE `issue_comments` ADD CONSTRAINT `issue_comments_issue_id_issues_id_fk` FOREIGN KEY (`issue_id`) REFERENCES `issues`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE `issue_comments` ADD CONSTRAINT `issue_comments_subtask_id_issue_subtasks_id_fk` FOREIGN KEY (`subtask_id`) REFERENCES `issue_subtasks`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE `issue_subtasks` ADD CONSTRAINT `issue_subtasks_issue_id_issues_id_fk` FOREIGN KEY (`issue_id`) REFERENCES `issues`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE `issue_work_logs` ADD CONSTRAINT `issue_work_logs_issue_id_issues_id_fk` FOREIGN KEY (`issue_id`) REFERENCES `issues`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE `issue_work_logs` ADD CONSTRAINT `issue_work_logs_subtask_id_issue_subtasks_id_fk` FOREIGN KEY (`subtask_id`) REFERENCES `issue_subtasks`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE `issues` ADD CONSTRAINT `issues_assignee_id_users_id_fk` FOREIGN KEY (`assignee_id`) REFERENCES `users`(`id`) ON DELETE no action ON UPDATE no action;--> statement-breakpoint
ALTER TABLE `issues` ADD CONSTRAINT `issues_assigned_by_id_users_id_fk` FOREIGN KEY (`assigned_by_id`) REFERENCES `users`(`id`) ON DELETE no action ON UPDATE no action;