Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@directus/schema

Package Overview
Dependencies
Maintainers
3
Versions
169
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@directus/schema - npm Package Compare versions

Comparing version 9.0.0-rc.101 to 9.0.0

92

dist/dialects/postgres.js

@@ -80,7 +80,7 @@ "use strict";

Postgres.prototype.overview = function () {
var _a, _b, _c, _d;
var _a;
return __awaiter(this, void 0, void 0, function () {
var _e, columnsResult, primaryKeysResult, columns, primaryKeys, geometryColumns, hasPostGIS, result, overview, _i, columns_1, column, _f, primaryKeys_1, _g, table_name, column_name, _h, geometryColumns_1, _j, table_name, column_name, data_type;
return __generator(this, function (_k) {
switch (_k.label) {
var _b, columnsResult, primaryKeysResult, columns, primaryKeys, geometryColumns, hasPostGIS, result, overview, _i, columns_1, column, _c, primaryKeys_1, _d, table_name, column_name, _e, geometryColumns_1, _f, table_name, column_name, data_type;
return __generator(this, function (_g) {
switch (_g.label) {
case 0:

@@ -94,15 +94,15 @@ return [4 /*yield*/, Promise.all([

case 1:
_e = _k.sent(), columnsResult = _e[0], primaryKeysResult = _e[1];
_b = _g.sent(), columnsResult = _b[0], primaryKeysResult = _b[1];
columns = columnsResult.rows;
primaryKeys = primaryKeysResult.rows;
geometryColumns = [];
return [4 /*yield*/, this.knex.raw("SELECT EXISTS (\n\t\t\t\tSELECT\n\t\t\t\tFROM\n\t\t\t\t\tpg_proc p\n\t\t\t\t\tJOIN pg_namespace n ON p.pronamespace = n.oid\n\t\t\t\tWHERE\n\t\t\t\t\tn.nspname IN(?)\n\t\t\t\t\tAND p.oid::regprocedure::varchar = 'postgis_version()'\n\t\t\t);", [this.explodedSchema.join(',')])];
return [4 /*yield*/, this.knex.raw("SELECT oid FROM pg_proc WHERE proname = 'postgis_version'")];
case 2:
hasPostGIS = (_c = (_b = (_a = (_k.sent())) === null || _a === void 0 ? void 0 : _a.rows) === null || _b === void 0 ? void 0 : _b[0]) === null || _c === void 0 ? void 0 : _c.exists;
hasPostGIS = (_g.sent()).rows.length > 0;
if (!hasPostGIS) return [3 /*break*/, 4];
return [4 /*yield*/, this.knex.raw("WITH geometries as (\n\t\t\t\t\tselect * from geometry_columns\n\t\t\t\t\tunion\n\t\t\t\t\tselect * from geography_columns\n\t\t\t\t)\n\t\t\t\tSELECT f_table_name as table_name\n\t\t\t\t\t, f_geometry_column as column_name\n\t\t\t\t\t, type as data_type\n\t\t\t\tFROM geometries g\n\t\t\t\tJOIN information_schema.tables t\n\t\t\t\t\tON g.f_table_name = t.table_name\n\t\t\t\t\tAND t.table_type = 'BASE TABLE'\n\t\t\t\tWHERE f_table_schema in (?)\n\t\t\t\t", [this.explodedSchema.join(',')])];
case 3:
result = _k.sent();
result = _g.sent();
geometryColumns = result.rows;
_k.label = 4;
_g.label = 4;
case 4:

@@ -112,3 +112,3 @@ overview = {};

column = columns_1[_i];
if (column.is_identity || ((_d = column.default_value) === null || _d === void 0 ? void 0 : _d.startsWith('nextval('))) {
if (column.is_identity || ((_a = column.default_value) === null || _a === void 0 ? void 0 : _a.startsWith('nextval('))) {
column.default_value = 'AUTO_INCREMENT';

@@ -122,10 +122,13 @@ }

}
if (['point', 'polygon'].includes(column.data_type)) {
column.data_type = 'unknown';
}
overview[column.table_name].columns[column.column_name] = column;
}
for (_f = 0, primaryKeys_1 = primaryKeys; _f < primaryKeys_1.length; _f++) {
_g = primaryKeys_1[_f], table_name = _g.table_name, column_name = _g.column_name;
for (_c = 0, primaryKeys_1 = primaryKeys; _c < primaryKeys_1.length; _c++) {
_d = primaryKeys_1[_c], table_name = _d.table_name, column_name = _d.column_name;
overview[table_name].primary = column_name;
}
for (_h = 0, geometryColumns_1 = geometryColumns; _h < geometryColumns_1.length; _h++) {
_j = geometryColumns_1[_h], table_name = _j.table_name, column_name = _j.column_name, data_type = _j.data_type;
for (_e = 0, geometryColumns_1 = geometryColumns; _e < geometryColumns_1.length; _e++) {
_f = geometryColumns_1[_e], table_name = _f.table_name, column_name = _f.column_name, data_type = _f.data_type;
overview[table_name].columns[column_name].data_type = data_type;

@@ -140,22 +143,23 @@ }

return __awaiter(this, void 0, void 0, function () {
var columns, _a, query, geometry, geometries, _loop_1, _i, columns_2, column_1;
return __generator(this, function (_b) {
switch (_b.label) {
var columns, _i, _a, column_1, hasPostGIS, query, geometry, geometries, _loop_1, _b, columns_2, column_2;
return __generator(this, function (_c) {
switch (_c.label) {
case 0: return [4 /*yield*/, _super.prototype.columnInfo.call(this, table, column)];
case 1:
columns = _b.sent();
columns = _c.sent();
if (!(columns === null || columns === void 0 ? void 0 : columns.length)) {
return [2 /*return*/, columns];
}
_b.label = 2;
for (_i = 0, _a = Array.isArray(columns) ? columns : [columns]; _i < _a.length; _i++) {
column_1 = _a[_i];
if (['point', 'polygon'].includes(column_1.data_type)) {
column_1.data_type = 'unknown';
}
}
return [4 /*yield*/, this.knex.raw("SELECT oid FROM pg_proc WHERE proname = 'postgis_version'")];
case 2:
_b.trys.push([2, 4, , 5]);
return [4 /*yield*/, this.knex.raw('select postgis_version()')];
case 3:
_b.sent();
return [3 /*break*/, 5];
case 4:
_a = _b.sent();
return [2 /*return*/, columns];
case 5:
hasPostGIS = (_c.sent()).rows.length > 0;
if (!hasPostGIS) {
return [2 /*return*/, columns];
}
query = this.knex

@@ -173,30 +177,24 @@ .with('geometries', this.knex.raw("\n\t\t\t\tselect * from geometry_columns\n\t\t\t\tunion\n\t\t\t\tselect * from geography_columns\n\t\t"))

}
if (!column) return [3 /*break*/, 7];
if (['point', 'polygon'].includes(columns.data_type)) {
columns.data_type = 'unknown';
}
if (!column) return [3 /*break*/, 4];
return [4 /*yield*/, query.andWhere('f_geometry_column', column).first()];
case 6:
geometry = _b.sent();
case 3:
geometry = _c.sent();
if (geometry) {
columns.data_type = geometry.data_type;
}
_b.label = 7;
case 7: return [4 /*yield*/, query];
case 8:
geometries = _b.sent();
_loop_1 = function (column_1) {
if (['point', 'polygon'].includes(column_1.data_type)) {
column_1.data_type = 'unknown';
}
_c.label = 4;
case 4: return [4 /*yield*/, query];
case 5:
geometries = _c.sent();
_loop_1 = function (column_2) {
var geometry = geometries.find(function (geometry) {
return column_1.name == geometry.name && column_1.table == geometry.table;
return column_2.name == geometry.name && column_2.table == geometry.table;
});
if (geometry) {
column_1.data_type = geometry.data_type;
column_2.data_type = geometry.data_type;
}
};
for (_i = 0, columns_2 = columns; _i < columns_2.length; _i++) {
column_1 = columns_2[_i];
_loop_1(column_1);
for (_b = 0, columns_2 = columns; _b < columns_2.length; _b++) {
column_2 = columns_2[_b];
_loop_1(column_2);
}

@@ -203,0 +201,0 @@ return [2 /*return*/, columns];

{
"name": "@directus/schema",
"version": "9.0.0-rc.101",
"version": "9.0.0",
"description": "Utility for extracting information about existing DB schema",

@@ -52,3 +52,3 @@ "main": "dist/index.js",

},
"gitHead": "37cf80e0fe1320610ffc0b4da9411ef51bd46afb"
"gitHead": "c95add08ef1386cab6e54546f03d541d889148ed"
}

@@ -76,16 +76,4 @@ import KnexPostgres, { parseDefaultValue } from 'knex-schema-inspector/dist/dialects/postgres';

// SQL, which we can't catch in JS.
const hasPostGIS = (
await this.knex.raw(
`SELECT EXISTS (
SELECT
FROM
pg_proc p
JOIN pg_namespace n ON p.pronamespace = n.oid
WHERE
n.nspname IN(?)
AND p.oid::regprocedure::varchar = 'postgis_version()'
);`,
[this.explodedSchema.join(',')]
)
)?.rows?.[0]?.exists;
const hasPostGIS =
(await this.knex.raw(`SELECT oid FROM pg_proc WHERE proname = 'postgis_version'`)).rows.length > 0;

@@ -126,2 +114,5 @@ if (hasPostGIS) {

}
if (['point', 'polygon'].includes(column.data_type)) {
column.data_type = 'unknown';
}
overview[column.table_name].columns[column.column_name] = column;

@@ -152,5 +143,13 @@ }

}
try {
await this.knex.raw('select postgis_version()');
} catch {
for (const column of Array.isArray(columns) ? columns : [columns]) {
if (['point', 'polygon'].includes(column.data_type)) {
column.data_type = 'unknown';
}
}
const hasPostGIS =
(await this.knex.raw(`SELECT oid FROM pg_proc WHERE proname = 'postgis_version'`)).rows.length > 0;
if (!hasPostGIS) {
return columns;

@@ -180,5 +179,2 @@ }

if (column) {
if (['point', 'polygon'].includes(columns.data_type)) {
columns.data_type = 'unknown';
}
const geometry = await query.andWhere('f_geometry_column', column).first();

@@ -191,5 +187,2 @@ if (geometry) {

for (const column of columns) {
if (['point', 'polygon'].includes(column.data_type)) {
column.data_type = 'unknown';
}
const geometry = geometries.find((geometry) => {

@@ -196,0 +189,0 @@ return column.name == geometry.name && column.table == geometry.table;

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc