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.62 to 9.0.0-rc.63

5

dist/dialects/oracledb.d.ts
import KnexOracle from 'knex-schema-inspector/dist/dialects/oracledb';
import { Column } from 'knex-schema-inspector/dist/types/column';
import { SchemaOverview } from '../types/overview';
import { SchemaInspector } from '../types/schema';
export default class Oracle extends KnexOracle implements SchemaInspector {
private static _mapColumnAutoIncrement;
columnInfo(): Promise<Column[]>;
columnInfo(table: string): Promise<Column[]>;
columnInfo(table: string, column: string): Promise<Column>;
overview(): Promise<SchemaOverview>;
}

36

dist/dialects/oracledb.js

@@ -75,2 +75,27 @@ "use strict";

}
Oracle._mapColumnAutoIncrement = function (column) {
// Oracle doesn't support AUTO_INCREMENT. Assume all numeric primary
// keys without a default are AUTO_INCREMENT
var hasAutoIncrement = !column.default_value && column.data_type === 'NUMBER' && column.is_primary_key;
return __assign(__assign({}, column), { default_value: hasAutoIncrement ? 'AUTO_INCREMENT' : column.default_value, has_auto_increment: hasAutoIncrement });
};
Oracle.prototype.columnInfo = function (table, column) {
return __awaiter(this, void 0, void 0, function () {
var columnInfo_1, columnInfo;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
if (!column) return [3 /*break*/, 2];
return [4 /*yield*/, _super.prototype.columnInfo.call(this, table, column)];
case 1:
columnInfo_1 = _a.sent();
return [2 /*return*/, Oracle._mapColumnAutoIncrement(columnInfo_1)];
case 2: return [4 /*yield*/, _super.prototype.columnInfo.call(this, table)];
case 3:
columnInfo = _a.sent();
return [2 /*return*/, columnInfo.map(Oracle._mapColumnAutoIncrement)];
}
});
});
};
Oracle.prototype.overview = function () {

@@ -96,9 +121,6 @@ var _a;

}
/**
* Oracle doesn't return AUTO_INCREMENT. Incrementing is done using triggers, and there is no
* nice way to detect if a trigger is an increment trigger. For compatibility sake, assume all
* numeric primary keys AUTO_INCREMENT to prevent authorization throwing a "required value" error.
*/
var isNumericPrimary = column.data_type === 'NUMBER' && overview[column.table_name].primary;
overview[column.table_name].columns[column.column_name] = __assign(__assign({}, column), { is_nullable: column.is_nullable === 'Y', default_value: !column.default_value && isNumericPrimary ? 'AUTO_INCREMENT' : column.default_value });
// Oracle doesn't support AUTO_INCREMENT. Assume all numeric primary
// keys without a default are AUTO_INCREMENT
var hasAutoIncrement = !column.default_value && column.data_type === 'NUMBER' && column.column_key === 'P';
overview[column.table_name].columns[column.column_name] = __assign(__assign({}, column), { is_nullable: column.is_nullable === 'Y', default_value: hasAutoIncrement ? 'AUTO_INCREMENT' : column.default_value });
};

@@ -105,0 +127,0 @@ for (_i = 0, columnsLowercase_1 = columnsLowercase; _i < columnsLowercase_1.length; _i++) {

4

dist/dialects/postgres.js

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

// cannot have primary keys so they cannot be used)
this.knex.raw("\n SELECT\n c.table_name,\n c.column_name,\n c.column_default as default_value,\n c.is_nullable,\n c.data_type\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\n c.table_name,\n c.column_name,\n c.column_default as default_value,\n c.is_nullable,\n c.data_type,\n c.is_identity\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\n relname as table_name,\n pg_attribute.attname as column_name\n FROM\n 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(',')]),

@@ -98,3 +98,3 @@ ])];

};
overview[column.table_name].columns[column.column_name] = __assign(__assign({}, column), { default_value: ((_b = column.default_value) === null || _b === void 0 ? void 0 : _b.startsWith('nextval('))
overview[column.table_name].columns[column.column_name] = __assign(__assign({}, column), { default_value: column.is_identity === 'YES' || ((_b = column.default_value) === null || _b === void 0 ? void 0 : _b.startsWith('nextval('))
? 'AUTO_INCREMENT'

@@ -101,0 +101,0 @@ : this_1.parseDefaultValue(column.default_value), is_nullable: column.is_nullable === 'YES' });

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

@@ -42,10 +42,10 @@ "main": "dist/index.js",

"devDependencies": {
"npm-watch": "^0.7.0",
"npm-watch": "^0.9.0",
"typescript": "^4.0.5"
},
"dependencies": {
"knex-schema-inspector": "^1.2.0",
"knex-schema-inspector": "^1.3.0",
"lodash": "^4.17.21"
},
"gitHead": "c653b167298289ff3540ba66b7516350a96f7ac5"
"gitHead": "5df6696bc029902b57eb5eb118c6fc39960937ef"
}

@@ -14,10 +14,10 @@ # @directus/schema

const database = knex({
client: 'mysql',
connection: {
host: '127.0.0.1',
user: 'your_database_user',
password: 'your_database_password',
database: 'myapp_test',
charset: 'utf8',
},
client: 'mysql',
connection: {
host: '127.0.0.1',
user: 'your_database_user',
password: 'your_database_password',
database: 'myapp_test',
charset: 'utf8',
},
});

@@ -36,4 +36,4 @@

async function logTables() {
const tables = await inspector.tables();
console.log(tables);
const tables = await inspector.tables();
console.log(tables);
}

@@ -46,3 +46,4 @@ ```

Note 2: Some database types might return slightly more information than others. See the type files for a specific overview what to expect from driver to driver.
Note 2: Some database types might return slightly more information than others. See the type files for a specific
overview what to expect from driver to driver.

@@ -49,0 +50,0 @@ Note 3: MSSQL doesn't support comment for either tables or columns

import KnexOracle from 'knex-schema-inspector/dist/dialects/oracledb';
import { Column } from 'knex-schema-inspector/dist/types/column';
import { SchemaOverview } from '../types/overview';

@@ -7,2 +8,27 @@ import { SchemaInspector } from '../types/schema';

export default class Oracle extends KnexOracle implements SchemaInspector {
private static _mapColumnAutoIncrement(column: Column): Column {
// Oracle doesn't support AUTO_INCREMENT. Assume all numeric primary
// keys without a default are AUTO_INCREMENT
const hasAutoIncrement = !column.default_value && column.data_type === 'NUMBER' && column.is_primary_key;
return {
...column,
default_value: hasAutoIncrement ? 'AUTO_INCREMENT' : column.default_value,
has_auto_increment: hasAutoIncrement,
};
}
columnInfo(): Promise<Column[]>;
columnInfo(table: string): Promise<Column[]>;
columnInfo(table: string, column: string): Promise<Column>;
async columnInfo(table?: string, column?: string): Promise<Column | Column[]> {
if (column) {
const columnInfo: Column = await super.columnInfo(table!, column!);
return Oracle._mapColumnAutoIncrement(columnInfo);
}
const columnInfo: Column[] = await super.columnInfo(table!);
return columnInfo.map(Oracle._mapColumnAutoIncrement);
}
async overview(): Promise<SchemaOverview> {

@@ -65,8 +91,5 @@ type RawColumn = {

/**
* Oracle doesn't return AUTO_INCREMENT. Incrementing is done using triggers, and there is no
* nice way to detect if a trigger is an increment trigger. For compatibility sake, assume all
* numeric primary keys AUTO_INCREMENT to prevent authorization throwing a "required value" error.
*/
const isNumericPrimary = column.data_type === 'NUMBER' && overview[column.table_name].primary;
// Oracle doesn't support AUTO_INCREMENT. Assume all numeric primary
// keys without a default are AUTO_INCREMENT
const hasAutoIncrement = !column.default_value && column.data_type === 'NUMBER' && column.column_key === 'P';

@@ -76,3 +99,3 @@ overview[column.table_name].columns[column.column_name] = {

is_nullable: column.is_nullable === 'Y',
default_value: !column.default_value && isNumericPrimary ? 'AUTO_INCREMENT' : column.default_value,
default_value: hasAutoIncrement ? 'AUTO_INCREMENT' : column.default_value,
};

@@ -79,0 +102,0 @@ }

@@ -17,3 +17,4 @@ import KnexPostgres from 'knex-schema-inspector/dist/dialects/postgres';

c.is_nullable,
c.data_type
c.data_type,
c.is_identity
FROM

@@ -68,5 +69,6 @@ information_schema.columns c

...column,
default_value: column.default_value?.startsWith('nextval(')
? 'AUTO_INCREMENT'
: this.parseDefaultValue(column.default_value),
default_value:
column.is_identity === 'YES' || column.default_value?.startsWith('nextval(')
? 'AUTO_INCREMENT'
: this.parseDefaultValue(column.default_value),
is_nullable: column.is_nullable === 'YES',

@@ -73,0 +75,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