@dbsp/adapter-pgsql 1.9.0 → 1.10.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.
- package/dist/index.js +16 -3
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -11885,13 +11885,14 @@ function upCreateIndex(change, schemaName) {
|
|
|
11885
11885
|
];
|
|
11886
11886
|
const cols = colParts.join(", ");
|
|
11887
11887
|
const include = idx.include && idx.include.length > 0 ? ` INCLUDE (${idx.include.map((n) => quoteIdent2(n, "alias")).join(", ")})` : "";
|
|
11888
|
+
const nullsNotDistinct = idx.unique && idx.nullsNotDistinct ? " NULLS NOT DISTINCT" : "";
|
|
11888
11889
|
const withParams = idx.with && Object.keys(idx.with).length > 0 ? ` WITH (${Object.entries(idx.with).map(([k, v]) => {
|
|
11889
11890
|
validateIdentifier(k, "alias");
|
|
11890
11891
|
return `${k} = ${v}`;
|
|
11891
11892
|
}).join(", ")})` : "";
|
|
11892
11893
|
if (idx.where) validateSqlExpression(idx.where, "index WHERE predicate");
|
|
11893
11894
|
const where = idx.where ? ` WHERE ${idx.where}` : "";
|
|
11894
|
-
return `CREATE ${unique}INDEX IF NOT EXISTS ${indexName} ON ${qualifyTable(change.table, schemaName)}${method} (${cols})${include}${withParams}${where};`;
|
|
11895
|
+
return `CREATE ${unique}INDEX IF NOT EXISTS ${indexName} ON ${qualifyTable(change.table, schemaName)}${method} (${cols})${include}${nullsNotDistinct}${withParams}${where};`;
|
|
11895
11896
|
}
|
|
11896
11897
|
function upDropIndex(change, schemaName) {
|
|
11897
11898
|
const idx = change.meta?.index;
|
|
@@ -12761,13 +12762,14 @@ function generateCreateIndex(tableName, idx, schemaName, naming) {
|
|
|
12761
12762
|
}
|
|
12762
12763
|
const cols = colParts.join(", ");
|
|
12763
12764
|
const include = idx.include && idx.include.length > 0 ? ` INCLUDE (${idx.include.map((c) => quoteIdentifier(naming.toDatabase(c))).join(", ")})` : "";
|
|
12765
|
+
const nullsNotDistinct = idx.unique && idx.nullsNotDistinct ? " NULLS NOT DISTINCT" : "";
|
|
12764
12766
|
const withParams = idx.with && Object.keys(idx.with).length > 0 ? ` WITH (${Object.entries(idx.with).map(([k, v]) => {
|
|
12765
12767
|
validateIdentifier(k, "alias");
|
|
12766
12768
|
return `${k} = ${v}`;
|
|
12767
12769
|
}).join(", ")})` : "";
|
|
12768
12770
|
if (idx.where) validateSqlExpression(idx.where, "index WHERE predicate");
|
|
12769
12771
|
const where = idx.where ? ` WHERE ${idx.where}` : "";
|
|
12770
|
-
return `CREATE ${unique}INDEX ${indexName} ON ${qualifiedTable}${method} (${cols})${include}${withParams}${where};`;
|
|
12772
|
+
return `CREATE ${unique}INDEX ${indexName} ON ${qualifiedTable}${method} (${cols})${include}${nullsNotDistinct}${withParams}${where};`;
|
|
12771
12773
|
}
|
|
12772
12774
|
function generateCreatePolicy(tableName, policy, schemaName, naming) {
|
|
12773
12775
|
const qualifiedTable = qualifyTable2(tableName, schemaName, naming);
|
|
@@ -12999,6 +13001,11 @@ function compareSchemata(schema, db, options) {
|
|
|
12999
13001
|
const plugin = options?.dbCasing !== void 0 ? getNamingPluginForDbCasing(options.dbCasing) : void 0;
|
|
13000
13002
|
const schemaTables = plugin ? normalizeTableMap(schema.tables, plugin) : new Map(schema.tables);
|
|
13001
13003
|
const dbTables = new Map(db.tables);
|
|
13004
|
+
const externalTables = new Set(
|
|
13005
|
+
[...schema.externalTables ?? []].map(
|
|
13006
|
+
(name) => plugin ? plugin.toDatabase(name) : name
|
|
13007
|
+
)
|
|
13008
|
+
);
|
|
13002
13009
|
const caps = options?.dialectCapabilities;
|
|
13003
13010
|
const sup2 = (flag) => !caps || flag === true;
|
|
13004
13011
|
if (sup2(caps?.supportsDDLEnumTypes)) {
|
|
@@ -13088,7 +13095,7 @@ function compareSchemata(schema, db, options) {
|
|
|
13088
13095
|
}
|
|
13089
13096
|
}
|
|
13090
13097
|
for (const [name] of dbTables) {
|
|
13091
|
-
if (!schemaTables.has(name)) {
|
|
13098
|
+
if (!schemaTables.has(name) && !externalTables.has(name)) {
|
|
13092
13099
|
changes.push({
|
|
13093
13100
|
kind: "drop_table",
|
|
13094
13101
|
table: name,
|
|
@@ -13429,6 +13436,7 @@ function indexKey(idx) {
|
|
|
13429
13436
|
const parts = [
|
|
13430
13437
|
idx.columns.join(","),
|
|
13431
13438
|
idx.unique ? "unique" : "nonunique",
|
|
13439
|
+
idx.unique && idx.nullsNotDistinct ? "nulls-not-distinct" : "",
|
|
13432
13440
|
idx.method ?? "btree",
|
|
13433
13441
|
idx.where ?? "",
|
|
13434
13442
|
(idx.expressions ?? []).join(","),
|
|
@@ -14123,6 +14131,7 @@ async function queryAllCatalogs(pool, schema) {
|
|
|
14123
14131
|
FILTER (WHERE k.n <= ix.indnkeyatts AND k.attnum != 0
|
|
14124
14132
|
AND NOT oc.opcdefault) AS opclass_cols,
|
|
14125
14133
|
ix.indisunique AS is_unique,
|
|
14134
|
+
bool_or(COALESCE((to_jsonb(ix) ->> 'indnullsnotdistinct')::boolean, false)) AS nulls_not_distinct,
|
|
14126
14135
|
am.amname AS method,
|
|
14127
14136
|
pg_get_expr(ix.indpred, ix.indrelid, false) AS predicate,
|
|
14128
14137
|
i.reloptions AS reloptions
|
|
@@ -14317,6 +14326,7 @@ function buildIndexMap(rows) {
|
|
|
14317
14326
|
name: idx.index_name,
|
|
14318
14327
|
columns,
|
|
14319
14328
|
...idx.is_unique ? { unique: true } : {},
|
|
14329
|
+
...idx.is_unique && idx.nulls_not_distinct ? { nullsNotDistinct: true } : {},
|
|
14320
14330
|
// Only store method when it's not the default 'btree'
|
|
14321
14331
|
...idx.method && idx.method !== "btree" ? { method: idx.method } : {},
|
|
14322
14332
|
...idx.predicate ? { where: idx.predicate } : {},
|
|
@@ -18132,6 +18142,9 @@ function generateCreateIndexSQL(table, options, schema) {
|
|
|
18132
18142
|
const includeCols = options.include.map((c) => quoteIdentifier2(c)).join(", ");
|
|
18133
18143
|
parts.push(`INCLUDE (${includeCols})`);
|
|
18134
18144
|
}
|
|
18145
|
+
if (options.unique && options.nullsNotDistinct) {
|
|
18146
|
+
parts.push("NULLS NOT DISTINCT");
|
|
18147
|
+
}
|
|
18135
18148
|
if (options.with && Object.keys(options.with).length > 0) {
|
|
18136
18149
|
const withParams = Object.entries(options.with).map(([k, v]) => {
|
|
18137
18150
|
validateIdentifier(k, "alias");
|