CREATE TABLE "post_media" (
	"project_id" uuid NOT NULL,
	"media_id" uuid NOT NULL,
	CONSTRAINT "post_media_project_id_media_id_pk" PRIMARY KEY("project_id","media_id")
);
--> statement-breakpoint
ALTER TABLE "posts" ADD COLUMN "main_tag_id" uuid;--> statement-breakpoint
ALTER TABLE "posts" ADD COLUMN "preview_id" uuid;--> statement-breakpoint
ALTER TABLE "post_media" ADD CONSTRAINT "post_media_project_id_posts_id_fk" FOREIGN KEY ("project_id") REFERENCES "public"."posts"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "post_media" ADD CONSTRAINT "post_media_media_id_media_id_fk" FOREIGN KEY ("media_id") REFERENCES "public"."media"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
CREATE INDEX "post_media_post_id_index" ON "post_media" USING btree ("project_id");--> statement-breakpoint
CREATE INDEX "post_media_media_id_index" ON "post_media" USING btree ("media_id");--> statement-breakpoint
ALTER TABLE "posts" ADD CONSTRAINT "posts_main_tag_id_tags_id_fk" FOREIGN KEY ("main_tag_id") REFERENCES "public"."tags"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "posts" ADD CONSTRAINT "posts_preview_id_media_id_fk" FOREIGN KEY ("preview_id") REFERENCES "public"."media"("id") ON DELETE set null ON UPDATE no action;