pgterra 0.2.13 → 0.2.15
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 +38 -10
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -23683,12 +23683,17 @@ function getQualifiedTableName(table, schema) {
|
|
|
23683
23683
|
function normalizeType(type) {
|
|
23684
23684
|
const typeMap = {
|
|
23685
23685
|
"character varying": "VARCHAR",
|
|
23686
|
+
character: "CHAR",
|
|
23687
|
+
bpchar: "CHAR",
|
|
23686
23688
|
text: "TEXT",
|
|
23687
23689
|
boolean: "BOOLEAN",
|
|
23688
23690
|
bool: "BOOLEAN",
|
|
23689
23691
|
"timestamp without time zone": "TIMESTAMP",
|
|
23690
23692
|
"timestamp with time zone": "TIMESTAMPTZ",
|
|
23691
23693
|
timestamptz: "TIMESTAMPTZ",
|
|
23694
|
+
"time without time zone": "TIME",
|
|
23695
|
+
"time with time zone": "TIMETZ",
|
|
23696
|
+
timetz: "TIMETZ",
|
|
23692
23697
|
int: "INT4",
|
|
23693
23698
|
int2: "INT2",
|
|
23694
23699
|
int4: "INT4",
|
|
@@ -23702,11 +23707,19 @@ function normalizeType(type) {
|
|
|
23702
23707
|
SMALLINT: "INT2",
|
|
23703
23708
|
INTEGER: "INT4",
|
|
23704
23709
|
BIGINT: "INT8",
|
|
23705
|
-
decimal: "NUMERIC"
|
|
23710
|
+
decimal: "NUMERIC",
|
|
23711
|
+
real: "FLOAT4",
|
|
23712
|
+
float4: "FLOAT4",
|
|
23713
|
+
"double precision": "FLOAT8",
|
|
23714
|
+
float8: "FLOAT8"
|
|
23706
23715
|
};
|
|
23707
23716
|
if (type.startsWith("character varying")) {
|
|
23708
23717
|
return type.replace("character varying", "VARCHAR");
|
|
23709
23718
|
}
|
|
23719
|
+
const lowerTypePrefix = type.toLowerCase();
|
|
23720
|
+
if (lowerTypePrefix.startsWith("character(") || lowerTypePrefix.startsWith("bpchar(")) {
|
|
23721
|
+
return type.replace(/^(character|bpchar)/i, "CHAR");
|
|
23722
|
+
}
|
|
23710
23723
|
if (type.toLowerCase().startsWith("numeric(") || type.toLowerCase().startsWith("decimal(")) {
|
|
23711
23724
|
const match = type.match(/^(numeric|decimal)\((\d+),(\d+)\)$/i);
|
|
23712
23725
|
if (match) {
|
|
@@ -23724,11 +23737,25 @@ function normalizeDefault(value) {
|
|
|
23724
23737
|
if (normalized.toUpperCase() === "NULL") {
|
|
23725
23738
|
return;
|
|
23726
23739
|
}
|
|
23727
|
-
normalized = normalized.replace(/::[a-z_]+(\s+[a-z_]+)*(\([^)]*\))?$/i, "");
|
|
23728
|
-
|
|
23740
|
+
normalized = normalized.replace(/::[a-z_]+(\s+[a-z_]+)*(\([^)]*\))?(\[\])?$/i, "");
|
|
23741
|
+
const castMatch = normalized.match(/^CAST\((.+)\s+AS\s+[a-z_]+(\[\])?\)$/i);
|
|
23742
|
+
if (castMatch) {
|
|
23743
|
+
normalized = castMatch[1].trim();
|
|
23744
|
+
}
|
|
23745
|
+
normalized = normalized.trim();
|
|
23746
|
+
const quotedNumeric = normalized.match(/^'(-?\d+(?:\.\d+)?)'$/);
|
|
23747
|
+
if (quotedNumeric) {
|
|
23748
|
+
normalized = quotedNumeric[1];
|
|
23749
|
+
}
|
|
23750
|
+
return normalized;
|
|
23729
23751
|
}
|
|
23730
23752
|
function normalizeExpression(expr) {
|
|
23731
|
-
let normalized = expr.replace(/\s+/g, " ").trim().replace(/::[a-z_]+(\([^)]*\))?/gi, "").replace(/\(([a-z_][a-z0-9_]*)\)/gi, "$1");
|
|
23753
|
+
let normalized = expr.replace(/\s+/g, " ").trim().replace(/::"?[a-z_]+"?(\([^)]*\))?/gi, "").replace(/\bpg_catalog\./gi, "").replace(/\((-?\d+(?:\.\d+)?)\)/g, "$1").replace(/(?<![a-z0-9_])\(([a-z_][a-z0-9_]*)\)/gi, "$1");
|
|
23754
|
+
let prevNormalized;
|
|
23755
|
+
do {
|
|
23756
|
+
prevNormalized = normalized;
|
|
23757
|
+
normalized = normalized.replace(/\(([a-z_][a-z0-9_]*\s*[<>=!]+\s*-?\d+(?:\.\d+)?)\)/gi, "$1").replace(/\(([a-z_][a-z0-9_]*\s+(?:IS\s+(?:NOT\s+)?NULL|IN\s+\([^)]*\)))\)/gi, "$1").replace(/\(([a-z_][a-z0-9_]*\s+IS\s+NOT\s+NULL\s+AND\s+[^)]+)\)/gi, "$1").replace(/\(([a-z_][a-z0-9_]*\s*\*\s*\([^)]+\))\)/gi, "$1");
|
|
23758
|
+
} while (normalized !== prevNormalized);
|
|
23732
23759
|
while (/^\(.*\)$/.test(normalized)) {
|
|
23733
23760
|
const inner = normalized.slice(1, -1);
|
|
23734
23761
|
let depth = 0;
|
|
@@ -24681,7 +24708,9 @@ class SchemaDiffer {
|
|
|
24681
24708
|
if (index1.columns[i] !== index2.columns[i])
|
|
24682
24709
|
return false;
|
|
24683
24710
|
}
|
|
24684
|
-
|
|
24711
|
+
const where1 = index1.where ? normalizeExpression(index1.where) : undefined;
|
|
24712
|
+
const where2 = index2.where ? normalizeExpression(index2.where) : undefined;
|
|
24713
|
+
if (where1 !== where2)
|
|
24685
24714
|
return false;
|
|
24686
24715
|
if (index1.expression !== index2.expression)
|
|
24687
24716
|
return false;
|
|
@@ -24957,9 +24986,8 @@ class SchemaDiffer {
|
|
|
24957
24986
|
}
|
|
24958
24987
|
}
|
|
24959
24988
|
collectCheckConstraintAlterations(desiredConstraints, currentConstraints, alterations) {
|
|
24960
|
-
const
|
|
24961
|
-
const
|
|
24962
|
-
const desiredMap = new Map(desiredConstraints.map((c) => [normalizeExpression2(c.expression), c]));
|
|
24989
|
+
const currentMap = new Map(currentConstraints.map((c) => [normalizeExpression(c.expression), c]));
|
|
24990
|
+
const desiredMap = new Map(desiredConstraints.map((c) => [normalizeExpression(c.expression), c]));
|
|
24963
24991
|
for (const [key, constraint] of currentMap) {
|
|
24964
24992
|
if (!desiredMap.has(key) && constraint.name) {
|
|
24965
24993
|
alterations.push({
|
|
@@ -25014,7 +25042,7 @@ class SchemaDiffer {
|
|
|
25014
25042
|
}
|
|
25015
25043
|
}
|
|
25016
25044
|
collectUniqueConstraintAlterations(desiredConstraints, currentConstraints, alterations) {
|
|
25017
|
-
const getStructuralKey = (c) =>
|
|
25045
|
+
const getStructuralKey = (c) => c.columns.join(",");
|
|
25018
25046
|
const currentMap = new Map(currentConstraints.map((c) => [getStructuralKey(c), c]));
|
|
25019
25047
|
const desiredMap = new Map(desiredConstraints.map((c) => [getStructuralKey(c), c]));
|
|
25020
25048
|
for (const [key, constraint] of currentMap) {
|
|
@@ -25864,7 +25892,7 @@ async function applyCommand(options, config6) {
|
|
|
25864
25892
|
// package.json
|
|
25865
25893
|
var package_default = {
|
|
25866
25894
|
name: "pgterra",
|
|
25867
|
-
version: "0.2.
|
|
25895
|
+
version: "0.2.15",
|
|
25868
25896
|
description: "Declarative schema management for Postgres",
|
|
25869
25897
|
keywords: [
|
|
25870
25898
|
"postgres",
|