@penclipai/db 2026.414.2 → 2026.418.0-canary.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,22 @@
1
+ CREATE TABLE "company_user_sidebar_preferences" (
2
+ "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
3
+ "company_id" uuid NOT NULL,
4
+ "user_id" text NOT NULL,
5
+ "project_order" jsonb DEFAULT '[]'::jsonb NOT NULL,
6
+ "created_at" timestamp with time zone DEFAULT now() NOT NULL,
7
+ "updated_at" timestamp with time zone DEFAULT now() NOT NULL
8
+ );
9
+ --> statement-breakpoint
10
+ CREATE TABLE "user_sidebar_preferences" (
11
+ "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
12
+ "user_id" text NOT NULL,
13
+ "company_order" jsonb DEFAULT '[]'::jsonb NOT NULL,
14
+ "created_at" timestamp with time zone DEFAULT now() NOT NULL,
15
+ "updated_at" timestamp with time zone DEFAULT now() NOT NULL
16
+ );
17
+ --> statement-breakpoint
18
+ ALTER TABLE "company_user_sidebar_preferences" ADD CONSTRAINT "company_user_sidebar_preferences_company_id_companies_id_fk" FOREIGN KEY ("company_id") REFERENCES "public"."companies"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
19
+ CREATE INDEX "company_user_sidebar_preferences_company_idx" ON "company_user_sidebar_preferences" USING btree ("company_id");--> statement-breakpoint
20
+ CREATE INDEX "company_user_sidebar_preferences_user_idx" ON "company_user_sidebar_preferences" USING btree ("user_id");--> statement-breakpoint
21
+ CREATE UNIQUE INDEX "company_user_sidebar_preferences_company_user_uq" ON "company_user_sidebar_preferences" USING btree ("company_id","user_id");--> statement-breakpoint
22
+ CREATE UNIQUE INDEX "user_sidebar_preferences_user_uq" ON "user_sidebar_preferences" USING btree ("user_id");
@@ -0,0 +1,57 @@
1
+ WITH ranked_user_requests AS (
2
+ SELECT
3
+ id,
4
+ row_number() OVER (
5
+ PARTITION BY company_id, requesting_user_id
6
+ ORDER BY created_at ASC, id ASC
7
+ ) AS rank
8
+ FROM join_requests
9
+ WHERE request_type = 'human'
10
+ AND status = 'pending_approval'
11
+ AND requesting_user_id IS NOT NULL
12
+ )
13
+ UPDATE join_requests
14
+ SET
15
+ status = 'rejected',
16
+ rejected_at = COALESCE(rejected_at, now()),
17
+ updated_at = now()
18
+ WHERE id IN (
19
+ SELECT id
20
+ FROM ranked_user_requests
21
+ WHERE rank > 1
22
+ );
23
+ --> statement-breakpoint
24
+ WITH ranked_email_requests AS (
25
+ SELECT
26
+ id,
27
+ row_number() OVER (
28
+ PARTITION BY company_id, lower(request_email_snapshot)
29
+ ORDER BY created_at ASC, id ASC
30
+ ) AS rank
31
+ FROM join_requests
32
+ WHERE request_type = 'human'
33
+ AND status = 'pending_approval'
34
+ AND request_email_snapshot IS NOT NULL
35
+ )
36
+ UPDATE join_requests
37
+ SET
38
+ status = 'rejected',
39
+ rejected_at = COALESCE(rejected_at, now()),
40
+ updated_at = now()
41
+ WHERE id IN (
42
+ SELECT id
43
+ FROM ranked_email_requests
44
+ WHERE rank > 1
45
+ );
46
+ --> statement-breakpoint
47
+ CREATE UNIQUE INDEX IF NOT EXISTS "join_requests_pending_human_user_uq"
48
+ ON "join_requests" USING btree ("company_id", "requesting_user_id")
49
+ WHERE "request_type" = 'human'
50
+ AND "status" = 'pending_approval'
51
+ AND "requesting_user_id" IS NOT NULL;
52
+ --> statement-breakpoint
53
+ CREATE UNIQUE INDEX IF NOT EXISTS "join_requests_pending_human_email_uq"
54
+ ON "join_requests" USING btree ("company_id", lower("request_email_snapshot"))
55
+ WHERE "request_type" = 'human'
56
+ AND "status" = 'pending_approval'
57
+ AND "request_email_snapshot" IS NOT NULL;