From e4aeded6c105de6c8af6a931d5c24a659dcbd138 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Wed, 31 Dec 2025 16:07:00 +0900 Subject: feat(crdt): add database migration for crdt_documents table MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add Drizzle migration to create the crdt_documents table with: - UUID primary key with auto-generation - Foreign key to users table with cascade delete - Unique index on (user_id, entity_type, entity_id) - Indexes for entity_type and sync_version queries 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 --- drizzle/0004_clean_leopardon.sql | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 drizzle/0004_clean_leopardon.sql (limited to 'drizzle/0004_clean_leopardon.sql') diff --git a/drizzle/0004_clean_leopardon.sql b/drizzle/0004_clean_leopardon.sql new file mode 100644 index 0000000..95e203d --- /dev/null +++ b/drizzle/0004_clean_leopardon.sql @@ -0,0 +1,15 @@ +CREATE TABLE "crdt_documents" ( + "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL, + "user_id" uuid NOT NULL, + "entity_type" varchar(50) NOT NULL, + "entity_id" uuid NOT NULL, + "binary" varchar(1048576) NOT NULL, + "sync_version" integer DEFAULT 0 NOT NULL, + "created_at" timestamp with time zone DEFAULT now() NOT NULL, + "updated_at" timestamp with time zone DEFAULT now() NOT NULL +); +--> statement-breakpoint +ALTER TABLE "crdt_documents" ADD CONSTRAINT "crdt_documents_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint +CREATE UNIQUE INDEX "crdt_documents_user_entity_idx" ON "crdt_documents" USING btree ("user_id","entity_type","entity_id");--> statement-breakpoint +CREATE INDEX "crdt_documents_entity_type_idx" ON "crdt_documents" USING btree ("entity_type");--> statement-breakpoint +CREATE INDEX "crdt_documents_sync_version_idx" ON "crdt_documents" USING btree ("user_id","sync_version"); \ No newline at end of file -- cgit v1.2.3-70-g09d2