ALTER TABLE `users` ADD `region_code` varchar(20);--> statement-breakpoint
ALTER TABLE `users` ADD `region_selected_at` datetime;--> statement-breakpoint
ALTER TABLE `users` ADD `region_changed_at` datetime;--> statement-breakpoint
CREATE INDEX `idx_users_region` ON `users` (`region_code`);--> statement-breakpoint
CREATE TABLE `user_region_change_logs` (
	`id` char(36) NOT NULL,
	`user_id` char(36) NOT NULL,
	`from_region_code` varchar(20),
	`to_region_code` varchar(20) NOT NULL,
	`changed_at` datetime DEFAULT CURRENT_TIMESTAMP,
	`created_at` datetime DEFAULT CURRENT_TIMESTAMP,
	CONSTRAINT `user_region_change_logs_id` PRIMARY KEY(`id`)
);--> statement-breakpoint
ALTER TABLE `user_region_change_logs` ADD CONSTRAINT `user_region_change_logs_user_id_users_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users`(`id`) ON DELETE no action ON UPDATE no action;--> statement-breakpoint
CREATE INDEX `idx_region_change_user_changed` ON `user_region_change_logs` (`user_id`,`changed_at`);
