@prisma-next/adapter-postgres 0.14.0-dev.21 → 0.14.0-dev.23
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/{adapter-BvM9axNH.mjs → adapter-C9_442Ul.mjs} +2 -2
- package/dist/{adapter-BvM9axNH.mjs.map → adapter-C9_442Ul.mjs.map} +1 -1
- package/dist/adapter.d.mts +1 -1
- package/dist/adapter.mjs +1 -1
- package/dist/{control-adapter-AffpjrYN.mjs → control-adapter-QeICiKLE.mjs} +22 -20
- package/dist/{control-adapter-AffpjrYN.mjs.map → control-adapter-QeICiKLE.mjs.map} +1 -1
- package/dist/control.d.mts +1 -1
- package/dist/control.d.mts.map +1 -1
- package/dist/control.mjs +1 -1
- package/dist/runtime.d.mts +1 -1
- package/dist/runtime.mjs +1 -1
- package/dist/{types-KXRwRZU8.d.mts → types-DkGeLfUp.d.mts} +3 -6
- package/dist/types-DkGeLfUp.d.mts.map +1 -0
- package/dist/types.d.mts +1 -1
- package/package.json +23 -23
- package/src/core/control-adapter.ts +56 -21
- package/src/core/types.ts +2 -3
- package/dist/types-KXRwRZU8.d.mts.map +0 -1
package/dist/control.d.mts
CHANGED
|
@@ -6,9 +6,9 @@ import { SqlEscapeError, escapeLiteral, qualifyName, quoteIdentifier } from "@pr
|
|
|
6
6
|
import { PostgresSchemaIR } from "@prisma-next/target-postgres/types";
|
|
7
7
|
import { SqlControlAdapterDescriptor } from "@prisma-next/family-sql/control";
|
|
8
8
|
import { PostgresDdlNode } from "@prisma-next/target-postgres/ddl";
|
|
9
|
-
import { Contract, ContractMarkerRecord, LedgerEntryRecord } from "@prisma-next/contract/types";
|
|
10
9
|
import { CodecRegistry } from "@prisma-next/framework-components/codec";
|
|
11
10
|
import { SqlControlDriverInstance, SqlStorage } from "@prisma-next/sql-contract/types";
|
|
11
|
+
import { Contract, ContractMarkerRecord, LedgerEntryRecord } from "@prisma-next/contract/types";
|
|
12
12
|
import { SqlControlAdapter } from "@prisma-next/family-sql/control-adapter";
|
|
13
13
|
import { SqlSchemaIR } from "@prisma-next/sql-schema-ir/types";
|
|
14
14
|
|
package/dist/control.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"control.d.mts","names":[],"sources":["../src/core/codec-lookup.ts","../src/core/control-adapter.ts","../src/exports/control.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;iBAWgB,gCAAA,IAAoC,aAAa;;;;;;;
|
|
1
|
+
{"version":3,"file":"control.d.mts","names":[],"sources":["../src/core/codec-lookup.ts","../src/core/control-adapter.ts","../src/exports/control.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;iBAWgB,gCAAA,IAAoC,aAAa;;;;;;;cCgGpD,sBAAA,YAAkC,iBAAA;EAAA,SACpC,QAAA;EAAA,SACA,QAAA;EAAA,iBAEQ,aAAA;cAEL,aAAA,EAAe,aAAA;;;;AAN7B;WAcW,gBAAA,SAAgB,sBAAA;;;;;;WAOhB,mBAAA,SAAmB,2BAAA;EAE5B,uBAAA,CACE,QAAA,EAAU,QAAA,CAAS,UAAA,GACnB,MAAA,EAAQ,WAAA,YACE,eAAA;EAsBZ,4BAAA,aAAyC,OAAA;EAIzC,0BAAA,aAAuC,OAAA;EAAA;;;;;;;;EAYvC,KAAA,CAAM,GAAA,EAAK,WAAA,GAAc,eAAA,EAAiB,OAAA,EAAS,cAAA,YAA0B,gBAAA;EAyB1E;;;;;;;EAHG,qBAAA,CACJ,GAAA,EAAK,WAAA,GAAc,eAAA,EACnB,OAAA,GAAU,cAAA,YACT,OAAA,CAAQ,iBAAA;EAmDoB;;;;;;;;EAxBzB,UAAA,CACJ,MAAA,EAAQ,wBAAA,cACR,KAAA,WACC,OAAA,CAAQ,oBAAA;EAKL,uBAAA,CACJ,MAAA,EAAQ,wBAAA,cACR,KAAA,WACC,OAAA,CAAQ,gBAAA;EA+MD;;;;;;EApMJ,cAAA,CACJ,MAAA,EAAQ,wBAAA,eACP,OAAA,CAAQ,WAAA,SAAoB,oBAAA;EAAA,QAKjB,oBAAA;EAjJgD;;;;;;EA0MxD,UAAA,CACJ,MAAA,EAAQ,wBAAA,cACR,KAAA,YACC,OAAA,UAAiB,iBAAA;EAAA,QAKN,gBAAA;EA5MF;;;;;EAgQN,YAAA,CACJ,MAAA,EAAQ,wBAAA,cACR,KAAA,UACA,WAAA;IAAA,SACW,WAAA;IAAA,SACA,WAAA;IAAA,SACA,UAAA;EAAA,IAEV,OAAA;EAoBG,UAAA,CACJ,MAAA,EAAQ,wBAAA,cACR,KAAA,UACA,WAAA;IAAA,SACW,WAAA;IAAA,SACA,WAAA;IAAA,SACA,UAAA;EAAA,IAEV,OAAA;EAtPoC;;;;EAyRjC,YAAA,CACJ,MAAA,EAAQ,wBAAA,cACR,KAAA,UACA,YAAA,UACA,WAAA;IAAA,SACW,WAAA;IAAA,SACA,WAAA;IAAA,SACA,UAAA;EAAA,IAEV,OAAA;EA/PI;;;;EA6RD,gBAAA,CACJ,MAAA,EAAQ,wBAAA,cACR,KAAA,UACA,KAAA;IAAA,SACW,MAAA;IAAA,SACA,IAAA;IAAA,SACA,EAAA;IAAA,SACA,aAAA;IAAA,SACA,aAAA;IAAA,SACA,UAAA;EAAA,IAEV,OAAA;EAAA,QAiBW,+BAAA;EAAA,QA0BA,gBAAA;EA7SJ;;;;;;;;;;;;;;;;;;;;;;;;EAuWJ,UAAA,CACJ,MAAA,EAAQ,wBAAA,cACR,QAAA,YACA,MAAA,YACC,OAAA,CAAQ,gBAAA;EA5NE;;;;;;;;EAAA,QAqPC,mBAAA;EAzND;;;;;;;EAAA,QA8OC,oBAAA;EApMD;;;;;EAAA,QAsPC,gBAAA;EAnNJ;;;EAAA,QA0uBI,kBAAA;AAAA;;;cC1rCV,yBAAA,EAA2B,2BAA2B"}
|
package/dist/control.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { r as createPostgresBuiltinCodecLookup, t as PostgresControlAdapter } from "./control-adapter-
|
|
1
|
+
import { r as createPostgresBuiltinCodecLookup, t as PostgresControlAdapter } from "./control-adapter-QeICiKLE.mjs";
|
|
2
2
|
import { t as postgresAdapterDescriptorMeta } from "./descriptor-meta-DnWlLrI6.mjs";
|
|
3
3
|
import { parsePostgresDefault } from "@prisma-next/target-postgres/default-normalizer";
|
|
4
4
|
import { normalizeSchemaNativeType } from "@prisma-next/target-postgres/native-type-normalizer";
|
package/dist/runtime.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { c as PostgresContract, l as PostgresLoweredStatement } from "./types-
|
|
1
|
+
import { c as PostgresContract, l as PostgresLoweredStatement } from "./types-DkGeLfUp.mjs";
|
|
2
2
|
import { Adapter, AnyQueryAst } from "@prisma-next/sql-relational-core/ast";
|
|
3
3
|
import { SqlRuntimeAdapterDescriptor } from "@prisma-next/sql-runtime";
|
|
4
4
|
import { RuntimeAdapterInstance } from "@prisma-next/framework-components/execution";
|
package/dist/runtime.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as postgresRawCodecInferer, t as createPostgresAdapter } from "./adapter-
|
|
1
|
+
import { n as postgresRawCodecInferer, t as createPostgresAdapter } from "./adapter-C9_442Ul.mjs";
|
|
2
2
|
import { n as postgresQueryOperations, t as postgresAdapterDescriptorMeta } from "./descriptor-meta-DnWlLrI6.mjs";
|
|
3
3
|
import { extractCodecLookup } from "@prisma-next/framework-components/control";
|
|
4
4
|
import { postgresCodecRegistry } from "@prisma-next/target-postgres/codecs";
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { BinaryExpr, ColumnRef, DefaultValueExpr, Direction, LoweredStatement, ParamRef, SelectAst } from "@prisma-next/sql-relational-core/ast";
|
|
2
|
-
import {
|
|
2
|
+
import { PostgresContract } from "@prisma-next/target-postgres/types";
|
|
3
3
|
import { CodecRegistry } from "@prisma-next/framework-components/codec";
|
|
4
|
-
import {
|
|
4
|
+
import { StorageColumn, StorageTable } from "@prisma-next/sql-contract/types";
|
|
5
5
|
|
|
6
6
|
//#region src/core/types.d.ts
|
|
7
7
|
interface PostgresAdapterOptions {
|
|
@@ -17,9 +17,6 @@ interface PostgresAdapterOptions {
|
|
|
17
17
|
*/
|
|
18
18
|
readonly codecLookup?: CodecRegistry;
|
|
19
19
|
}
|
|
20
|
-
type PostgresContract = Contract<SqlStorage> & {
|
|
21
|
-
readonly target: 'postgres';
|
|
22
|
-
};
|
|
23
20
|
type Expr = ColumnRef | ParamRef | DefaultValueExpr;
|
|
24
21
|
interface OrderClause {
|
|
25
22
|
readonly expr: ColumnRef;
|
|
@@ -28,4 +25,4 @@ interface OrderClause {
|
|
|
28
25
|
type PostgresLoweredStatement = LoweredStatement;
|
|
29
26
|
//#endregion
|
|
30
27
|
export { OrderClause as a, PostgresContract as c, StorageColumn as d, StorageTable as f, Expr as i, PostgresLoweredStatement as l, ColumnRef as n, ParamRef as o, Direction as r, PostgresAdapterOptions as s, BinaryExpr as t, SelectAst as u };
|
|
31
|
-
//# sourceMappingURL=types-
|
|
28
|
+
//# sourceMappingURL=types-DkGeLfUp.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types-DkGeLfUp.d.mts","names":[],"sources":["../src/core/types.ts"],"mappings":";;;;;;UAmBiB,sBAAA;EAAA,SACN,SAAA;;AADX;;;;;;;;WAWW,WAAA,GAAc,aAAa;AAAA;AAAA,KAK1B,IAAA,GAAO,SAAA,GAAY,QAAA,GAAW,gBAAA;AAAA,UAEzB,WAAA;EAAA,SACN,IAAA,EAAM,SAAA;EAAA,SACN,GAAA,EAAK,SAAS;AAAA;AAAA,KAGb,wBAAA,GAA2B,gBAAgB"}
|
package/dist/types.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as OrderClause, c as PostgresContract, d as StorageColumn, f as StorageTable, i as Expr, l as PostgresLoweredStatement, n as ColumnRef, o as ParamRef, r as Direction, s as PostgresAdapterOptions, t as BinaryExpr, u as SelectAst } from "./types-
|
|
1
|
+
import { a as OrderClause, c as PostgresContract, d as StorageColumn, f as StorageTable, i as Expr, l as PostgresLoweredStatement, n as ColumnRef, o as ParamRef, r as Direction, s as PostgresAdapterOptions, t as BinaryExpr, u as SelectAst } from "./types-DkGeLfUp.mjs";
|
|
2
2
|
export type { BinaryExpr, ColumnRef, Direction, Expr, OrderClause, ParamRef, PostgresAdapterOptions, PostgresContract, PostgresLoweredStatement, SelectAst, StorageColumn, StorageTable };
|
package/package.json
CHANGED
|
@@ -1,35 +1,35 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prisma-next/adapter-postgres",
|
|
3
|
-
"version": "0.14.0-dev.
|
|
3
|
+
"version": "0.14.0-dev.23",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
7
7
|
"dependencies": {
|
|
8
|
-
"@prisma-next/contract": "0.14.0-dev.
|
|
9
|
-
"@prisma-next/contract-authoring": "0.14.0-dev.
|
|
10
|
-
"@prisma-next/errors": "0.14.0-dev.
|
|
11
|
-
"@prisma-next/family-sql": "0.14.0-dev.
|
|
12
|
-
"@prisma-next/framework-components": "0.14.0-dev.
|
|
13
|
-
"@prisma-next/ids": "0.14.0-dev.
|
|
14
|
-
"@prisma-next/sql-contract": "0.14.0-dev.
|
|
15
|
-
"@prisma-next/sql-contract-psl": "0.14.0-dev.
|
|
16
|
-
"@prisma-next/sql-contract-ts": "0.14.0-dev.
|
|
17
|
-
"@prisma-next/sql-operations": "0.14.0-dev.
|
|
18
|
-
"@prisma-next/sql-relational-core": "0.14.0-dev.
|
|
19
|
-
"@prisma-next/sql-runtime": "0.14.0-dev.
|
|
20
|
-
"@prisma-next/sql-schema-ir": "0.14.0-dev.
|
|
21
|
-
"@prisma-next/target-postgres": "0.14.0-dev.
|
|
22
|
-
"@prisma-next/utils": "0.14.0-dev.
|
|
8
|
+
"@prisma-next/contract": "0.14.0-dev.23",
|
|
9
|
+
"@prisma-next/contract-authoring": "0.14.0-dev.23",
|
|
10
|
+
"@prisma-next/errors": "0.14.0-dev.23",
|
|
11
|
+
"@prisma-next/family-sql": "0.14.0-dev.23",
|
|
12
|
+
"@prisma-next/framework-components": "0.14.0-dev.23",
|
|
13
|
+
"@prisma-next/ids": "0.14.0-dev.23",
|
|
14
|
+
"@prisma-next/sql-contract": "0.14.0-dev.23",
|
|
15
|
+
"@prisma-next/sql-contract-psl": "0.14.0-dev.23",
|
|
16
|
+
"@prisma-next/sql-contract-ts": "0.14.0-dev.23",
|
|
17
|
+
"@prisma-next/sql-operations": "0.14.0-dev.23",
|
|
18
|
+
"@prisma-next/sql-relational-core": "0.14.0-dev.23",
|
|
19
|
+
"@prisma-next/sql-runtime": "0.14.0-dev.23",
|
|
20
|
+
"@prisma-next/sql-schema-ir": "0.14.0-dev.23",
|
|
21
|
+
"@prisma-next/target-postgres": "0.14.0-dev.23",
|
|
22
|
+
"@prisma-next/utils": "0.14.0-dev.23",
|
|
23
23
|
"arktype": "^2.2.0"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
|
-
"@prisma-next/cli": "0.14.0-dev.
|
|
27
|
-
"@prisma-next/driver-postgres": "0.14.0-dev.
|
|
28
|
-
"@prisma-next/migration-tools": "0.14.0-dev.
|
|
29
|
-
"@prisma-next/psl-parser": "0.14.0-dev.
|
|
30
|
-
"@prisma-next/test-utils": "0.14.0-dev.
|
|
31
|
-
"@prisma-next/tsconfig": "0.14.0-dev.
|
|
32
|
-
"@prisma-next/tsdown": "0.14.0-dev.
|
|
26
|
+
"@prisma-next/cli": "0.14.0-dev.23",
|
|
27
|
+
"@prisma-next/driver-postgres": "0.14.0-dev.23",
|
|
28
|
+
"@prisma-next/migration-tools": "0.14.0-dev.23",
|
|
29
|
+
"@prisma-next/psl-parser": "0.14.0-dev.23",
|
|
30
|
+
"@prisma-next/test-utils": "0.14.0-dev.23",
|
|
31
|
+
"@prisma-next/tsconfig": "0.14.0-dev.23",
|
|
32
|
+
"@prisma-next/tsdown": "0.14.0-dev.23",
|
|
33
33
|
"pathe": "^2.0.3",
|
|
34
34
|
"tsdown": "0.22.1",
|
|
35
35
|
"typescript": "5.9.3",
|
|
@@ -39,7 +39,6 @@ import type {
|
|
|
39
39
|
SqlIndexIR,
|
|
40
40
|
SqlReferentialAction,
|
|
41
41
|
SqlSchemaIR,
|
|
42
|
-
SqlTableIR,
|
|
43
42
|
SqlUniqueIR,
|
|
44
43
|
} from '@prisma-next/sql-schema-ir/types';
|
|
45
44
|
import {
|
|
@@ -60,13 +59,19 @@ import type {
|
|
|
60
59
|
} from '@prisma-next/target-postgres/ddl';
|
|
61
60
|
import { parsePostgresDefault } from '@prisma-next/target-postgres/default-normalizer';
|
|
62
61
|
import { normalizeSchemaNativeType } from '@prisma-next/target-postgres/native-type-normalizer';
|
|
63
|
-
import {
|
|
62
|
+
import {
|
|
63
|
+
contractToPostgresSchemaIR,
|
|
64
|
+
diffPostgresSchema,
|
|
65
|
+
filterIssuesByOwnership,
|
|
66
|
+
} from '@prisma-next/target-postgres/planner';
|
|
64
67
|
import { escapeLiteral, quoteIdentifier } from '@prisma-next/target-postgres/sql-utils';
|
|
65
68
|
import {
|
|
69
|
+
ensurePostgresSchemaIR,
|
|
66
70
|
isPostgresSchemaIR,
|
|
67
71
|
PostgresRlsPolicy,
|
|
68
72
|
PostgresRole,
|
|
69
73
|
PostgresSchemaIR,
|
|
74
|
+
PostgresTableIR,
|
|
70
75
|
} from '@prisma-next/target-postgres/types';
|
|
71
76
|
import { blindCast } from '@prisma-next/utils/casts';
|
|
72
77
|
import { ifDefined } from '@prisma-next/utils/defined';
|
|
@@ -129,10 +134,23 @@ export class PostgresControlAdapter implements SqlControlAdapter<'postgres'> {
|
|
|
129
134
|
): readonly SchemaDiffIssue[] {
|
|
130
135
|
if (!isPostgresSchemaIR(schema)) {
|
|
131
136
|
throw new Error(
|
|
132
|
-
`
|
|
137
|
+
`Postgres schema diff requires a PostgresSchemaIR; got ${(schema as { constructor?: { name?: string } }).constructor?.name ?? typeof schema}`,
|
|
133
138
|
);
|
|
134
139
|
}
|
|
135
|
-
|
|
140
|
+
const expected = contractToPostgresSchemaIR(
|
|
141
|
+
blindCast<
|
|
142
|
+
PostgresContract,
|
|
143
|
+
'collectSchemaDiffIssues is only called with a postgres contract'
|
|
144
|
+
>(contract),
|
|
145
|
+
{ annotationNamespace: 'pg' },
|
|
146
|
+
);
|
|
147
|
+
const actual = ensurePostgresSchemaIR(schema);
|
|
148
|
+
const issues = diffPostgresSchema(expected, actual);
|
|
149
|
+
const ownedSchemaNames = new Set([
|
|
150
|
+
...expected.rlsPolicies.map((p) => p.namespaceId),
|
|
151
|
+
...expected.existingSchemas,
|
|
152
|
+
]);
|
|
153
|
+
return filterIssuesByOwnership(issues, ownedSchemaNames);
|
|
136
154
|
}
|
|
137
155
|
|
|
138
156
|
bootstrapControlTableQueries(): readonly DdlNode[] {
|
|
@@ -586,7 +604,6 @@ export class PostgresControlAdapter implements SqlControlAdapter<'postgres'> {
|
|
|
586
604
|
tables: ir.tables,
|
|
587
605
|
pgSchemaName: ir.pgSchemaName,
|
|
588
606
|
pgVersion: ir.pgVersion,
|
|
589
|
-
rlsPolicies: ir.rlsPolicies,
|
|
590
607
|
roles: ir.roles,
|
|
591
608
|
existingSchemas,
|
|
592
609
|
nativeEnumTypeNames: ir.nativeEnumTypeNames,
|
|
@@ -647,17 +664,12 @@ export class PostgresControlAdapter implements SqlControlAdapter<'postgres'> {
|
|
|
647
664
|
perSchema.push(await this.introspectSchema(driver, schema));
|
|
648
665
|
}
|
|
649
666
|
|
|
650
|
-
const mergedTables: Record<string,
|
|
667
|
+
const mergedTables: Record<string, PostgresTableIR> = {};
|
|
668
|
+
const mergedRoles: PostgresRole[] = [];
|
|
651
669
|
for (const ir of perSchema) {
|
|
652
670
|
for (const [tableName, table] of Object.entries(ir.tables)) {
|
|
653
671
|
mergedTables[tableName] = table;
|
|
654
672
|
}
|
|
655
|
-
}
|
|
656
|
-
|
|
657
|
-
const mergedRlsPolicies: PostgresRlsPolicy[] = [];
|
|
658
|
-
const mergedRoles: PostgresRole[] = [];
|
|
659
|
-
for (const ir of perSchema) {
|
|
660
|
-
mergedRlsPolicies.push(...ir.rlsPolicies);
|
|
661
673
|
mergedRoles.push(...ir.roles);
|
|
662
674
|
}
|
|
663
675
|
|
|
@@ -666,7 +678,6 @@ export class PostgresControlAdapter implements SqlControlAdapter<'postgres'> {
|
|
|
666
678
|
tables: mergedTables,
|
|
667
679
|
pgSchemaName: first?.pgSchemaName ?? 'public',
|
|
668
680
|
pgVersion: first?.pgVersion ?? 'unknown',
|
|
669
|
-
rlsPolicies: mergedRlsPolicies,
|
|
670
681
|
roles: mergedRoles,
|
|
671
682
|
existingSchemas: first?.existingSchemas ?? ['public'],
|
|
672
683
|
nativeEnumTypeNames: first?.nativeEnumTypeNames ?? [],
|
|
@@ -923,7 +934,18 @@ export class PostgresControlAdapter implements SqlControlAdapter<'postgres'> {
|
|
|
923
934
|
constraints.add(row.constraint_name);
|
|
924
935
|
}
|
|
925
936
|
|
|
926
|
-
const
|
|
937
|
+
const tableInputs: Record<
|
|
938
|
+
string,
|
|
939
|
+
{
|
|
940
|
+
name: string;
|
|
941
|
+
columns: Record<string, SqlColumnIR>;
|
|
942
|
+
primaryKey?: PrimaryKey;
|
|
943
|
+
foreignKeys: readonly SqlForeignKeyIR[];
|
|
944
|
+
uniques: readonly SqlUniqueIR[];
|
|
945
|
+
indexes: readonly SqlIndexIR[];
|
|
946
|
+
checks?: SqlCheckConstraintIRInput[];
|
|
947
|
+
}
|
|
948
|
+
> = {};
|
|
927
949
|
|
|
928
950
|
for (const tableRow of tablesResult.rows) {
|
|
929
951
|
const tableName = tableRow.table_name;
|
|
@@ -1108,7 +1130,7 @@ export class PostgresControlAdapter implements SqlControlAdapter<'postgres'> {
|
|
|
1108
1130
|
}
|
|
1109
1131
|
}
|
|
1110
1132
|
|
|
1111
|
-
|
|
1133
|
+
tableInputs[tableName] = {
|
|
1112
1134
|
name: tableName,
|
|
1113
1135
|
columns,
|
|
1114
1136
|
...ifDefined('primaryKey', primaryKey),
|
|
@@ -1152,24 +1174,38 @@ export class PostgresControlAdapter implements SqlControlAdapter<'postgres'> {
|
|
|
1152
1174
|
AND rolname != 'postgres'
|
|
1153
1175
|
ORDER BY rolname`,
|
|
1154
1176
|
);
|
|
1155
|
-
const
|
|
1177
|
+
const policiesByTable = new Map<string, PostgresRlsPolicy[]>();
|
|
1178
|
+
for (const row of policiesResult.rows) {
|
|
1156
1179
|
const operation = mapPgCmd(row.cmd);
|
|
1157
|
-
const
|
|
1180
|
+
const policyRoles = [
|
|
1181
|
+
...new Set(parsePgNameArray(row.roles).map((r) => r.toLowerCase())),
|
|
1182
|
+
].sort();
|
|
1158
1183
|
const permissive = row.permissive.toUpperCase() === 'PERMISSIVE';
|
|
1159
1184
|
const hashSuffixMatch = /^(.+)_([0-9a-f]{8})$/.exec(row.policyname);
|
|
1160
1185
|
const prefix = hashSuffixMatch?.[1] ?? row.policyname;
|
|
1161
|
-
|
|
1186
|
+
const policy = new PostgresRlsPolicy({
|
|
1162
1187
|
name: row.policyname,
|
|
1163
1188
|
prefix,
|
|
1164
1189
|
tableName: row.tablename,
|
|
1165
1190
|
namespaceId: row.schemaname,
|
|
1166
1191
|
operation,
|
|
1167
|
-
roles,
|
|
1192
|
+
roles: policyRoles,
|
|
1168
1193
|
...(row.qual !== null ? { using: row.qual } : {}),
|
|
1169
1194
|
...(row.with_check !== null ? { withCheck: row.with_check } : {}),
|
|
1170
1195
|
permissive,
|
|
1171
1196
|
});
|
|
1172
|
-
|
|
1197
|
+
const list = policiesByTable.get(row.tablename) ?? [];
|
|
1198
|
+
list.push(policy);
|
|
1199
|
+
policiesByTable.set(row.tablename, list);
|
|
1200
|
+
}
|
|
1201
|
+
|
|
1202
|
+
const tables: Record<string, PostgresTableIR> = {};
|
|
1203
|
+
for (const [tableName, input] of Object.entries(tableInputs)) {
|
|
1204
|
+
tables[tableName] = new PostgresTableIR({
|
|
1205
|
+
...input,
|
|
1206
|
+
rlsPolicies: policiesByTable.get(tableName) ?? [],
|
|
1207
|
+
});
|
|
1208
|
+
}
|
|
1173
1209
|
|
|
1174
1210
|
const roles: PostgresRole[] = rolesResult.rows.map(
|
|
1175
1211
|
(row) => new PostgresRole({ name: row.rolname, namespaceId: UNBOUND_NAMESPACE_ID }),
|
|
@@ -1179,7 +1215,6 @@ export class PostgresControlAdapter implements SqlControlAdapter<'postgres'> {
|
|
|
1179
1215
|
tables,
|
|
1180
1216
|
pgSchemaName: schema,
|
|
1181
1217
|
pgVersion: await this.getPostgresVersion(driver),
|
|
1182
|
-
rlsPolicies,
|
|
1183
1218
|
roles,
|
|
1184
1219
|
existingSchemas: [],
|
|
1185
1220
|
nativeEnumTypeNames,
|
package/src/core/types.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import type { Contract } from '@prisma-next/contract/types';
|
|
2
1
|
import type { CodecRegistry } from '@prisma-next/framework-components/codec';
|
|
3
|
-
import type {
|
|
2
|
+
import type { StorageColumn, StorageTable } from '@prisma-next/sql-contract/types';
|
|
4
3
|
import type {
|
|
5
4
|
AnyQueryAst,
|
|
6
5
|
BinaryExpr,
|
|
@@ -32,7 +31,7 @@ export interface PostgresAdapterOptions {
|
|
|
32
31
|
readonly codecLookup?: CodecRegistry;
|
|
33
32
|
}
|
|
34
33
|
|
|
35
|
-
export type PostgresContract
|
|
34
|
+
export type { PostgresContract } from '@prisma-next/target-postgres/types';
|
|
36
35
|
|
|
37
36
|
export type Expr = ColumnRef | ParamRef | DefaultValueExpr;
|
|
38
37
|
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types-KXRwRZU8.d.mts","names":[],"sources":["../src/core/types.ts"],"mappings":";;;;;;UAoBiB,sBAAA;EAAA,SACN,SAAA;EADM;;;;;;;;AAWqB;EAXrB,SAWN,WAAA,GAAc,aAAa;AAAA;AAAA,KAG1B,gBAAA,GAAmB,QAAQ,CAAC,UAAA;EAAA,SAAyB,MAAA;AAAA;AAAA,KAErD,IAAA,GAAO,SAAA,GAAY,QAAA,GAAW,gBAAA;AAAA,UAEzB,WAAA;EAAA,SACN,IAAA,EAAM,SAAA;EAAA,SACN,GAAA,EAAK,SAAS;AAAA;AAAA,KAGb,wBAAA,GAA2B,gBAAgB"}
|