CREATE TABLE `project_change_sets` (
	`id` text PRIMARY KEY NOT NULL,
	`project_revision_id` text NOT NULL,
	`command_type` text NOT NULL,
	`payload_schema_version` integer NOT NULL,
	`forward_payload_json` text NOT NULL,
	`inverse_payload_json` text NOT NULL,
	FOREIGN KEY (`project_revision_id`) REFERENCES `project_revisions`(`id`) ON UPDATE no action ON DELETE cascade
);
--> statement-breakpoint
CREATE UNIQUE INDEX `project_change_sets_revision_unique` ON `project_change_sets` (`project_revision_id`);--> statement-breakpoint
CREATE TABLE `project_revisions` (
	`id` text PRIMARY KEY NOT NULL,
	`project_id` text NOT NULL,
	`revision_number` integer NOT NULL,
	`created_at_iso` text NOT NULL,
	`actor_id` text,
	`source` text NOT NULL,
	`description` text,
	FOREIGN KEY (`project_id`) REFERENCES `projects`(`id`) ON UPDATE no action ON DELETE cascade
);
--> statement-breakpoint
CREATE UNIQUE INDEX `project_revisions_project_number_unique` ON `project_revisions` (`project_id`,`revision_number`);--> statement-breakpoint
ALTER TABLE `projects` ADD `current_revision` integer DEFAULT 0 NOT NULL;
