CREATE TABLE `external_access_pending` (
	`id` varchar(36) NOT NULL,
	`resource_name` varchar(100) NOT NULL,
	`link` varchar(500) NOT NULL,
	`login` varchar(100) NOT NULL,
	`password` varchar(100) NOT NULL,
	`comment` text,
	`status` varchar(20) NOT NULL DEFAULT 'pending',
	`target_id` varchar(36),
	`created_by` varchar(36),
	`reviewed_by` varchar(36),
	`reviewed_at` timestamp,
	`rejection_reason` text,
	`created_at` timestamp NOT NULL DEFAULT (now()),
	`updated_at` timestamp NOT NULL DEFAULT (now()) ON UPDATE CURRENT_TIMESTAMP,
	CONSTRAINT `external_access_pending_id` PRIMARY KEY(`id`)
);
--> statement-breakpoint
CREATE TABLE `role_session_policies` (
	`id` varchar(36) NOT NULL,
	`role` varchar(50) NOT NULL,
	`logout_time` varchar(5),
	`inactivity_timeout` int,
	`session_duration` int,
	`created_at` timestamp NOT NULL DEFAULT (now()),
	`updated_at` timestamp NOT NULL DEFAULT (now()) ON UPDATE CURRENT_TIMESTAMP,
	CONSTRAINT `role_session_policies_id` PRIMARY KEY(`id`),
	CONSTRAINT `unique_session_policy_role` UNIQUE(`role`)
);
--> statement-breakpoint
ALTER TABLE `users` ADD `last_activity_at` timestamp;--> statement-breakpoint
ALTER TABLE `external_access` ADD `is_approved` boolean DEFAULT false NOT NULL;--> statement-breakpoint
ALTER TABLE `external_access` ADD `created_by` varchar(36);--> statement-breakpoint
ALTER TABLE `contractors` ADD `responsible_managers` json;--> statement-breakpoint
ALTER TABLE `contractors_pending` ADD `responsible_managers` json;