knex-schema-inspector
Advanced tools
Comparing version 3.0.0 to 3.0.1
@@ -232,3 +232,3 @@ "use strict"; | ||
knex.raw("\n SELECT *, CASE WHEN res.is_generated THEN (\n SELECT\n generation_expression\n FROM\n information_schema.columns\n WHERE\n table_schema = res.schema \n AND table_name = res.table \n AND column_name = res.name\n ) ELSE NULL END AS generation_expression\n FROM (\n SELECT\n att.attname AS name,\n rel.relname AS table,\n rel.relnamespace::regnamespace::text AS schema,\n format_type(att.atttypid, null) AS data_type,\n NOT att.attnotnull AS is_nullable,\n CASE WHEN att.attgenerated = '' THEN pg_get_expr(ad.adbin, ad.adrelid) ELSE null END AS default_value,\n att.attgenerated = 's' AS is_generated,\n CASE\n WHEN att.atttypid IN (1042, 1043) THEN (att.atttypmod - 4)::int4\n WHEN att.atttypid IN (1560, 1562) THEN (att.atttypmod)::int4\n ELSE NULL\n END AS max_length,\n des.description AS comment,\n CASE att.atttypid\n WHEN 21 THEN 16\n WHEN 23 THEN 32\n WHEN 20 THEN 64\n WHEN 1700 THEN\n CASE WHEN atttypmod = -1 THEN NULL\n ELSE (((atttypmod - 4) >> 16) & 65535)::int4\n END\n WHEN 700 THEN 24\n WHEN 701 THEN 53\n ELSE NULL\n END AS numeric_precision,\n CASE\n WHEN atttypid IN (21, 23, 20) THEN 0\n WHEN atttypid = 1700 THEN\n CASE\n WHEN atttypmod = -1 THEN NULL\n ELSE ((atttypmod - 4) & 65535)::int4\n END\n ELSE null\n END AS numeric_scale\n FROM\n pg_attribute att\n LEFT JOIN pg_class rel ON att.attrelid = rel.oid\n LEFT JOIN pg_attrdef ad ON (att.attrelid, att.attnum) = (ad.adrelid, ad.adnum)\n LEFT JOIN pg_description des ON (att.attrelid, att.attnum) = (des.objoid, des.objsubid)\n WHERE\n rel.relnamespace IN (".concat(schemaIn, ")\n ").concat(table ? 'AND rel.relname = ?' : '', "\n ").concat(column ? 'AND att.attname = ?' : '', "\n AND rel.relkind = 'r'\n AND att.attnum > 0\n AND NOT att.attisdropped\n ORDER BY rel.relname, att.attnum) res;\n "), bindings), | ||
knex.raw("\n SELECT\n con.contype AS type,\n rel.relname AS table,\n att.attname AS column,\n frel.relnamespace::regnamespace::text AS foreign_key_schema,\n frel.relname AS foreign_key_table,\n fatt.attname AS foreign_key_column,\n false AS has_auto_increment\n FROM\n pg_constraint con\n LEFT JOIN pg_class rel ON con.conrelid = rel.oid\n LEFT JOIN pg_class frel ON con.confrelid = frel.oid\n LEFT JOIN pg_attribute att ON att.attrelid = con.conrelid AND att.attnum = con.conkey[1]\n LEFT JOIN pg_attribute fatt ON fatt.attrelid = con.confrelid AND fatt.attnum = con.confkey[1]\n WHERE con.connamespace IN (".concat(schemaIn, ")\n AND array_length(con.conkey, 1) <= 1\n AND (con.confkey IS NULL OR array_length(con.confkey, 1) = 1)\n ").concat(table ? 'AND rel.relname = ?' : '', "\n ").concat(column ? 'AND att.attname = ?' : '', "\n "), bindings), | ||
knex.raw("\n SELECT\n con.contype AS type,\n rel.relname AS table,\n att.attname AS column,\n frel.relnamespace::regnamespace::text AS foreign_key_schema,\n frel.relname AS foreign_key_table,\n fatt.attname AS foreign_key_column\n FROM\n pg_constraint con\n LEFT JOIN pg_class rel ON con.conrelid = rel.oid\n LEFT JOIN pg_class frel ON con.confrelid = frel.oid\n LEFT JOIN pg_attribute att ON att.attrelid = con.conrelid AND att.attnum = con.conkey[1]\n LEFT JOIN pg_attribute fatt ON fatt.attrelid = con.confrelid AND fatt.attnum = con.confkey[1]\n WHERE con.connamespace IN (".concat(schemaIn, ")\n AND array_length(con.conkey, 1) <= 1\n AND (con.confkey IS NULL OR array_length(con.confkey, 1) = 1)\n ").concat(table ? 'AND rel.relname = ?' : '', "\n ").concat(column ? 'AND att.attname = ?' : '', "\n "), bindings), | ||
])]; | ||
@@ -238,3 +238,3 @@ case 1: | ||
parsedColumms = columns.rows.map(function (col) { | ||
var _a, _b, _c; | ||
var _a, _b, _c, _d, _e; | ||
var constraintsForColumn = constraints.rows.filter(function (constraint) { | ||
@@ -246,3 +246,4 @@ return constraint.table === col.table && constraint.column === col.name; | ||
return ['u', 'p'].includes(constraint.type); | ||
}), is_primary_key: constraintsForColumn.some(function (constraint) { return constraint.type === 'p'; }), has_auto_increment: constraintsForColumn.some(function (constraint) { return constraint.has_auto_increment; }), default_value: parseDefaultValue(col.default_value), foreign_key_schema: (_a = foreignKeyConstraint === null || foreignKeyConstraint === void 0 ? void 0 : foreignKeyConstraint.foreign_key_schema) !== null && _a !== void 0 ? _a : null, foreign_key_table: (_b = foreignKeyConstraint === null || foreignKeyConstraint === void 0 ? void 0 : foreignKeyConstraint.foreign_key_table) !== null && _b !== void 0 ? _b : null, foreign_key_column: (_c = foreignKeyConstraint === null || foreignKeyConstraint === void 0 ? void 0 : foreignKeyConstraint.foreign_key_column) !== null && _c !== void 0 ? _c : null }); | ||
}), is_primary_key: constraintsForColumn.some(function (constraint) { return constraint.type === 'p'; }), has_auto_increment: ['integer', 'bigint'].includes(col.data_type) && | ||
((_b = (_a = col.default_value) === null || _a === void 0 ? void 0 : _a.startsWith('nextval(')) !== null && _b !== void 0 ? _b : false), default_value: parseDefaultValue(col.default_value), foreign_key_schema: (_c = foreignKeyConstraint === null || foreignKeyConstraint === void 0 ? void 0 : foreignKeyConstraint.foreign_key_schema) !== null && _c !== void 0 ? _c : null, foreign_key_table: (_d = foreignKeyConstraint === null || foreignKeyConstraint === void 0 ? void 0 : foreignKeyConstraint.foreign_key_table) !== null && _d !== void 0 ? _d : null, foreign_key_column: (_e = foreignKeyConstraint === null || foreignKeyConstraint === void 0 ? void 0 : foreignKeyConstraint.foreign_key_column) !== null && _e !== void 0 ? _e : null }); | ||
}); | ||
@@ -249,0 +250,0 @@ if (table && column) |
@@ -278,4 +278,3 @@ import { Knex } from 'knex'; | ||
frel.relname AS foreign_key_table, | ||
fatt.attname AS foreign_key_column, | ||
false AS has_auto_increment | ||
fatt.attname AS foreign_key_column | ||
FROM | ||
@@ -315,5 +314,5 @@ pg_constraint con | ||
), | ||
has_auto_increment: constraintsForColumn.some( | ||
(constraint) => constraint.has_auto_increment | ||
), | ||
has_auto_increment: | ||
['integer', 'bigint'].includes(col.data_type) && | ||
(col.default_value?.startsWith('nextval(') ?? false), | ||
default_value: parseDefaultValue(col.default_value), | ||
@@ -320,0 +319,0 @@ foreign_key_schema: foreignKeyConstraint?.foreign_key_schema ?? null, |
{ | ||
"name": "knex-schema-inspector", | ||
"version": "3.0.0", | ||
"version": "3.0.1", | ||
"description": "Utility for extracting information about existing DB schema", | ||
"main": "dist/index.js", | ||
"types": "dist/index.d.ts", | ||
"scripts": { | ||
"build": "tsc --build", | ||
"prepare": "npm run build", | ||
"lint": "prettier --check .", | ||
"test": "npm run lint && ts-mocha test/**/*.spec.ts --timeout 10000" | ||
}, | ||
"repository": { | ||
@@ -71,3 +65,8 @@ "type": "git", | ||
"lodash.isnil": "^4.0.0" | ||
}, | ||
"scripts": { | ||
"build": "tsc --build", | ||
"lint": "prettier --check .", | ||
"test": "npm run lint && ts-mocha test/**/*.spec.ts --timeout 10000" | ||
} | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
408632