CREATE TABLE `class_invitation_codes` (
	`id` varchar(128) NOT NULL,
	`class_id` varchar(128) NOT NULL,
	`code` varchar(8) NOT NULL,
	`class_invitation_code_status` enum('active','disabled','expired','exhausted') NOT NULL DEFAULT 'active',
	`max_uses` int,
	`used_count` int NOT NULL DEFAULT 0,
	`expires_at` timestamp,
	`created_by` varchar(128) NOT NULL,
	`created_at` timestamp NOT NULL DEFAULT (now()),
	`updated_at` timestamp NOT NULL DEFAULT (now()) ON UPDATE CURRENT_TIMESTAMP,
	`revoked_at` timestamp,
	`revoked_by` varchar(128),
	`note` varchar(255),
	CONSTRAINT `class_invitation_codes_id` PRIMARY KEY(`id`),
	CONSTRAINT `class_invitation_codes_code_unique` UNIQUE(`code`),
	CONSTRAINT `class_invitation_codes_code_idx` UNIQUE(`code`)
);
--> statement-breakpoint
CREATE TABLE `system_settings` (
	`id` varchar(128) NOT NULL,
	`category` varchar(50) NOT NULL,
	`key` varchar(100) NOT NULL,
	`value` text NOT NULL,
	`value_type` varchar(20) NOT NULL DEFAULT 'string',
	`updated_by` varchar(128),
	`created_at` timestamp NOT NULL DEFAULT (now()),
	`updated_at` timestamp NOT NULL DEFAULT (now()) ON UPDATE CURRENT_TIMESTAMP,
	CONSTRAINT `system_settings_id` PRIMARY KEY(`id`),
	CONSTRAINT `ss_category_key_idx` UNIQUE(`category`,`key`)
);
--> statement-breakpoint
ALTER TABLE `homework_assignments` MODIFY COLUMN `source_exam_id` varchar(128);--> statement-breakpoint
ALTER TABLE `learning_diagnostic_reports` MODIFY COLUMN `student_id` varchar(128);--> statement-breakpoint
ALTER TABLE `messages` ADD `sender_deleted_at` timestamp;--> statement-breakpoint
ALTER TABLE `messages` ADD `receiver_deleted_at` timestamp;--> statement-breakpoint
ALTER TABLE `notification_preferences` ADD `quiet_hours_enabled` boolean DEFAULT false NOT NULL;--> statement-breakpoint
ALTER TABLE `notification_preferences` ADD `quiet_hours_start` varchar(5);--> statement-breakpoint
ALTER TABLE `notification_preferences` ADD `quiet_hours_end` varchar(5);--> statement-breakpoint
ALTER TABLE `class_invitation_codes` ADD CONSTRAINT `class_invitation_codes_class_id_classes_id_fk` FOREIGN KEY (`class_id`) REFERENCES `classes`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE `class_invitation_codes` ADD CONSTRAINT `class_invitation_codes_created_by_users_id_fk` FOREIGN KEY (`created_by`) REFERENCES `users`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE `class_invitation_codes` ADD CONSTRAINT `cic_c_fk` FOREIGN KEY (`class_id`) REFERENCES `classes`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
CREATE INDEX `class_invitation_codes_class_idx` ON `class_invitation_codes` (`class_id`);--> statement-breakpoint
CREATE INDEX `class_invitation_codes_status_expires_idx` ON `class_invitation_codes` (`class_invitation_code_status`,`expires_at`);--> statement-breakpoint
CREATE INDEX `ss_category_idx` ON `system_settings` (`category`);