@authhero/drizzle 1.6.2 → 1.7.1

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,18 @@
1
+ -- One client grant per (tenant_id, client_id, audience) — the constraint
2
+ -- kysely has always enforced (same index name), which drizzle was missing
3
+ -- (#1360). Without it a duplicate pair is silently accepted and scope
4
+ -- resolution picks an arbitrary row.
5
+ --
6
+ -- Existing databases may already hold duplicates, so dedupe first: keep the
7
+ -- newest row per pair (latest created_at, then highest rowid).
8
+ DELETE FROM `client_grants` WHERE `rowid` IN (
9
+ SELECT `rowid` FROM (
10
+ SELECT `rowid`, ROW_NUMBER() OVER (
11
+ PARTITION BY `tenant_id`, `client_id`, `audience`
12
+ ORDER BY `created_at` DESC, `rowid` DESC
13
+ ) AS `rn`
14
+ FROM `client_grants`
15
+ )
16
+ WHERE `rn` > 1
17
+ );--> statement-breakpoint
18
+ CREATE UNIQUE INDEX `uq_client_grants_tenant_client_audience` ON `client_grants` (`tenant_id`,`client_id`,`audience`);