-- Current sql file was generated after introspecting the database
-- If you want to run this migration please uncomment this code before executing migrations
/*
CREATE TABLE `sys_dict_items` (
	`id` bigint NOT NULL,
	`type_id` bigint NOT NULL,
	`item_key` varchar(50) NOT NULL,
	`item_value` varchar(200) NOT NULL,
	`label` varchar(100) NOT NULL,
	`label_en` varchar(200),
	`description` text,
	`pid` bigint DEFAULT 0,
	`path` varchar(500),
	`level` int NOT NULL DEFAULT 1,
	`sort_order` int NOT NULL DEFAULT 0,
	`status` varchar(20) NOT NULL DEFAULT 'active',
	`css_class` varchar(50),
	`color` varchar(50),
	`extra` json,
	`created_by` bigint,
	`created_at` datetime NOT NULL DEFAULT (CURRENT_TIMESTAMP),
	`updated_by` bigint,
	`updated_at` datetime NOT NULL DEFAULT (CURRENT_TIMESTAMP),
	`deleted_at` datetime,
	CONSTRAINT `sys_dict_items_id` PRIMARY KEY(`id`),
	CONSTRAINT `uk_type_key` UNIQUE(`type_id`,`item_key`,`deleted_at`)
);
--> statement-breakpoint
CREATE TABLE `sys_dict_types` (
	`id` bigint NOT NULL,
	`code` varchar(50) NOT NULL,
	`name` varchar(100) NOT NULL,
	`description` text,
	`pid` bigint DEFAULT 0,
	`path` varchar(500),
	`level` int NOT NULL DEFAULT 1,
	`status` varchar(20) NOT NULL DEFAULT 'active',
	`is_system` tinyint(1) NOT NULL DEFAULT 0,
	`sort_order` int NOT NULL DEFAULT 0,
	`created_by` bigint,
	`created_at` datetime NOT NULL DEFAULT (CURRENT_TIMESTAMP),
	`updated_by` bigint,
	`updated_at` datetime NOT NULL DEFAULT (CURRENT_TIMESTAMP),
	`deleted_at` datetime,
	CONSTRAINT `sys_dict_types_id` PRIMARY KEY(`id`),
	CONSTRAINT `uk_code` UNIQUE(`code`,`deleted_at`)
);
--> statement-breakpoint
CREATE TABLE `sys_operation_logs` (
	`id` bigint NOT NULL,
	`user_id` bigint,
	`username` varchar(100),
	`module` varchar(50) NOT NULL,
	`action` varchar(50) NOT NULL,
	`target` varchar(200),
	`target_id` bigint,
	`request_data` text,
	`response_data` text,
	`status` varchar(20) NOT NULL,
	`ip` varchar(45),
	`user_agent` varchar(200),
	`duration` bigint,
	`error_msg` text,
	`created_at` datetime NOT NULL DEFAULT (CURRENT_TIMESTAMP),
	CONSTRAINT `sys_operation_logs_id` PRIMARY KEY(`id`)
);
--> statement-breakpoint
CREATE TABLE `sys_organizations` (
	`id` bigint NOT NULL,
	`code` varchar(100) NOT NULL,
	`name` varchar(200) NOT NULL,
	`full_name` varchar(200),
	`description` text,
	`pid` bigint DEFAULT 0,
	`path` varchar(500),
	`level` int NOT NULL DEFAULT 1,
	`type` varchar(20),
	`status` varchar(20) NOT NULL DEFAULT 'active',
	`sort_order` int NOT NULL DEFAULT 0,
	`leader_id` bigint,
	`address` varchar(200),
	`phone` varchar(50),
	`extra` json,
	`created_by` bigint,
	`created_at` datetime NOT NULL DEFAULT (CURRENT_TIMESTAMP),
	`updated_by` bigint,
	`updated_at` datetime NOT NULL DEFAULT (CURRENT_TIMESTAMP),
	`deleted_at` datetime,
	`version` int NOT NULL DEFAULT 1,
	CONSTRAINT `sys_organizations_id` PRIMARY KEY(`id`),
	CONSTRAINT `uk_code` UNIQUE(`code`,`deleted_at`)
);
--> statement-breakpoint
CREATE TABLE `sys_permissions` (
	`id` bigint NOT NULL,
	`code` varchar(100) NOT NULL,
	`name` varchar(100) NOT NULL,
	`type` varchar(20) NOT NULL,
	`resource` varchar(50),
	`action` varchar(50),
	`description` text,
	`pid` bigint DEFAULT 0,
	`path` varchar(500),
	`level` int NOT NULL DEFAULT 1,
	`sort_order` int NOT NULL DEFAULT 0,
	`status` varchar(20) NOT NULL DEFAULT 'active',
	`meta` json,
	`created_by` bigint,
	`created_at` datetime NOT NULL DEFAULT (CURRENT_TIMESTAMP),
	`updated_by` bigint,
	`updated_at` datetime NOT NULL DEFAULT (CURRENT_TIMESTAMP),
	`deleted_at` datetime,
	CONSTRAINT `sys_permissions_id` PRIMARY KEY(`id`),
	CONSTRAINT `uk_code` UNIQUE(`code`,`deleted_at`)
);
--> statement-breakpoint
CREATE TABLE `sys_role_permissions` (
	`id` bigint NOT NULL,
	`role_id` bigint NOT NULL,
	`permission_id` bigint NOT NULL,
	`is_half` tinyint(1) NOT NULL DEFAULT 0,
	`created_by` bigint,
	`created_at` datetime NOT NULL DEFAULT (CURRENT_TIMESTAMP),
	CONSTRAINT `sys_role_permissions_id` PRIMARY KEY(`id`),
	CONSTRAINT `uk_role_permission` UNIQUE(`role_id`,`permission_id`)
);
--> statement-breakpoint
CREATE TABLE `sys_roles` (
	`id` bigint NOT NULL,
	`code` varchar(50) NOT NULL,
	`name` varchar(100) NOT NULL,
	`description` text,
	`pid` bigint DEFAULT 0,
	`path` varchar(500),
	`level` int NOT NULL DEFAULT 1,
	`sort_order` int NOT NULL DEFAULT 0,
	`status` varchar(20) NOT NULL DEFAULT 'active',
	`is_system` tinyint(1) NOT NULL DEFAULT 0,
	`permissions_snapshot` json,
	`extra` json,
	`created_by` bigint,
	`created_at` datetime NOT NULL DEFAULT (CURRENT_TIMESTAMP),
	`updated_by` bigint,
	`updated_at` datetime NOT NULL DEFAULT (CURRENT_TIMESTAMP),
	`deleted_at` datetime,
	`version` int NOT NULL DEFAULT 1,
	CONSTRAINT `sys_roles_id` PRIMARY KEY(`id`),
	CONSTRAINT `uk_code` UNIQUE(`code`,`deleted_at`)
);
--> statement-breakpoint
CREATE TABLE `sys_tags` (
	`id` bigint NOT NULL,
	`name` varchar(50) NOT NULL,
	`type` varchar(50) DEFAULT 'user',
	`color` varchar(50),
	`description` text,
	`usage_count` int NOT NULL DEFAULT 0,
	`created_by` bigint,
	`created_at` datetime NOT NULL DEFAULT (CURRENT_TIMESTAMP),
	`deleted_at` datetime,
	CONSTRAINT `sys_tags_id` PRIMARY KEY(`id`),
	CONSTRAINT `uk_name_type` UNIQUE(`name`,`type`,`deleted_at`)
);
--> statement-breakpoint
CREATE TABLE `sys_user_organizations` (
	`id` bigint NOT NULL,
	`user_id` bigint NOT NULL,
	`organization_id` bigint NOT NULL,
	`is_primary` tinyint(1) NOT NULL DEFAULT 0,
	`position` varchar(100),
	`joined_at` datetime NOT NULL DEFAULT (CURRENT_TIMESTAMP),
	`created_by` bigint,
	`created_at` datetime NOT NULL DEFAULT (CURRENT_TIMESTAMP),
	CONSTRAINT `sys_user_organizations_id` PRIMARY KEY(`id`),
	CONSTRAINT `uk_user_org` UNIQUE(`user_id`,`organization_id`)
);
--> statement-breakpoint
CREATE TABLE `sys_user_roles` (
	`id` bigint NOT NULL,
	`user_id` bigint NOT NULL,
	`role_id` bigint NOT NULL,
	`expired_at` datetime,
	`created_by` bigint,
	`created_at` datetime NOT NULL DEFAULT (CURRENT_TIMESTAMP),
	CONSTRAINT `sys_user_roles_id` PRIMARY KEY(`id`),
	CONSTRAINT `uk_user_role` UNIQUE(`user_id`,`role_id`)
);
--> statement-breakpoint
CREATE TABLE `sys_user_tags` (
	`id` bigint NOT NULL,
	`user_id` bigint NOT NULL,
	`tag_id` bigint NOT NULL,
	`created_by` bigint,
	`created_at` datetime NOT NULL DEFAULT (CURRENT_TIMESTAMP),
	CONSTRAINT `sys_user_tags_id` PRIMARY KEY(`id`),
	CONSTRAINT `uk_user_tag` UNIQUE(`user_id`,`tag_id`)
);
--> statement-breakpoint
CREATE TABLE `sys_users` (
	`id` bigint NOT NULL,
	`username` varchar(50) NOT NULL,
	`email` varchar(100) NOT NULL,
	`mobile` varchar(20),
	`password_hash` varchar(255) NOT NULL,
	`avatar` varchar(255),
	`nickname` varchar(100),
	`status` varchar(20) NOT NULL DEFAULT 'active',
	`gender` tinyint DEFAULT 0,
	`birthday` date,
	`bio` varchar(500),
	`login_count` int NOT NULL DEFAULT 0,
	`last_login_at` datetime,
	`last_login_ip` varchar(45),
	`failed_attempts` int NOT NULL DEFAULT 0,
	`locked_until` datetime,
	`is_root` tinyint(1) NOT NULL DEFAULT 0,
	`extra` json,
	`created_by` bigint,
	`created_at` datetime NOT NULL DEFAULT (CURRENT_TIMESTAMP),
	`updated_by` bigint,
	`updated_at` datetime NOT NULL DEFAULT (CURRENT_TIMESTAMP),
	`deleted_at` datetime,
	`version` int NOT NULL DEFAULT 1,
	CONSTRAINT `sys_users_id` PRIMARY KEY(`id`),
	CONSTRAINT `uk_email` UNIQUE(`email`,`deleted_at`),
	CONSTRAINT `uk_username` UNIQUE(`username`,`deleted_at`)
);
--> statement-breakpoint
CREATE INDEX `idx_deleted_at` ON `sys_dict_items` (`deleted_at`);--> statement-breakpoint
CREATE INDEX `idx_key` ON `sys_dict_items` (`item_key`);--> statement-breakpoint
CREATE INDEX `idx_pid` ON `sys_dict_items` (`pid`);--> statement-breakpoint
CREATE INDEX `idx_sort` ON `sys_dict_items` (`type_id`,`sort_order`);--> statement-breakpoint
CREATE INDEX `idx_status` ON `sys_dict_items` (`status`);--> statement-breakpoint
CREATE INDEX `idx_type_id` ON `sys_dict_items` (`type_id`);--> statement-breakpoint
CREATE INDEX `idx_deleted_at` ON `sys_dict_types` (`deleted_at`);--> statement-breakpoint
CREATE INDEX `idx_is_system` ON `sys_dict_types` (`is_system`);--> statement-breakpoint
CREATE INDEX `idx_name` ON `sys_dict_types` (`name`);--> statement-breakpoint
CREATE INDEX `idx_path` ON `sys_dict_types` (`path`);--> statement-breakpoint
CREATE INDEX `idx_pid` ON `sys_dict_types` (`pid`);--> statement-breakpoint
CREATE INDEX `idx_sort` ON `sys_dict_types` (`pid`,`sort_order`);--> statement-breakpoint
CREATE INDEX `idx_status` ON `sys_dict_types` (`status`);--> statement-breakpoint
CREATE INDEX `idx_created_at` ON `sys_operation_logs` (`created_at`);--> statement-breakpoint
CREATE INDEX `idx_ip` ON `sys_operation_logs` (`ip`);--> statement-breakpoint
CREATE INDEX `idx_module_action` ON `sys_operation_logs` (`module`,`action`);--> statement-breakpoint
CREATE INDEX `idx_status` ON `sys_operation_logs` (`status`);--> statement-breakpoint
CREATE INDEX `idx_target` ON `sys_operation_logs` (`target_id`);--> statement-breakpoint
CREATE INDEX `idx_user_id` ON `sys_operation_logs` (`user_id`);--> statement-breakpoint
CREATE INDEX `idx_deleted_at` ON `sys_organizations` (`deleted_at`);--> statement-breakpoint
CREATE INDEX `idx_leader_id` ON `sys_organizations` (`leader_id`);--> statement-breakpoint
CREATE INDEX `idx_name` ON `sys_organizations` (`name`);--> statement-breakpoint
CREATE INDEX `idx_path` ON `sys_organizations` (`path`);--> statement-breakpoint
CREATE INDEX `idx_pid` ON `sys_organizations` (`pid`);--> statement-breakpoint
CREATE INDEX `idx_sort` ON `sys_organizations` (`pid`,`sort_order`);--> statement-breakpoint
CREATE INDEX `idx_status` ON `sys_organizations` (`status`);--> statement-breakpoint
CREATE INDEX `idx_type` ON `sys_organizations` (`type`);--> statement-breakpoint
CREATE INDEX `idx_deleted_at` ON `sys_permissions` (`deleted_at`);--> statement-breakpoint
CREATE INDEX `idx_pid` ON `sys_permissions` (`pid`);--> statement-breakpoint
CREATE INDEX `idx_resource_action` ON `sys_permissions` (`resource`,`action`);--> statement-breakpoint
CREATE INDEX `idx_sort` ON `sys_permissions` (`pid`,`sort_order`);--> statement-breakpoint
CREATE INDEX `idx_status` ON `sys_permissions` (`status`);--> statement-breakpoint
CREATE INDEX `idx_type` ON `sys_permissions` (`type`);--> statement-breakpoint
CREATE INDEX `idx_is_half` ON `sys_role_permissions` (`is_half`);--> statement-breakpoint
CREATE INDEX `idx_permission_id` ON `sys_role_permissions` (`permission_id`);--> statement-breakpoint
CREATE INDEX `idx_role_id` ON `sys_role_permissions` (`role_id`);--> statement-breakpoint
CREATE INDEX `idx_deleted_at` ON `sys_roles` (`deleted_at`);--> statement-breakpoint
CREATE INDEX `idx_is_system` ON `sys_roles` (`is_system`);--> statement-breakpoint
CREATE INDEX `idx_name` ON `sys_roles` (`name`);--> statement-breakpoint
CREATE INDEX `idx_path` ON `sys_roles` (`path`);--> statement-breakpoint
CREATE INDEX `idx_pid` ON `sys_roles` (`pid`);--> statement-breakpoint
CREATE INDEX `idx_sort` ON `sys_roles` (`pid`,`sort_order`);--> statement-breakpoint
CREATE INDEX `idx_status` ON `sys_roles` (`status`);--> statement-breakpoint
CREATE INDEX `idx_deleted_at` ON `sys_tags` (`deleted_at`);--> statement-breakpoint
CREATE INDEX `idx_name` ON `sys_tags` (`name`);--> statement-breakpoint
CREATE INDEX `idx_type` ON `sys_tags` (`type`);--> statement-breakpoint
CREATE INDEX `idx_usage_count` ON `sys_tags` (`usage_count`);--> statement-breakpoint
CREATE INDEX `idx_is_primary` ON `sys_user_organizations` (`is_primary`);--> statement-breakpoint
CREATE INDEX `idx_joined_at` ON `sys_user_organizations` (`joined_at`);--> statement-breakpoint
CREATE INDEX `idx_organization_id` ON `sys_user_organizations` (`organization_id`);--> statement-breakpoint
CREATE INDEX `idx_user_id` ON `sys_user_organizations` (`user_id`);--> statement-breakpoint
CREATE INDEX `idx_created_at` ON `sys_user_roles` (`created_at`);--> statement-breakpoint
CREATE INDEX `idx_expired_at` ON `sys_user_roles` (`expired_at`);--> statement-breakpoint
CREATE INDEX `idx_role_id` ON `sys_user_roles` (`role_id`);--> statement-breakpoint
CREATE INDEX `idx_user_id` ON `sys_user_roles` (`user_id`);--> statement-breakpoint
CREATE INDEX `idx_created_at` ON `sys_user_tags` (`created_at`);--> statement-breakpoint
CREATE INDEX `idx_tag_id` ON `sys_user_tags` (`tag_id`);--> statement-breakpoint
CREATE INDEX `idx_user_id` ON `sys_user_tags` (`user_id`);--> statement-breakpoint
CREATE INDEX `idx_created_at` ON `sys_users` (`created_at`);--> statement-breakpoint
CREATE INDEX `idx_deleted_at` ON `sys_users` (`deleted_at`);--> statement-breakpoint
CREATE INDEX `idx_is_root` ON `sys_users` (`is_root`);--> statement-breakpoint
CREATE INDEX `idx_last_login` ON `sys_users` (`last_login_at`);--> statement-breakpoint
CREATE INDEX `idx_mobile` ON `sys_users` (`mobile`);--> statement-breakpoint
CREATE INDEX `idx_status` ON `sys_users` (`status`);
*/