Skip to content

Instantly share code, notes, and snippets.

@gahabeen
Created June 25, 2025 16:42
Show Gist options
  • Save gahabeen/b6a2c647479c0bf36d51e8cddf0c4614 to your computer and use it in GitHub Desktop.
Save gahabeen/b6a2c647479c0bf36d51e8cddf0c4614 to your computer and use it in GitHub Desktop.
diff --git a/node_modules/drizzle-kit/.bun-tag-469926db1e5d574e b/.bun-tag-469926db1e5d574e
new file mode 100644
index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391
diff --git a/node_modules/drizzle-kit/.bun-tag-4e553d2f75b4d8e0 b/.bun-tag-4e553d2f75b4d8e0
new file mode 100644
index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391
diff --git a/bin.cjs b/bin.cjs
index bedabc839ed5b87ff6794113f702edc5a323bd0f..ec6e8a557d27f9d6e56c2fd31b58494ded011e08 100755
--- a/bin.cjs
+++ b/bin.cjs
@@ -6478,18 +6478,38 @@ var init_pgSchema = __esm({
on: splitted[6] !== "undefined" ? splitted[6] : void 0
};
},
- squashPolicyPush: (policy5) => {
- var _a2;
- return `${policy5.name}--${policy5.as}--${policy5.for}--${(_a2 = policy5.to) == null ? void 0 : _a2.join(",")}--${policy5.on}`;
+ squashPolicyPush: (policy4) => {
+ const toList = policy4.to?.join(",") ?? "";
+ return [
+ policy4.name,
+ policy4.as,
+ policy4.for,
+ toList,
+ policy4.using ?? "undefined",
+ policy4.withCheck ?? "undefined",
+ policy4.on ?? "undefined",
+ ].join("--");
},
- unsquashPolicyPush: (policy5) => {
- const splitted = policy5.split("--");
+
+ unsquashPolicyPush: (policyString) => {
+ const [
+ name,
+ as,
+ forOp,
+ toList,
+ using,
+ withCheck,
+ on,
+ ] = policyString.split("--");
+
return {
- name: splitted[0],
- as: splitted[1],
- for: splitted[2],
- to: splitted[3].split(","),
- on: splitted[4] !== "undefined" ? splitted[4] : void 0
+ name,
+ as,
+ for: forOp,
+ to: toList ? toList.split(",") : [],
+ using: using !== "undefined" ? using : undefined,
+ withCheck: withCheck !== "undefined" ? withCheck : undefined,
+ on: on !== "undefined" ? on : undefined,
};
},
squashPK: (pk) => {
@@ -18920,24 +18940,25 @@ ${withStyle.errorWarning(
});
}
}
- if (policiesObject[policy5.name] !== void 0) {
- console.log(
- `
-${withStyle.errorWarning(
- `We've found duplicated policy name across ${source_default.underline.blue(tableKey2)} table. Please rename one of the policies with ${source_default.underline.blue(
- policy5.name
- )} name`
- )}`
- );
- process.exit(1);
+ const policyFor = ((_b2 = policy5.for) == null ? void 0 : _b2.toUpperCase()) ?? "ALL";
+ let usingClause, withCheckClause;
+ if (policyFor === "SELECT" || policyFor === "DELETE") {
+ usingClause = (0, import_drizzle_orm4.is)(policy5.using, import_drizzle_orm4.SQL) ? dialect6.sqlToQuery(policy5.using).sql : void 0;
+ withCheckClause = undefined;
+ } else if (policyFor === "INSERT") {
+ usingClause = undefined;
+ withCheckClause = (0, import_drizzle_orm4.is)(policy5.withCheck, import_drizzle_orm4.SQL) ? dialect6.sqlToQuery(policy5.withCheck).sql : void 0;
+ } else if (policyFor === "UPDATE" || policyFor === "ALL") {
+ usingClause = (0, import_drizzle_orm4.is)(policy5.using, import_drizzle_orm4.SQL) ? dialect6.sqlToQuery(policy5.using).sql : void 0;
+ withCheckClause = (0, import_drizzle_orm4.is)(policy5.withCheck, import_drizzle_orm4.SQL) ? dialect6.sqlToQuery(policy5.withCheck).sql : void 0;
}
policiesObject[policy5.name] = {
name: policy5.name,
as: ((_a3 = policy5.as) == null ? void 0 : _a3.toUpperCase()) ?? "PERMISSIVE",
- for: ((_b2 = policy5.for) == null ? void 0 : _b2.toUpperCase()) ?? "ALL",
+ for: policyFor,
to: mappedTo.sort(),
- using: (0, import_drizzle_orm4.is)(policy5.using, import_drizzle_orm4.SQL) ? dialect6.sqlToQuery(policy5.using).sql : void 0,
- withCheck: (0, import_drizzle_orm4.is)(policy5.withCheck, import_drizzle_orm4.SQL) ? dialect6.sqlToQuery(policy5.withCheck).sql : void 0
+ ...(usingClause !== undefined ? { using: usingClause } : {}),
+ ...(withCheckClause !== undefined ? { withCheck: withCheckClause } : {})
};
});
checks.forEach((check2) => {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment