DROP INDEX `idx_entities_relations_source_key_target_to_source_relation_target_key`;--> statement-breakpoint
ALTER TABLE `entities_relations` ADD `source_version` text;--> statement-breakpoint
ALTER TABLE `entities_relations` ADD `source_revision` text;--> statement-breakpoint
ALTER TABLE `entities_relations` ADD `target_version` text;--> statement-breakpoint
ALTER TABLE `entities_relations` ADD `target_revision` text;--> statement-breakpoint
CREATE UNIQUE INDEX `idx_entities_relations_unique` ON `entities_relations` (`source_key`,`target_key`,`source_version`,`target_version`,`source_revision`,`target_revision`);--> statement-breakpoint
ALTER TABLE `entities_relations` DROP COLUMN `schema_version`;--> statement-breakpoint
DROP INDEX `entities_key_unique`;--> statement-breakpoint
DROP INDEX `idx_entities_key_source`;--> statement-breakpoint
ALTER TABLE `entities` ADD `version` text;--> statement-breakpoint
ALTER TABLE `entities` ADD `revision` text;--> statement-breakpoint
ALTER TABLE `entities` ADD `hash` text;--> statement-breakpoint
ALTER TABLE `entities` ADD `is_current` integer DEFAULT true;--> statement-breakpoint
ALTER TABLE `entities` ADD `is_default_version` integer DEFAULT false;--> statement-breakpoint
CREATE INDEX `idx_entities_hash` ON `entities` (`hash`);--> statement-breakpoint
CREATE INDEX `idx_entities_key_source_created_at` ON `entities` (`key`,`created_at`);--> statement-breakpoint
CREATE INDEX `idx_entities_key_source_is_current` ON `entities` (`key`,`is_current`);--> statement-breakpoint
CREATE INDEX `idx_entities_key_source_is_default` ON `entities` (`key`,`is_default_version`);--> statement-breakpoint
CREATE UNIQUE INDEX `idx_entities_key_source` ON `entities` (`key`,`source`,`revision`,`version`);--> statement-breakpoint
ALTER TABLE `entities` DROP COLUMN `schema_version`;