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.1 to 9.1.0

2

dist/dialects/mssql.js

@@ -98,3 +98,3 @@ "use strict";

switch (_b.label) {
case 0: return [4 /*yield*/, this.knex.raw("\n\t\t\tSELECT\n\t\t\t\tc.TABLE_NAME as table_name,\n\t\t\t\tc.COLUMN_NAME as column_name,\n\t\t\t\tc.COLUMN_DEFAULT as default_value,\n\t\t\t\tc.IS_NULLABLE as is_nullable,\n\t\t\t\tc.DATA_TYPE as data_type,\n\t\t\t\tc.CHARACTER_MAXIMUM_LENGTH as max_length,\n\t\t\t\tpk.PK_SET as column_key,\n\t\t\t\tCOLUMNPROPERTY(OBJECT_ID(c.TABLE_SCHEMA + '.' + c.TABLE_NAME), c.COLUMN_NAME, 'IsIdentity') as is_identity,\n\t\t\t\tCOLUMNPROPERTY(OBJECT_ID(c.TABLE_SCHEMA + '.' + c.TABLE_NAME), c.COLUMN_NAME, 'IsComputed') as is_generated\n\t\t\tFROM\n\t\t\t\t[" + this.knex.client.database() + "].INFORMATION_SCHEMA.COLUMNS as c\n\t\t\tLEFT JOIN (\n\t\t\t\tSELECT\n\t\t\t\t\tPK_SET = CASE WHEN CONSTRAINT_NAME LIKE '%pk%' THEN 'PRIMARY' ELSE NULL END,\n\t\t\t\t\tTABLE_NAME,\n\t\t\t\t\tCONSTRAINT_CATALOG,\n\t\t\t\t\tCOLUMN_NAME\n\t\t\t\tFROM [" + this.knex.client.database() + "].INFORMATION_SCHEMA.KEY_COLUMN_USAGE\n\t\t\t) as pk\n\t\t\tON [c].[TABLE_NAME] = [pk].[TABLE_NAME]\n\t\t\tAND [c].[TABLE_CATALOG] = [pk].[CONSTRAINT_CATALOG]\n\t\t\tAND [c].[COLUMN_NAME] = [pk].[COLUMN_NAME]\n\t\t\tINNER JOIN\n\t\t\t\t[" + this.knex.client.database() + "].INFORMATION_SCHEMA.TABLES as t\n\t\t\tON [c].[TABLE_NAME] = [t].[TABLE_NAME]\n\t\t\tAND [c].[TABLE_CATALOG] = [t].[TABLE_CATALOG]\n\t\t\tAND [t].TABLE_TYPE = 'BASE TABLE'\n\t\t\t")];
case 0: return [4 /*yield*/, this.knex.raw("\n\t\t\tSELECT\n\t\t\t\tc.TABLE_NAME as table_name,\n\t\t\t\tc.COLUMN_NAME as column_name,\n\t\t\t\tc.COLUMN_DEFAULT as default_value,\n\t\t\t\tc.IS_NULLABLE as is_nullable,\n\t\t\t\tc.DATA_TYPE as data_type,\n\t\t\t\tc.CHARACTER_MAXIMUM_LENGTH as max_length,\n\t\t\t\tpk.PK_SET as column_key,\n\t\t\t\tCOLUMNPROPERTY(OBJECT_ID(c.TABLE_SCHEMA + '.' + c.TABLE_NAME), c.COLUMN_NAME, 'IsIdentity') as is_identity,\n\t\t\t\tCOLUMNPROPERTY(OBJECT_ID(c.TABLE_SCHEMA + '.' + c.TABLE_NAME), c.COLUMN_NAME, 'IsComputed') as is_generated\n\t\t\tFROM\n\t\t\t\t[".concat(this.knex.client.database(), "].INFORMATION_SCHEMA.COLUMNS as c\n\t\t\tLEFT JOIN (\n\t\t\t\tSELECT\n\t\t\t\t\tPK_SET = CASE WHEN CONSTRAINT_NAME LIKE '%pk%' THEN 'PRIMARY' ELSE NULL END,\n\t\t\t\t\tTABLE_NAME,\n\t\t\t\t\tCONSTRAINT_CATALOG,\n\t\t\t\t\tCOLUMN_NAME,\n\t\t\t\t\tCOUNT(*) OVER (PARTITION BY CONSTRAINT_NAME) as PK_COUNT\n\t\t\t\tFROM [").concat(this.knex.client.database(), "].INFORMATION_SCHEMA.KEY_COLUMN_USAGE\n\t\t\t) as pk\n\t\t\tON [c].[TABLE_NAME] = [pk].[TABLE_NAME]\n\t\t\tAND [c].[TABLE_CATALOG] = [pk].[CONSTRAINT_CATALOG]\n\t\t\tAND [c].[COLUMN_NAME] = [pk].[COLUMN_NAME]\n\t\t\tAND [pk].[PK_SET] = 'PRIMARY'\n\t\t\tAND [pk].[PK_COUNT] = 1\n\t\t\tINNER JOIN\n\t\t\t\t[").concat(this.knex.client.database(), "].INFORMATION_SCHEMA.TABLES as t\n\t\t\tON [c].[TABLE_NAME] = [t].[TABLE_NAME]\n\t\t\tAND [c].[TABLE_CATALOG] = [t].[TABLE_CATALOG]\n\t\t\tAND [t].TABLE_TYPE = 'BASE TABLE'\n\t\t\t"))];
case 1:

@@ -101,0 +101,0 @@ columns = _b.sent();

@@ -91,17 +91,18 @@ "use strict";

MySQL.prototype.overview = function () {
var _a, _b, _c;
var _a, _b;
return __awaiter(this, void 0, void 0, function () {
var columns, overview, _loop_1, _i, _d, column;
return __generator(this, function (_e) {
switch (_e.label) {
var columns, overview, _loop_1, _i, _c, column;
return __generator(this, function (_d) {
switch (_d.label) {
case 0: return [4 /*yield*/, this.knex.raw("\n\t\t\tSELECT\n\t\t\t\tC.TABLE_NAME as table_name,\n\t\t\t\tC.COLUMN_NAME as column_name,\n\t\t\t\tC.COLUMN_DEFAULT as default_value,\n\t\t\t\tC.IS_NULLABLE as is_nullable,\n\t\t\t\tC.COLUMN_TYPE as data_type,\n\t\t\t\tC.COLUMN_KEY as column_key,\n\t\t\t\tC.CHARACTER_MAXIMUM_LENGTH as max_length,\n\t\t\t\tC.EXTRA as extra\n\t\t\tFROM\n\t\t\t\tINFORMATION_SCHEMA.COLUMNS AS C\n\t\t\tLEFT JOIN\n\t\t\t\tINFORMATION_SCHEMA.TABLES AS T ON C.TABLE_NAME = T.TABLE_NAME\n\t\t\tWHERE\n\t\t\t\tT.TABLE_TYPE = 'BASE TABLE' AND\n\t\t\t\tC.TABLE_SCHEMA = ?;\n\t\t\t", [this.knex.client.database()])];
case 1:
columns = _e.sent();
columns = _d.sent();
overview = {};
_loop_1 = function (column) {
if (column.table_name in overview === false) {
var primaryKeys = columns[0].filter(function (nested) {
return nested.table_name === column.table_name && nested.column_key === 'PRI';
});
overview[column.table_name] = {
primary: (_a = columns[0].find(function (nested) {
return nested.table_name === column.table_name && nested.column_key === 'PRI';
})) === null || _a === void 0 ? void 0 : _a.column_name,
primary: primaryKeys.length !== 1 ? undefined : primaryKeys[0].column_name,
columns: {},

@@ -119,6 +120,6 @@ };

}
overview[column.table_name].columns[column.column_name] = __assign(__assign({}, column), { default_value: column.extra === 'auto_increment' ? 'AUTO_INCREMENT' : (0, mysql_1.parseDefaultValue)(column.default_value), is_nullable: column.is_nullable === 'YES', is_generated: (_c = (_b = column.extra) === null || _b === void 0 ? void 0 : _b.endsWith('GENERATED')) !== null && _c !== void 0 ? _c : false, data_type: dataType });
overview[column.table_name].columns[column.column_name] = __assign(__assign({}, column), { default_value: column.extra === 'auto_increment' ? 'AUTO_INCREMENT' : (0, mysql_1.parseDefaultValue)(column.default_value), is_nullable: column.is_nullable === 'YES', is_generated: (_b = (_a = column.extra) === null || _a === void 0 ? void 0 : _a.endsWith('GENERATED')) !== null && _b !== void 0 ? _b : false, data_type: dataType });
};
for (_i = 0, _d = columns[0]; _i < _d.length; _i++) {
column = _d[_i];
for (_i = 0, _c = columns[0]; _i < _c.length; _i++) {
column = _c[_i];
_loop_1(column);

@@ -125,0 +126,0 @@ }

@@ -107,3 +107,3 @@ "use strict";

case 0:
return [4 /*yield*/, this.knex.raw("\n\t\t\tWITH \"uc\" AS (\n\t\t\t\tSELECT /*+ materialize */\n\t\t\t\t\t\"uc\".\"TABLE_NAME\",\n\t\t\t\t\t\"ucc\".\"COLUMN_NAME\",\n\t\t\t\t\t\"uc\".\"CONSTRAINT_TYPE\"\n\t\t\t\tFROM \"USER_CONSTRAINTS\" \"uc\"\n\t\t\t\tINNER JOIN \"USER_CONS_COLUMNS\" \"ucc\" ON \"uc\".\"CONSTRAINT_NAME\" = \"ucc\".\"CONSTRAINT_NAME\"\n\t\t\t\tWHERE \"uc\".\"CONSTRAINT_TYPE\" = 'P'\n\t\t\t)\n\t\t\tSELECT\n\t\t\t\t\"c\".\"TABLE_NAME\" \"table_name\",\n\t\t\t\t\"c\".\"COLUMN_NAME\" \"column_name\",\n\t\t\t\t\"c\".\"DATA_DEFAULT\" \"default_value\",\n\t\t\t\t\"c\".\"NULLABLE\" \"is_nullable\",\n\t\t\t\t\"c\".\"DATA_TYPE\" \"data_type\",\n\t\t\t\t\"c\".\"DATA_PRECISION\" \"numeric_precision\",\n\t\t\t\t\"c\".\"DATA_SCALE\" \"numeric_scale\",\n\t\t\t\t\"ct\".\"CONSTRAINT_TYPE\" \"column_key\",\n\t\t\t\t\"c\".\"CHAR_LENGTH\" \"max_length\",\n\t\t\t\t\"c\".\"VIRTUAL_COLUMN\" \"is_generated\"\n\t\t\tFROM \"USER_TAB_COLS\" \"c\"\n\t\t\tLEFT JOIN \"uc\" \"ct\" ON \"c\".\"TABLE_NAME\" = \"ct\".\"TABLE_NAME\"\n\t\t\t\tAND \"c\".\"COLUMN_NAME\" = \"ct\".\"COLUMN_NAME\"\n\t\t\tWHERE \"c\".\"HIDDEN_COLUMN\" = 'NO'\n\t\t")];
return [4 /*yield*/, this.knex.raw("\n\t\t\tWITH \"uc\" AS (\n\t\t\t\tSELECT /*+ materialize */\n\t\t\t\t\t\"uc\".\"TABLE_NAME\",\n\t\t\t\t\t\"ucc\".\"COLUMN_NAME\",\n\t\t\t\t\t\"uc\".\"CONSTRAINT_TYPE\"\n\t\t\t\tFROM \"USER_CONSTRAINTS\" \"uc\"\n\t\t\t\tINNER JOIN (\n\t\t\t\t\tSELECT\n\t\t\t\t\t\t\"COLUMN_NAME\",\n\t\t\t\t\t\t\"CONSTRAINT_NAME\",\n\t\t\t\t\t\tCOUNT(*) OVER(PARTITION BY \"CONSTRAINT_NAME\") \"INDEX_COLUMN_COUNT\"\n\t\t\t\t\tFROM \"USER_CONS_COLUMNS\"\n\t\t\t\t) \"ucc\"\n\t\t\t\t\tON \"uc\".\"CONSTRAINT_NAME\" = \"ucc\".\"CONSTRAINT_NAME\"\n\t\t\t\t\tAND \"uc\".\"CONSTRAINT_TYPE\" = 'P'\n\t\t\t\t\tAND \"ucc\".\"INDEX_COLUMN_COUNT\" = 1\n\t\t\t)\n\t\t\tSELECT\n\t\t\t\t\"c\".\"TABLE_NAME\" \"table_name\",\n\t\t\t\t\"c\".\"COLUMN_NAME\" \"column_name\",\n\t\t\t\t\"c\".\"DATA_DEFAULT\" \"default_value\",\n\t\t\t\t\"c\".\"NULLABLE\" \"is_nullable\",\n\t\t\t\t\"c\".\"DATA_TYPE\" \"data_type\",\n\t\t\t\t\"c\".\"DATA_PRECISION\" \"numeric_precision\",\n\t\t\t\t\"c\".\"DATA_SCALE\" \"numeric_scale\",\n\t\t\t\t\"ct\".\"CONSTRAINT_TYPE\" \"column_key\",\n\t\t\t\t\"c\".\"CHAR_LENGTH\" \"max_length\",\n\t\t\t\t\"c\".\"VIRTUAL_COLUMN\" \"is_generated\"\n\t\t\tFROM \"USER_TAB_COLS\" \"c\"\n\t\t\tLEFT JOIN \"uc\" \"ct\"\n\t\t\t\tON \"c\".\"TABLE_NAME\" = \"ct\".\"TABLE_NAME\"\n\t\t\t\tAND \"c\".\"COLUMN_NAME\" = \"ct\".\"COLUMN_NAME\"\n\t\t\tWHERE \"c\".\"HIDDEN_COLUMN\" = 'NO'\n\t\t")];
case 1:

@@ -110,0 +110,0 @@ columns = _b.sent();

@@ -90,3 +90,3 @@ "use strict";

this.knex.raw("\n SELECT c.table_name\n , c.column_name\n , c.column_default as default_value\n , c.data_type\n\t\t\t \t\t, c.character_maximum_length as max_length\n , c.is_generated = 'ALWAYS' is_generated\n , CASE WHEN c.is_identity = 'YES' THEN true ELSE false END is_identity\n , CASE WHEN c.is_nullable = 'YES' THEN true ELSE false END is_nullable\n FROM\n information_schema.columns c\n LEFT JOIN information_schema.tables t\n ON c.table_name = t.table_name\n WHERE\n t.table_type = 'BASE TABLE'\n AND c.table_schema IN (?);\n ", [this.explodedSchema.join(',')]),
this.knex.raw("\n SELECT relname as table_name\n , pg_attribute.attname as column_name\n FROM pg_index\n , pg_class\n , pg_attribute\n , pg_namespace\n WHERE\n indrelid = pg_class.oid\n AND nspname IN (?)\n AND pg_class.relnamespace = pg_namespace.oid\n AND pg_attribute.attrelid = pg_class.oid\n AND pg_attribute.attnum = ANY (pg_index.indkey)\n AND indisprimary\n ", [this.explodedSchema.join(',')]),
this.knex.raw("\n SELECT relname as table_name\n , pg_attribute.attname as column_name\n FROM pg_index\n , pg_class\n , pg_attribute\n , pg_namespace\n WHERE\n indrelid = pg_class.oid\n AND nspname IN (?)\n AND pg_class.relnamespace = pg_namespace.oid\n AND pg_attribute.attrelid = pg_class.oid\n AND pg_attribute.attnum = ANY (pg_index.indkey)\n AND indisprimary\n AND indnkeyatts = 1\n ", [this.explodedSchema.join(',')]),
])];

@@ -93,0 +93,0 @@ case 1:

@@ -68,3 +68,3 @@ "use strict";

return __awaiter(this, void 0, void 0, function () {
var tablesWithAutoIncrementPrimaryKeys, tables, overview, _i, tables_1, table, columns, _a, columns_1, column;
var tablesWithAutoIncrementPrimaryKeys, tables, overview, _i, tables_1, table, columns, primaryKeys, _a, columns_1, column;
return __generator(this, function (_b) {

@@ -91,4 +91,5 @@ switch (_b.label) {

if (table in overview === false) {
primaryKeys = columns.filter(function (column) { return column.pk !== 0; });
overview[table] = {
primary: columns.find(function (column) { return column.pk == 1; }).name,
primary: primaryKeys.length !== 1 ? undefined : primaryKeys[0].name,
columns: {},

@@ -95,0 +96,0 @@ };

{
"name": "@directus/schema",
"version": "9.0.1",
"version": "9.1.0",
"description": "Utility for extracting information about existing DB schema",

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

"npm-watch": "0.11.0",
"typescript": "4.4.4"
"typescript": "4.5.2"
},

@@ -53,3 +53,3 @@ "dependencies": {

},
"gitHead": "ba72d2cfd040f7f0db282ccac006f36df6f05058"
"gitHead": "7a1c534b36714a721b9f9df52d51f7f74ef1dada"
}

@@ -28,3 +28,4 @@ import KnexMSSQL, { parseDefaultValue } from 'knex-schema-inspector/dist/dialects/mssql';

CONSTRAINT_CATALOG,
COLUMN_NAME
COLUMN_NAME,
COUNT(*) OVER (PARTITION BY CONSTRAINT_NAME) as PK_COUNT
FROM [${this.knex.client.database()}].INFORMATION_SCHEMA.KEY_COLUMN_USAGE

@@ -35,2 +36,4 @@ ) as pk

AND [c].[COLUMN_NAME] = [pk].[COLUMN_NAME]
AND [pk].[PK_SET] = 'PRIMARY'
AND [pk].[PK_COUNT] = 1
INNER JOIN

@@ -37,0 +40,0 @@ [${this.knex.client.database()}].INFORMATION_SCHEMA.TABLES as t

@@ -33,6 +33,7 @@ import KnexMySQL, { parseDefaultValue } from 'knex-schema-inspector/dist/dialects/mysql';

if (column.table_name in overview === false) {
const primaryKeys = columns[0].filter((nested: { column_key: string; table_name: string }) => {
return nested.table_name === column.table_name && nested.column_key === 'PRI';
});
overview[column.table_name] = {
primary: columns[0].find((nested: { column_key: string; table_name: string }) => {
return nested.table_name === column.table_name && nested.column_key === 'PRI';
})?.column_name,
primary: primaryKeys.length !== 1 ? undefined : primaryKeys[0].column_name,
columns: {},

@@ -39,0 +40,0 @@ };

@@ -47,2 +47,5 @@ import KnexOracle from 'knex-schema-inspector/dist/dialects/oracledb';

/**
* NOTICE: This query is optimized for speed. Please keep this in mind.
*/
const columns = await this.knex.raw<RawColumn[]>(`

@@ -55,4 +58,12 @@ WITH "uc" AS (

FROM "USER_CONSTRAINTS" "uc"
INNER JOIN "USER_CONS_COLUMNS" "ucc" ON "uc"."CONSTRAINT_NAME" = "ucc"."CONSTRAINT_NAME"
WHERE "uc"."CONSTRAINT_TYPE" = 'P'
INNER JOIN (
SELECT
"COLUMN_NAME",
"CONSTRAINT_NAME",
COUNT(*) OVER(PARTITION BY "CONSTRAINT_NAME") "INDEX_COLUMN_COUNT"
FROM "USER_CONS_COLUMNS"
) "ucc"
ON "uc"."CONSTRAINT_NAME" = "ucc"."CONSTRAINT_NAME"
AND "uc"."CONSTRAINT_TYPE" = 'P'
AND "ucc"."INDEX_COLUMN_COUNT" = 1
)

@@ -71,3 +82,4 @@ SELECT

FROM "USER_TAB_COLS" "c"
LEFT JOIN "uc" "ct" ON "c"."TABLE_NAME" = "ct"."TABLE_NAME"
LEFT JOIN "uc" "ct"
ON "c"."TABLE_NAME" = "ct"."TABLE_NAME"
AND "c"."COLUMN_NAME" = "ct"."COLUMN_NAME"

@@ -74,0 +86,0 @@ WHERE "c"."HIDDEN_COLUMN" = 'NO'

@@ -64,2 +64,3 @@ import KnexPostgres, { parseDefaultValue } from 'knex-schema-inspector/dist/dialects/postgres';

AND indisprimary
AND indnkeyatts = 1
`,

@@ -66,0 +67,0 @@ [this.explodedSchema.join(',')]

@@ -31,4 +31,5 @@ import KnexSQLite from 'knex-schema-inspector/dist/dialects/sqlite';

if (table in overview === false) {
const primaryKeys = columns.filter((column) => column.pk !== 0);
overview[table] = {
primary: columns.find((column) => column.pk == 1)!.name!,
primary: primaryKeys.length !== 1 ? (undefined as any) : primaryKeys[0]!.name!,
columns: {},

@@ -35,0 +36,0 @@ };

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