@intentius/chant-lexicon-sql 0.116.0 → 0.117.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.
Files changed (107) hide show
  1. package/dist/codegen/registry.d.ts.map +1 -1
  2. package/dist/config.d.ts +20 -0
  3. package/dist/config.d.ts.map +1 -1
  4. package/dist/index.d.ts +1 -1
  5. package/dist/index.d.ts.map +1 -1
  6. package/dist/integrity.json +5 -5
  7. package/dist/lint/rules/sqlpg001.d.ts.map +1 -1
  8. package/dist/lsp/postgres-template.d.ts.map +1 -1
  9. package/dist/manifest.json +1 -1
  10. package/dist/meta.json +20 -0
  11. package/dist/okf/index.md +4 -0
  12. package/dist/okf/types/PostgresDefaultPrivileges.md +9 -0
  13. package/dist/okf/types/PostgresGrant.md +9 -0
  14. package/dist/okf/types/PostgresPolicy.md +9 -0
  15. package/dist/okf/types/PostgresRole.md +9 -0
  16. package/dist/op/activities/postgres-migration.d.ts.map +1 -1
  17. package/dist/op/activity-contracts.d.ts +10 -0
  18. package/dist/op/activity-contracts.d.ts.map +1 -1
  19. package/dist/plugin.d.ts.map +1 -1
  20. package/dist/postgres/access/acl.d.ts +119 -0
  21. package/dist/postgres/access/acl.d.ts.map +1 -0
  22. package/dist/postgres/access/import.d.ts +13 -0
  23. package/dist/postgres/access/import.d.ts.map +1 -0
  24. package/dist/postgres/access/live.d.ts +24 -0
  25. package/dist/postgres/access/live.d.ts.map +1 -0
  26. package/dist/postgres/apply/apply.d.ts.map +1 -1
  27. package/dist/postgres/apply/statements.d.ts +3 -0
  28. package/dist/postgres/apply/statements.d.ts.map +1 -1
  29. package/dist/postgres/entities.d.ts +106 -4
  30. package/dist/postgres/entities.d.ts.map +1 -1
  31. package/dist/postgres/entity-types.d.ts +4 -0
  32. package/dist/postgres/entity-types.d.ts.map +1 -1
  33. package/dist/postgres/import/generator.d.ts +4 -1
  34. package/dist/postgres/import/generator.d.ts.map +1 -1
  35. package/dist/postgres/import/live-export.d.ts +6 -0
  36. package/dist/postgres/import/live-export.d.ts.map +1 -1
  37. package/dist/postgres/live/bind.d.ts +2 -0
  38. package/dist/postgres/live/bind.d.ts.map +1 -1
  39. package/dist/postgres/live/catalog.d.ts +11 -2
  40. package/dist/postgres/live/catalog.d.ts.map +1 -1
  41. package/dist/postgres/live/describe-resources.d.ts +9 -0
  42. package/dist/postgres/live/describe-resources.d.ts.map +1 -1
  43. package/dist/postgres/migrate/op.d.ts +29 -0
  44. package/dist/postgres/migrate/op.d.ts.map +1 -1
  45. package/dist/postgres/parser.d.ts +76 -3
  46. package/dist/postgres/parser.d.ts.map +1 -1
  47. package/dist/postgres/plan/commands.d.ts +12 -0
  48. package/dist/postgres/plan/commands.d.ts.map +1 -1
  49. package/dist/postgres/plan/deep.d.ts.map +1 -1
  50. package/dist/postgres/plan/diff.d.ts +10 -1
  51. package/dist/postgres/plan/diff.d.ts.map +1 -1
  52. package/dist/postgres/plan/normalize.d.ts +8 -1
  53. package/dist/postgres/plan/normalize.d.ts.map +1 -1
  54. package/dist/postgres/plan/rules.d.ts +8 -0
  55. package/dist/postgres/plan/rules.d.ts.map +1 -1
  56. package/dist/postgres/plan/schema.d.ts +2 -1
  57. package/dist/postgres/plan/schema.d.ts.map +1 -1
  58. package/dist/postgres/plan/server-normalize.d.ts +4 -1
  59. package/dist/postgres/plan/server-normalize.d.ts.map +1 -1
  60. package/dist/postgres.d.ts +1 -1
  61. package/dist/postgres.d.ts.map +1 -1
  62. package/dist/rules/postgres-templates.ts +2 -2
  63. package/dist/rules/sqlpg001.ts +7 -4
  64. package/dist/validate.d.ts.map +1 -1
  65. package/package.json +2 -2
  66. package/src/codegen/registry.ts +4 -0
  67. package/src/config.ts +10 -0
  68. package/src/generated/lexicon-sql.json +20 -0
  69. package/src/index.ts +1 -1
  70. package/src/lint/rules/postgres-templates.ts +2 -2
  71. package/src/lint/rules/sqlpg001.ts +7 -4
  72. package/src/lsp/postgres-template.ts +2 -0
  73. package/src/mcp/postgres.ts +1 -1
  74. package/src/migration-statements.ts +7 -0
  75. package/src/op/activities/postgres-migration.ts +27 -2
  76. package/src/op/activity-contracts.ts +1 -0
  77. package/src/plugin.ts +3 -0
  78. package/src/postgres/access/access.e2e.test.ts +191 -0
  79. package/src/postgres/access/access.test.ts +147 -0
  80. package/src/postgres/access/acl.ts +400 -0
  81. package/src/postgres/access/import.ts +64 -0
  82. package/src/postgres/access/live.ts +123 -0
  83. package/src/postgres/apply/apply.ts +117 -4
  84. package/src/postgres/apply/statements.ts +55 -9
  85. package/src/postgres/entities.ts +287 -11
  86. package/src/postgres/entity-types.ts +4 -0
  87. package/src/postgres/import/generator.ts +14 -4
  88. package/src/postgres/import/live-export.ts +12 -2
  89. package/src/postgres/live/bind.ts +3 -0
  90. package/src/postgres/live/catalog.ts +79 -3
  91. package/src/postgres/live/describe-resources.ts +27 -3
  92. package/src/postgres/migrate/migrate.test.ts +24 -1
  93. package/src/postgres/migrate/op.ts +80 -35
  94. package/src/postgres/migrate/outer.e2e.test.ts +163 -0
  95. package/src/postgres/parser.ts +247 -8
  96. package/src/postgres/plan/commands.ts +60 -7
  97. package/src/postgres/plan/deep.ts +24 -3
  98. package/src/postgres/plan/diff.ts +71 -6
  99. package/src/postgres/plan/normalize.ts +115 -2
  100. package/src/postgres/plan/rules.ts +44 -0
  101. package/src/postgres/plan/schema.ts +4 -2
  102. package/src/postgres/plan/server-normalize.ts +29 -1
  103. package/src/postgres.ts +11 -0
  104. package/src/skill-defs.ts +1 -1
  105. package/src/skills/chant-sql-postgres-migration.md +3 -1
  106. package/src/skills/chant-sql-postgres.md +9 -2
  107. package/src/validate.ts +4 -0
@@ -16,11 +16,18 @@ import { type ChangeSet, type ClassifiedChange } from "../../core/classifier.js"
16
16
  import { matchByIdentity } from "../../core/diff.js";
17
17
  import { type PgChangeClass, type PgClassifierRuleId } from "./rules.js";
18
18
  import { type CanonicalConstraint } from "./normalize.js";
19
+ import { type AccessChange } from "../access/acl.js";
19
20
  import { type PgDiffObject, type PgSchemaObject } from "./schema.js";
20
21
  import type { PostgresMigrationOpSuggestion } from "../migrate/handoff.js";
21
22
  /** What the diff needs to know beyond the two schemas: the server's major (`sql.postgresMajor`, else the newest pinned). */
22
23
  export interface PgDiffOptions {
23
24
  major?: number;
25
+ /**
26
+ * Whether to compare the access the two sides declare (grants, revokes,
27
+ * default privileges). On by default, for a diff between two builds; a plan
28
+ * against a server compares the server's access itself (`./commands.ts`).
29
+ */
30
+ access?: boolean;
24
31
  }
25
32
  export type PgChange = ClassifiedChange<PgClassifierRuleId, PgChangeClass>;
26
33
  export interface PgSchemaDiff extends ChangeSet<PgChange> {
@@ -28,6 +35,8 @@ export interface PgSchemaDiff extends ChangeSet<PgChange> {
28
35
  refused: PgChange[];
29
36
  /** The `PostgresMigrationOp` to run for each refused column rename or type change (#3281). */
30
37
  migrationOps?: PostgresMigrationOpSuggestion[];
38
+ /** The access changes among `changes`, each with its GRANT, REVOKE or ALTER DEFAULT PRIVILEGES statements (#3681). */
39
+ access?: AccessChange[];
31
40
  }
32
41
  /** The rule adding a constraint falls under. */
33
42
  export declare function addConstraintRule(c: CanonicalConstraint): PgClassifierRuleId;
@@ -41,5 +50,5 @@ export declare function addConstraintRule(c: CanonicalConstraint): PgClassifierR
41
50
  * (`../apply/`) match the same way.
42
51
  */
43
52
  export declare function matchPgObjects(before: readonly PgSchemaObject[], after: readonly PgSchemaObject[]): ReturnType<typeof matchByIdentity<PgDiffObject>>;
44
- export declare function diffPgSchemas(before: readonly PgSchemaObject[], after: readonly PgSchemaObject[], options?: PgDiffOptions): PgSchemaDiff;
53
+ export declare function diffPgSchemas(beforeAll: readonly PgSchemaObject[], afterAll: readonly PgSchemaObject[], options?: PgDiffOptions): PgSchemaDiff;
45
54
  //# sourceMappingURL=diff.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"diff.d.ts","sourceRoot":"","sources":["../../../src/postgres/plan/diff.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH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EAAE,QAAQ,EAAE,SAAS,cAAc,EAAE,EAAE,OAAO,GAAE,aAAkB,GAAG,YAAY,CAqClJ"}
@@ -85,7 +85,11 @@ export interface CanonicalConstraint {
85
85
  notValid?: boolean;
86
86
  comment?: string;
87
87
  }
88
- export type CanonicalKind = "schema" | "table" | "index" | "view" | "materializedView" | "sequence" | "enum" | "domain" | "extension" | "function" | "procedure" | "trigger";
88
+ export type CanonicalKind = "schema" | "table" | "index" | "view" | "materializedView" | "sequence" | "enum" | "domain" | "extension" | "function" | "procedure" | "trigger" | "policy" | "role" | "grant" | "defaultPrivileges";
89
+ /** The kinds whose declarations are privileges, compared as the access they add up to (`../access/`), not one by one. */
90
+ export declare const ACCESS_KINDS: ReadonlySet<CanonicalKind>;
91
+ /** The kinds a profile manages only when it says so (`sql.profiles.<env>.access`). */
92
+ export declare const ACCESS_MANAGED_KINDS: ReadonlySet<CanonicalKind>;
89
93
  export interface CanonicalPgObject {
90
94
  kind: CanonicalKind;
91
95
  schema?: string;
@@ -115,6 +119,9 @@ export declare function canonicalSequenceOptions(o: {
115
119
  export declare function canonicalArgType(text: string, defaultSchema: string): string;
116
120
  /** A routine's identity among its overloads: its input parameter types, `(integer,text)`. */
117
121
  export declare function routineSignature(p: Pick<RoutineProps, "args">, defaultSchema: string): string;
122
+ /** A routine named with its parameters as a GRANT writes it (`app.f(int, text)`), as the target the catalog names: `app.f(integer,text)`. */
123
+ export declare function canonicalRoutineTarget(text: string, defaultSchema: string): string;
124
+ export declare function canonicalRoleAttributes(options: readonly string[]): string[];
118
125
  /**
119
126
  * A definition in canonical form. `props` is an entity's props, declared or
120
127
  * parsed from what the server printed; `defaultSchema` qualifies a bare name.
@@ -1 +1 @@
1
- {"version":3,"file":"normalize.d.ts","sourceRoot":"","sources":["../../../src/postgres/plan/normalize.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2CG;AAQH,OAAO,KAAK,EAWV,YAAY,E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IER_RULES: {
84
84
  readonly SQLPG283: PgClassifierRule;
85
85
  readonly SQLPG284: PgClassifierRule;
86
86
  readonly SQLPG285: PgClassifierRule;
87
+ readonly SQLPG290: PgClassifierRule;
88
+ readonly SQLPG291: PgClassifierRule;
89
+ readonly SQLPG292: PgClassifierRule;
90
+ readonly SQLPG293: PgClassifierRule;
91
+ readonly SQLPG294: PgClassifierRule;
92
+ readonly SQLPG296: PgClassifierRule;
93
+ readonly SQLPG297: PgClassifierRule;
94
+ readonly SQLPG298: PgClassifierRule;
87
95
  readonly SQLPG270: PgClassifierRule;
88
96
  };
89
97
  export type PgClassifierRuleId = keyof typeof PG_CLASSIFIER_RULES;
@@ -1 +1 @@
1
- {"version":3,"file":"rules.d.ts","sourceRoot":"","sources":["../../../src/postgres/plan/rules.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAEH,OAAO,EAAkB,KAAK,aAAa,EAAE,KAAK,cAAc,IAAI,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAErH,MAAM,MAAM,aAAa,GAAG,UAAU,GAAG,UAAU,GAAG,cAAc,GAAG,SAAS,GAAG,QAAQ,GAAG,QAAQ,GAAG,MAAM,CAAC;AAEhH,MAAM,MAAM,gBAAgB,GAAG,iBAAiB,CAAC,aAAa,CAAC,CAAC;AAEhE,eAAO,MAAM,iBAAiB,EAAE,aAAa,CAAC,aAAa,CAY1D,CAAC;AASF,eAAO,MAAM,mBAAmB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA6PqB,CAAC;AAEtD,MAAM,MAAM,kBAAkB,GAAG,MAAM,OAAO,mBAAmB,CAAC"}
1
+ {"version":3,"file":"rules.d.ts","sourceRoot":"","sources":["../../../src/postgres/plan/rules.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAEH,OAAO,EAAkB,KAAK,aAAa,EAAE,KAAK,cAAc,IAAI,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAErH,MAAM,MAAM,aAAa,GAAG,UAAU,GAAG,UAAU,GAAG,cAAc,GAAG,SAAS,GAAG,QAAQ,GAAG,QAAQ,GAAG,MAAM,CAAC;AAEhH,MAAM,MAAM,gBAAgB,GAAG,iBAAiB,CAAC,aAAa,CAAC,CAAC;AAEhE,eAAO,MAAM,iBAAiB,EAAE,aAAa,CAAC,aAAa,CAY1D,CAAC;AASF,eAAO,MAAM,mBAAmB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAySqB,CAAC;AAEtD,MAAM,MAAM,kBAAkB,GAAG,MAAM,OAAO,mBAAmB,CAAC"}
@@ -43,7 +43,8 @@ export declare function pgSchemaFromBuildFile(path: string, defaultSchema?: stri
43
43
  * The namespace an object's name is unique in: relations (tables, views,
44
44
  * sequences, indexes) share one per schema, types and domains another,
45
45
  * functions and procedures a third (told apart by their parameter types),
46
- * and a trigger's name is unique on its table.
46
+ * a trigger's or a policy's name is unique on its table, and a role's in the
47
+ * cluster.
47
48
  */
48
49
  export declare function pgNamespace(kind: string): string;
49
50
  /** The identity an object has on a server: its kind's namespace, its qualified name, and its signature where it has one. */
@@ -1 +1 @@
1
- {"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../../src/postgres/plan/schema.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAE7C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAEpD,OAAO,EAAqB,KAAK,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAGxE,oHAAoH;AACpH,MAAM,WAAW,YAAa,SAAQ,iBAAiB;IACrD,IAAI,EAAE,MAAM,CAAC;IACb,qDAAqD;IACrD,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,2DAA2D;IAC3D,gBAAgB,EAAE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IAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CAAE,CAajG;AAED,oEAAoE;AACpE,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,GAAG,YAAY,CAgBzF;AAQD,+EAA+E;AAC/E,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,MAAM,EAAE,aAAa,SAAW,GAAG,cAAc,EAAE,CAIhG;AAED,8GAA8G;AAC9G,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAG7D;AAED,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAEjE;AAED,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,MAAM,EAAE,aAAa,SAAW,GAAG,cAAc,EAAE,CAE9F;AAED;;;;;;GAMG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAMhD;AAED,4HAA4H;AAC5H,wBAAgB,YAAY,CAAC,CAAC,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,SAAS,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,MAAM,CAE3G;AAED,uFAAuF;AACvF,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,SAAS,cAAc,EAAE,GAAG,cAAc,EAAE,CAEzF;AAED,wEAAwE;AACxE,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,SAAS,YAAY,EAAE,EAAE,aAAa,EAAE,MAAM,GAAG,cAAc,EAAE,CAUvG"}
@@ -8,7 +8,10 @@
8
8
  * (`CREATE TEMP VIEW`, or a `CREATE TEMP TABLE` holding the columns' types,
9
9
  * defaults and generated expressions and the checks) inside a transaction
10
10
  * that is always rolled back, with a short `lock_timeout`, and read back with
11
- * the same printers the catalog read uses. Nothing is left behind: Postgres
11
+ * the same printers the catalog read uses. A trigger's `WHEN` and a policy's
12
+ * `USING` and `WITH CHECK`, which the server prints with the casts it
13
+ * resolved, are read back from a trigger or policy on a temporary copy of the
14
+ * table (`CREATE TEMP TABLE ... (LIKE table)`). Nothing is left behind: Postgres
12
15
  * DDL is transactional and a temporary object lives in the session's own
13
16
  * schema. A server that refuses (no TEMP privilege, a lock not granted in
14
17
  * time, an expression it rejects) leaves the rules' answer standing.
@@ -1 +1 @@
1
- {"version":3,"file":"server-normalize.d.ts","sourceRoot":"","sources":["../../../src/postgres/plan/server-normalize.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAErD,OAAO,EAAiB,KAAK,iBAAiB,EAAE,MAAM,aAAa,CAAC;AA4FpE;;;;GAIG;AACH,wBAAsB,gBAAgB,CAAC,CAAC,SAAS,iBAAiB,GAAG;IAAE,OAAO,CAAC,EAAE,MAAM,EAAE,CAAA;CAAE,EAAE,MAAM,EAAE,cAAc,EAAE,CAAC,EAAE,CAAC,EAAE,aAAa,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,CAAC,CA+B5J"}
1
+ {"version":3,"file":"server-normalize.d.ts","sourceRoot":"","sources":["../../../src/postgres/plan/server-normalize.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAErD,OAAO,EAAiB,KAAK,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAiHpE;;;;GAIG;AACH,wBAAsB,gBAAgB,CAAC,CAAC,SAAS,iBAAiB,GAAG;IAAE,OAAO,CAAC,EAAE,MAAM,EAAE,CAAA;CAAE,EAAE,MAAM,EAAE,cAAc,EAAE,CAAC,EAAE,CAAC,EAAE,aAAa,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,CAAC,CAmC5J"}
@@ -5,7 +5,7 @@
5
5
  * the statements are Postgres's own DDL, parsed at build time into entities,
6
6
  * and the names fold and quote as Postgres folds and quotes them.
7
7
  */
8
- export { schema, table, index, view, sequence, type, domain, extension, func, procedure, trigger, literal, SqlLiteral, SqlTemplateError, PostgresObject, POSTGRES_ENTITY_TYPES, isPostgresObject, isColumnRef, quoteIdent, type PostgresEntityType, type PostgresSchema, type PostgresRelation, type PostgresTable, type PostgresView, type PostgresIndex, type PostgresSequence, type PostgresEnum, type PostgresDomain, type PostgresExtension, type PostgresFunction, type PostgresProcedure, type PostgresTrigger, type ColumnDef, type KeyDef, type CheckDef, type ForeignKeyDef, type ExclusionDef, type SchemaProps, type TableProps, type IndexProps, type ViewProps, type SequenceProps, type EnumProps, type DomainProps, type ExtensionProps, type RoutineProps, type RoutineArgDef, type FunctionProps, type ProcedureProps, type TriggerProps, type LineageEdge, } from "./postgres/entities.js";
8
+ export { schema, table, index, view, sequence, type, domain, extension, func, procedure, trigger, policy, role, grant, literal, SqlLiteral, SqlTemplateError, PostgresObject, POSTGRES_ENTITY_TYPES, isPostgresObject, isColumnRef, quoteIdent, type PostgresEntityType, type PostgresSchema, type PostgresRelation, type PostgresTable, type PostgresView, type PostgresIndex, type PostgresSequence, type PostgresEnum, type PostgresDomain, type PostgresExtension, type PostgresFunction, type PostgresProcedure, type PostgresTrigger, type PostgresPolicy, type PostgresRole, type PostgresGrant, type ColumnDef, type KeyDef, type CheckDef, type ForeignKeyDef, type ExclusionDef, type SchemaProps, type TableProps, type IndexProps, type ViewProps, type SequenceProps, type EnumProps, type DomainProps, type ExtensionProps, type RoutineProps, type RoutineArgDef, type FunctionProps, type ProcedureProps, type TriggerProps, type PolicyProps, type RoleProps, type GrantProps, type DefaultPrivilegesProps, type PrivilegeDef, type LineageEdge, } from "./postgres/entities.js";
9
9
  export { POSTGRES_PROVIDERS, COMMON_REFUSED, providerData, isPostgresProvider, providerAllowsExtension, isProviderOwned, refusedStatement, normalizeStatement, type PostgresProvider, type ProviderData, type ProviderSource, type RefusedStatement, type LiveObjectRef, } from "./postgres/providers/index.js";
10
10
  export { PostgresMigrationOp, type PostgresMigrationOpConfig, type PostgresMigrationOpResources, type PostgresMigrationArgs, } from "./postgres/migrate/op.js";
11
11
  export { POSTGRES_RECEIPTS_TABLE } from "./postgres/migrate/receipts.js";
@@ -1 +1 @@
1
- {"version":3,"file":"postgres.d.ts","sourceRoot":"","sources":["../src/postgres.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EACL,MAAM,EACN,KAAK,EACL,KAAK,EACL,IAAI,EACJ,QAAQ,EACR,IAAI,EACJ,MAAM,EACN,SAAS,EACT,IAAI,EACJ,SAAS,EACT,OAAO,EACP,OAAO,EACP,UAAU,EACV,gBAAgB,EAChB,cAAc,EACd,qBAAqB,EACrB,gBAAgB,EAChB,WAAW,EACX,UAAU,EACV,KAAK,kBAAkB,EACvB,KAAK,cAAc,EACnB,KAAK,gBAAgB,EACrB,KAAK,aAAa,EAClB,KAAK,YAAY,EACjB,KAAK,aAAa,EAClB,KAAK,gBAAgB,EACrB,KAAK,YAAY,EACjB,KAAK,cAAc,EACnB,KAAK,iBAAiB,EACtB,KAAK,gBAAgB,EACrB,KAAK,iBAAiB,EACtB,KAAK,eAAe,EACpB,KAAK,SAAS,EACd,KAAK,MAAM,EACX,KAAK,QAAQ,EACb,KAAK,aAAa,EAClB,KAAK,YAAY,EACjB,KAAK,WAAW,EAChB,KAAK,UAAU,EACf,KAAK,UAAU,EACf,KAAK,SAAS,EACd,KAAK,aAAa,EAClB,KAAK,SAAS,EACd,KAAK,WAAW,EAChB,KAAK,cAAc,EACnB,KAAK,YAAY,EACjB,KAAK,aAAa,EAClB,KAAK,aAAa,EAClB,KAAK,cAAc,EACnB,KAAK,YAAY,EACjB,KAAK,WAAW,GACjB,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EACL,kBAAkB,EAClB,cAAc,EACd,YAAY,EACZ,kBAAkB,EAClB,uBAAuB,EACvB,eAAe,EACf,gBAAgB,EAChB,kBAAkB,EAClB,KAAK,gBAAgB,EACrB,KAAK,YAAY,EACjB,KAAK,cAAc,EACnB,KAAK,gBAAgB,EACrB,KAAK,aAAa,GACnB,MAAM,sBAAsB,CAAC;AAE9B,OAAO,EACL,mBAAmB,EACnB,KAAK,yBAAyB,EAC9B,KAAK,4BAA4B,EACjC,KAAK,qBAAqB,GAC3B,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,uBAAuB,EAAE,MAAM,6BAA6B,CAAC;AACtE,cAAc,uBAAuB,CAAC"}
1
+ {"version":3,"file":"postgres.d.ts","sourceRoot":"","sources":["../src/postgres.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EACL,MAAM,EACN,KAAK,EACL,KAAK,EACL,IAAI,EACJ,QAAQ,EACR,IAAI,EACJ,MAAM,EACN,SAAS,EACT,IAAI,EACJ,SAAS,EACT,OAAO,EACP,MAAM,EACN,IAAI,EACJ,KAAK,EACL,OAAO,EACP,UAAU,EACV,gBAAgB,EAChB,cAAc,EACd,qBAAqB,EACrB,gBAAgB,EAChB,WAAW,EACX,UAAU,EACV,KAAK,kBAAkB,EACvB,KAAK,cAAc,EACnB,KAAK,gBAAgB,EACrB,KAAK,aAAa,EAClB,KAAK,YAAY,EACjB,KAAK,aAAa,EAClB,KAAK,gBAAgB,EACrB,KAAK,YAAY,EACjB,KAAK,cAAc,EACnB,KAAK,iBAAiB,EACtB,KAAK,gBAAgB,EACrB,KAAK,iBAAiB,EACtB,KAAK,eAAe,EACpB,KAAK,cAAc,EACnB,KAAK,YAAY,EACjB,KAAK,aAAa,EAClB,KAAK,SAAS,EACd,KAAK,MAAM,EACX,KAAK,QAAQ,EACb,KAAK,aAAa,EAClB,KAAK,YAAY,EACjB,KAAK,WAAW,EAChB,KAAK,UAAU,EACf,KAAK,UAAU,EACf,KAAK,SAAS,EACd,KAAK,aAAa,EAClB,KAAK,SAAS,EACd,KAAK,WAAW,EAChB,KAAK,cAAc,EACnB,KAAK,YAAY,EACjB,KAAK,aAAa,EAClB,KAAK,aAAa,EAClB,KAAK,cAAc,EACnB,KAAK,YAAY,EACjB,KAAK,WAAW,EAChB,KAAK,SAAS,EACd,KAAK,UAAU,EACf,KAAK,sBAAsB,EAC3B,KAAK,YAAY,EACjB,KAAK,WAAW,GACjB,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EACL,kBAAkB,EAClB,cAAc,EACd,YAAY,EACZ,kBAAkB,EAClB,uBAAuB,EACvB,eAAe,EACf,gBAAgB,EAChB,kBAAkB,EAClB,KAAK,gBAAgB,EACrB,KAAK,YAAY,EACjB,KAAK,cAAc,EACnB,KAAK,gBAAgB,EACrB,KAAK,aAAa,GACnB,MAAM,sBAAsB,CAAC;AAE9B,OAAO,EACL,mBAAmB,EACnB,KAAK,yBAAyB,EAC9B,KAAK,4BAA4B,EACjC,KAAK,qBAAqB,GAC3B,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,uBAAuB,EAAE,MAAM,6BAA6B,CAAC;AACtE,cAAc,uBAAuB,CAAC"}
@@ -17,12 +17,12 @@ export const POSTGRES_TEMPLATE_SOURCES: readonly TemplateSource<PostgresTag>[] =
17
17
  {
18
18
  dialect: "postgres",
19
19
  modules: ["@intentius/chant-lexicon-sql/postgres"],
20
- tags: ["schema", "table", "index", "view", "sequence", "type", "domain", "extension", "func", "procedure", "trigger"],
20
+ tags: ["schema", "table", "index", "view", "sequence", "type", "domain", "extension", "func", "procedure", "trigger", "policy", "role", "grant"],
21
21
  },
22
22
  {
23
23
  dialect: "postgres",
24
24
  modules: ["@intentius/chant-lexicon-sql"],
25
- tags: ["schema", "index", "sequence", "type", "domain", "extension", "func", "procedure", "trigger"],
25
+ tags: ["schema", "index", "sequence", "type", "domain", "extension", "func", "procedure", "trigger", "policy", "role", "grant"],
26
26
  },
27
27
  ];
28
28
 
@@ -1,6 +1,6 @@
1
1
  import type { LintContext, LintDiagnostic, LintRule } from "@intentius/chant/lint/rule";
2
2
  import { parseStatements, SqlSyntaxError } from "../../postgres/parser";
3
- import { STATEMENT_NAMES, type PostgresTag } from "../../postgres/entities";
3
+ import { followOnStray, STATEMENT_NAMES, type PostgresTag } from "../../postgres/entities";
4
4
  import { findPostgresTemplates, postgresTokensOf, templatePosition, tokenPosition } from "./postgres-templates";
5
5
 
6
6
  /** The statement each tag holds. */
@@ -16,6 +16,9 @@ const STATEMENT: Record<PostgresTag, string> = {
16
16
  func: "function",
17
17
  procedure: "procedure",
18
18
  trigger: "trigger",
19
+ policy: "policy",
20
+ role: "role",
21
+ grant: "grant",
19
22
  };
20
23
 
21
24
  const TAG_OF: Record<string, PostgresTag> = Object.fromEntries(Object.entries(STATEMENT).map(([tag, statement]) => [statement, tag as PostgresTag]));
@@ -62,15 +65,15 @@ export const sqlpg001: LintRule = {
62
65
  report(
63
66
  use
64
67
  ? `${found.tag}\`...\` holds a ${STATEMENT_NAMES[node!.statement]}; use the ${use} tag`
65
- : `${found.tag}\`...\` starts with a COMMENT ON; it goes after the CREATE it comments on`,
68
+ : `${found.tag}\`...\` starts with a ${STATEMENT_NAMES[node!.statement]}; it goes after the CREATE it belongs to`,
66
69
  templatePosition(source, found, 0, 0),
67
70
  );
68
71
  continue;
69
72
  }
70
- const stray = rest.find((n) => n.statement !== "comment");
73
+ const stray = followOnStray(found.tag, rest);
71
74
  if (stray) {
72
75
  report(
73
- `${found.tag}\`...\` holds a second statement (${STATEMENT_NAMES[stray.statement]}); a template declares one object, followed only by COMMENT ON statements for it`,
76
+ `${found.tag}\`...\` holds a second statement (${STATEMENT_NAMES[stray.statement]}); a template declares one object, followed only by COMMENT ON statements for it${found.tag === "table" ? " and ALTER TABLE ... ROW LEVEL SECURITY" : ""}`,
74
77
  templatePosition(source, found, 0, 0),
75
78
  );
76
79
  }
@@ -1 +1 @@
1
- {"version":3,"file":"validate.d.ts","sourceRoot":"","sources":["../src/validate.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAKH,OAAO,EAAgD,KAAK,cAAc,EAAE,MAAM,mCAAmC,CAAC;AAMtH,YAAY,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,mCAAmC,CAAC;AAgEvF,wBAAsB,QAAQ,CAAC,IAAI,CAAC,EAAE;IAAE,QAAQ,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,OAAO,CAAC,cAAc,CAAC,CAoEpF"}
1
+ {"version":3,"file":"validate.d.ts","sourceRoot":"","sources":["../src/validate.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAKH,OAAO,EAAgD,KAAK,cAAc,EAAE,MAAM,mCAAmC,CAAC;AAMtH,YAAY,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,mCAAmC,CAAC;AAoEvF,wBAAsB,QAAQ,CAAC,IAAI,CAAC,EAAE;IAAE,QAAQ,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,OAAO,CAAC,cAAc,CAAC,CAoEpF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@intentius/chant-lexicon-sql",
3
- "version": "0.116.0",
3
+ "version": "0.117.0",
4
4
  "description": "SQL lexicon for chant — database schema as typed declarations, one dialect at a time; ClickHouse first, with types read from a pinned server's catalog",
5
5
  "license": "Apache-2.0",
6
6
  "homepage": "https://intentius.io/chant",
@@ -70,7 +70,7 @@
70
70
  "typescript": "^5.9.3"
71
71
  },
72
72
  "peerDependencies": {
73
- "@intentius/chant": "^0.116.0",
73
+ "@intentius/chant": "^0.117.0",
74
74
  "typescript": "^5.9.3"
75
75
  }
76
76
  }
@@ -29,6 +29,10 @@ const KINDS: Record<string, string> = {
29
29
  PostgresFunction: POSTGRES_ENTITY_TYPES.function,
30
30
  PostgresProcedure: POSTGRES_ENTITY_TYPES.procedure,
31
31
  PostgresTrigger: POSTGRES_ENTITY_TYPES.trigger,
32
+ PostgresPolicy: POSTGRES_ENTITY_TYPES.policy,
33
+ PostgresRole: POSTGRES_ENTITY_TYPES.role,
34
+ PostgresGrant: POSTGRES_ENTITY_TYPES.grant,
35
+ PostgresDefaultPrivileges: POSTGRES_ENTITY_TYPES.defaultPrivileges,
32
36
  };
33
37
 
34
38
  export function buildRegistry(): string {
package/src/config.ts CHANGED
@@ -146,6 +146,16 @@ export const sqlProfileSchema = z.strictObject({
146
146
  * `CONCURRENTLY` index build), in milliseconds. 0, no limit, when omitted.
147
147
  */
148
148
  scanTimeoutMs: z.number().int().nonnegative().optional(),
149
+ /**
150
+ * Postgres: whether chant manages access in this environment (#3681): the
151
+ * declared row-level security policies and each table's row-level security,
152
+ * the declared roles (created when missing, never dropped), and the
153
+ * privileges on the declared objects and the default privileges, which a
154
+ * plan compares and an apply grants and revokes. Off when omitted: the
155
+ * access declarations are not planned or applied, and the server's access
156
+ * is not read, so a project that manages access elsewhere is not affected.
157
+ */
158
+ access: z.boolean().optional(),
149
159
  });
150
160
 
151
161
  const dialectName = z.enum(SQL_DIALECTS);
@@ -78,5 +78,25 @@
78
78
  "resourceType": "Postgres::Trigger",
79
79
  "kind": "resource",
80
80
  "lexicon": "sql"
81
+ },
82
+ "PostgresPolicy": {
83
+ "resourceType": "Postgres::Policy",
84
+ "kind": "resource",
85
+ "lexicon": "sql"
86
+ },
87
+ "PostgresRole": {
88
+ "resourceType": "Postgres::Role",
89
+ "kind": "resource",
90
+ "lexicon": "sql"
91
+ },
92
+ "PostgresGrant": {
93
+ "resourceType": "Postgres::Grant",
94
+ "kind": "resource",
95
+ "lexicon": "sql"
96
+ },
97
+ "PostgresDefaultPrivileges": {
98
+ "resourceType": "Postgres::DefaultPrivileges",
99
+ "kind": "resource",
100
+ "lexicon": "sql"
81
101
  }
82
102
  }
package/src/index.ts CHANGED
@@ -18,7 +18,7 @@ export { database, table, view, literal } from "./clickhouse/entities";
18
18
  // A tag folds as the function its file imports, so `table` imported from
19
19
  // `@intentius/chant-lexicon-sql/postgres` is Postgres's. Declarations import
20
20
  // them from the dialect subpath.
21
- export { schema, index, sequence, type, domain, extension, func, procedure, trigger } from "./postgres/entities";
21
+ export { schema, index, sequence, type, domain, extension, func, procedure, trigger, policy, role, grant } from "./postgres/entities";
22
22
 
23
23
  // A schema change's statements between two builds, rendered offline for a
24
24
  // migration file (#3644); also at `@intentius/chant-lexicon-sql/migration-statements`.
@@ -17,12 +17,12 @@ export const POSTGRES_TEMPLATE_SOURCES: readonly TemplateSource<PostgresTag>[] =
17
17
  {
18
18
  dialect: "postgres",
19
19
  modules: ["@intentius/chant-lexicon-sql/postgres"],
20
- tags: ["schema", "table", "index", "view", "sequence", "type", "domain", "extension", "func", "procedure", "trigger"],
20
+ tags: ["schema", "table", "index", "view", "sequence", "type", "domain", "extension", "func", "procedure", "trigger", "policy", "role", "grant"],
21
21
  },
22
22
  {
23
23
  dialect: "postgres",
24
24
  modules: ["@intentius/chant-lexicon-sql"],
25
- tags: ["schema", "index", "sequence", "type", "domain", "extension", "func", "procedure", "trigger"],
25
+ tags: ["schema", "index", "sequence", "type", "domain", "extension", "func", "procedure", "trigger", "policy", "role", "grant"],
26
26
  },
27
27
  ];
28
28
 
@@ -1,6 +1,6 @@
1
1
  import type { LintContext, LintDiagnostic, LintRule } from "@intentius/chant/lint/rule";
2
2
  import { parseStatements, SqlSyntaxError } from "../../postgres/parser";
3
- import { STATEMENT_NAMES, type PostgresTag } from "../../postgres/entities";
3
+ import { followOnStray, STATEMENT_NAMES, type PostgresTag } from "../../postgres/entities";
4
4
  import { findPostgresTemplates, postgresTokensOf, templatePosition, tokenPosition } from "./postgres-templates";
5
5
 
6
6
  /** The statement each tag holds. */
@@ -16,6 +16,9 @@ const STATEMENT: Record<PostgresTag, string> = {
16
16
  func: "function",
17
17
  procedure: "procedure",
18
18
  trigger: "trigger",
19
+ policy: "policy",
20
+ role: "role",
21
+ grant: "grant",
19
22
  };
20
23
 
21
24
  const TAG_OF: Record<string, PostgresTag> = Object.fromEntries(Object.entries(STATEMENT).map(([tag, statement]) => [statement, tag as PostgresTag]));
@@ -62,15 +65,15 @@ export const sqlpg001: LintRule = {
62
65
  report(
63
66
  use
64
67
  ? `${found.tag}\`...\` holds a ${STATEMENT_NAMES[node!.statement]}; use the ${use} tag`
65
- : `${found.tag}\`...\` starts with a COMMENT ON; it goes after the CREATE it comments on`,
68
+ : `${found.tag}\`...\` starts with a ${STATEMENT_NAMES[node!.statement]}; it goes after the CREATE it belongs to`,
66
69
  templatePosition(source, found, 0, 0),
67
70
  );
68
71
  continue;
69
72
  }
70
- const stray = rest.find((n) => n.statement !== "comment");
73
+ const stray = followOnStray(found.tag, rest);
71
74
  if (stray) {
72
75
  report(
73
- `${found.tag}\`...\` holds a second statement (${STATEMENT_NAMES[stray.statement]}); a template declares one object, followed only by COMMENT ON statements for it`,
76
+ `${found.tag}\`...\` holds a second statement (${STATEMENT_NAMES[stray.statement]}); a template declares one object, followed only by COMMENT ON statements for it${found.tag === "table" ? " and ALTER TABLE ... ROW LEVEL SECURITY" : ""}`,
74
77
  templatePosition(source, found, 0, 0),
75
78
  );
76
79
  }
@@ -152,6 +152,8 @@ export function postgresDeclarations(content: string, fileName = "file.ts"): Pos
152
152
  case "function":
153
153
  case "procedure":
154
154
  case "trigger":
155
+ case "policy":
156
+ case "role":
155
157
  sqlName = text(node.name.span);
156
158
  kind = node.statement;
157
159
  break;
@@ -81,7 +81,7 @@ export function postgresSearch(params: Record<string, unknown>): unknown {
81
81
  };
82
82
  }
83
83
 
84
- const TAGS = { schema: pg.schema, table: pg.table, index: pg.index, view: pg.view, sequence: pg.sequence, type: pg.type, domain: pg.domain, extension: pg.extension, func: pg.func, procedure: pg.procedure, trigger: pg.trigger } as const;
84
+ const TAGS = { schema: pg.schema, table: pg.table, index: pg.index, view: pg.view, sequence: pg.sequence, type: pg.type, domain: pg.domain, extension: pg.extension, func: pg.func, procedure: pg.procedure, trigger: pg.trigger, policy: pg.policy, role: pg.role, grant: pg.grant } as const;
85
85
  export const POSTGRES_TAGS = Object.keys(TAGS);
86
86
 
87
87
  /** Parse one statement with the Postgres tag; an error comes back as SQLPG001 with its line and column. */
@@ -237,6 +237,13 @@ function postgresStatements(beforeJson: string, afterJson: string, options: Diff
237
237
  });
238
238
  }
239
239
  }
240
+ // Privileges (#3681), after the objects they are on: one statement each, under the declaration behind it.
241
+ const afterByExport = new Map(after.map((o) => [o.exportName, o]));
242
+ for (const c of diff.access ?? []) {
243
+ const decl = c.exports.map((e) => afterByExport.get(e)).find((o) => o !== undefined);
244
+ const where = decl ? at(decl.exportName, decl.type, decl.name) : at(c.change.object, c.target.kind === "default" ? POSTGRES_ENTITY_TYPES.defaultPrivileges : POSTGRES_ENTITY_TYPES.grant, c.change.object.slice(4));
245
+ for (const sql of c.sql) steps.push({ kind: "statement", ...where, sql, rule: c.change.rule, class: c.change.class, transactional: true });
246
+ }
240
247
  const beforeByExport = new Map(before.map((o) => [o.exportName, o]));
241
248
  for (const d of plan.drops) {
242
249
  const o = beforeByExport.get(d.key);
@@ -17,8 +17,8 @@ import { resolveBoundTarget } from "../../postgres/live/bind";
17
17
  import { connectPostgres, type PostgresClient, type PostgresEndpoint } from "../../postgres/live/client";
18
18
  import { DEFAULT_POSTGRES_APPLY_TIMEOUTS, declaredObjects } from "../../postgres/apply/apply";
19
19
  import { PG_CLASSIFIER_RULES } from "../../postgres/plan/rules";
20
- import { declaredTable, migrationPlanDigest, observeMigration } from "../../postgres/migrate/observe";
21
- import { backfill, verifyMigration, type BackfillDeps, type BackfillResult, type VerifyResult } from "../../postgres/migrate/backfill";
20
+ import { declaredTable, migrationPlanDigest, MigrationRefusal, observeMigration } from "../../postgres/migrate/observe";
21
+ import { backfill, MigrationVerificationError, verifyMigration, type BackfillDeps, type BackfillResult, type VerifyResult } from "../../postgres/migrate/backfill";
22
22
  import {
23
23
  carryOver,
24
24
  compensate,
@@ -60,8 +60,33 @@ async function loadConfig(cwd: string): Promise<Pick<ChantConfig, "sql" | "owner
60
60
  }
61
61
  }
62
62
 
63
+ /**
64
+ * With `onFailure: "keep"` (#3687) no onFailure drops what the expand added,
65
+ * so a step that fails says what a person does instead: a refusal or a
66
+ * failed verification would otherwise fail every run after it the same way.
67
+ */
68
+ const ON_FAILURE_DROPS = "onFailure drops what the expand added, and the next run starts again.";
69
+
70
+ function noting(args: PostgresMigrationArgs, err: unknown): unknown {
71
+ if (args.keepOnFailure && (err instanceof MigrationRefusal || err instanceof MigrationVerificationError)) {
72
+ const kept =
73
+ `This migration keeps what the expand added on failure (onFailure: "keep"), so nothing drops it: ` +
74
+ `to start again from a new column, run the Op once with onFailure: "drop" (the default), whose onFailure drops it when this step fails again.`;
75
+ err.message = err.message.includes(ON_FAILURE_DROPS) ? err.message.replace(ON_FAILURE_DROPS, kept) : `${err.message.replace(/\.?$/, ".")} ${kept}`;
76
+ }
77
+ return err;
78
+ }
79
+
63
80
  /** Bind the server, connect and read the declaration, run `body` with it, then close the connection. */
64
81
  async function withRun<T>(args: PostgresMigrationArgs, signal: AbortSignal | undefined, deps: PostgresMigrationDeps, body: (run: MigrationRun) => Promise<T>): Promise<T> {
82
+ try {
83
+ return await bound(args, signal, deps, body);
84
+ } catch (err) {
85
+ throw noting(args, err);
86
+ }
87
+ }
88
+
89
+ async function bound<T>(args: PostgresMigrationArgs, signal: AbortSignal | undefined, deps: PostgresMigrationDeps, body: (run: MigrationRun) => Promise<T>): Promise<T> {
65
90
  const cwd = args.cwd ?? process.cwd();
66
91
  const config = deps.config ?? (await loadConfig(cwd));
67
92
  const marker = resolveOwnershipMarker(args, config, "PostgresMigrationOp");
@@ -127,6 +127,7 @@ const migrationArgs = z.strictObject({
127
127
  stack: z.string().optional(),
128
128
  ownershipEnv: z.string().optional(),
129
129
  cwd: z.string().optional(),
130
+ keepOnFailure: z.boolean().optional(),
130
131
  });
131
132
 
132
133
  const migrationState = z.enum(["migrate", "switched", "done"]);
package/src/plugin.ts CHANGED
@@ -106,6 +106,9 @@ export const sqlPlugin: LexiconPlugin = {
106
106
  { name: "func", isTag: true, description: "A Postgres CREATE FUNCTION, parsed into a function entity with its body kept verbatim" },
107
107
  { name: "procedure", isTag: true, description: "A Postgres CREATE PROCEDURE, parsed into a procedure entity with its body kept verbatim" },
108
108
  { name: "trigger", isTag: true, description: "A Postgres CREATE TRIGGER, parsed into a trigger entity on its table" },
109
+ { name: "policy", isTag: true, description: "A Postgres CREATE POLICY, parsed into a row-level security policy on its table" },
110
+ { name: "role", isTag: true, description: "A Postgres CREATE ROLE without a password or memberships, parsed into a role entity" },
111
+ { name: "grant", isTag: true, description: "A Postgres GRANT, REVOKE or ALTER DEFAULT PRIVILEGES, parsed into the privileges it declares" },
109
112
  {
110
113
  name: "literal",
111
114
  isTag: false,