CREATE TYPE "public"."notification_kind" AS ENUM('task_assigned', 'asset_log_added', 'asset_moved', 'decision_created', 'maintenance_event_recorded', 'generic');--> statement-breakpoint CREATE TABLE "notifications" ( "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL, "user_id" uuid NOT NULL, "company_id" uuid NOT NULL, "kind" "notification_kind" NOT NULL, "title" varchar(255) NOT NULL, "body" text NOT NULL, "link" varchar(1024), "read_at" timestamp with time zone, "created_at" timestamp with time zone DEFAULT now() NOT NULL ); --> statement-breakpoint ALTER TABLE "users" ADD COLUMN "email_notifications" boolean DEFAULT true NOT NULL;--> statement-breakpoint ALTER TABLE "users" ADD COLUMN "matrix_notifications" boolean DEFAULT false NOT NULL;--> statement-breakpoint ALTER TABLE "users" ADD COLUMN "matrix_user_id" varchar(255);--> statement-breakpoint ALTER TABLE "notifications" ADD CONSTRAINT "notifications_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "notifications" ADD CONSTRAINT "notifications_company_id_companies_id_fk" FOREIGN KEY ("company_id") REFERENCES "public"."companies"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint CREATE INDEX "notifications_by_user_unread" ON "notifications" USING btree ("user_id","read_at","created_at");--> statement-breakpoint CREATE INDEX "notifications_by_user_company" ON "notifications" USING btree ("user_id","company_id","created_at");