@authhero/drizzle 1.7.0 → 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.
package/dist/drizzle-adapter.mjs
CHANGED
|
@@ -431,10 +431,14 @@ var Ie = Object.defineProperty, Le = (e, t) => {
|
|
|
431
431
|
authorization_details_types: T("authorization_details_types").default("[]"),
|
|
432
432
|
created_at: T("created_at", { length: 35 }).notNull(),
|
|
433
433
|
updated_at: T("updated_at", { length: 35 }).notNull()
|
|
434
|
-
}, (e) => [
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
434
|
+
}, (e) => [
|
|
435
|
+
C({
|
|
436
|
+
columns: [e.tenant_id, e.id],
|
|
437
|
+
name: "pk_client_grants"
|
|
438
|
+
}),
|
|
439
|
+
x("idx_client_grants_audience").on(e.audience),
|
|
440
|
+
re("uq_client_grants_tenant_client_audience").on(e.tenant_id, e.client_id, e.audience)
|
|
441
|
+
]), z = w("grants", {
|
|
438
442
|
id: T("id", { length: 21 }).primaryKey(),
|
|
439
443
|
tenant_id: T("tenant_id", { length: 255 }).notNull().references(() => O.id, { onDelete: "cascade" }),
|
|
440
444
|
user_id: T("user_id", { length: 255 }).notNull(),
|
|
@@ -1705,7 +1709,7 @@ function Bt(e) {
|
|
|
1705
1709
|
if (d?.sort_by) {
|
|
1706
1710
|
let e = R[d.sort_by];
|
|
1707
1711
|
e && (h = h.orderBy(d.sort_order === "desc" ? i(e) : n(e)));
|
|
1708
|
-
} else h = h.orderBy(
|
|
1712
|
+
} else h = h.orderBy(i(R.created_at), i(R.id));
|
|
1709
1713
|
let g = (await h.offset(c * l).limit(l)).map(zt);
|
|
1710
1714
|
if (!u) return { client_grants: g };
|
|
1711
1715
|
let [_] = await e.select({ count: r() }).from(R).where(m);
|
|
@@ -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`);
|