@directus/schema
Advanced tools
Comparing version 9.0.0-rc.61 to 9.0.0-rc.62
@@ -95,3 +95,9 @@ "use strict"; | ||
} | ||
overview[column.table_name].columns[column.column_name] = __assign(__assign({}, column), { is_nullable: column.is_nullable === 'YES' }); | ||
/** | ||
* 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 }); | ||
}; | ||
@@ -98,0 +104,0 @@ for (_i = 0, columnsLowercase_1 = columnsLowercase; _i < columnsLowercase_1.length; _i++) { |
@@ -64,10 +64,9 @@ "use strict"; | ||
SQLite.prototype.overview = function () { | ||
var _a; | ||
return __awaiter(this, void 0, void 0, function () { | ||
var tablesWithAutoIncrementPrimaryKeys, tables, overview, _i, tables_1, table, columns, _b, columns_1, column; | ||
return __generator(this, function (_c) { | ||
switch (_c.label) { | ||
var tablesWithAutoIncrementPrimaryKeys, tables, overview, _i, tables_1, table, columns, _a, columns_1, column; | ||
return __generator(this, function (_b) { | ||
switch (_b.label) { | ||
case 0: return [4 /*yield*/, this.knex.select('name').from('sqlite_master').whereRaw("sql LIKE \"%AUTOINCREMENT%\"")]; | ||
case 1: | ||
tablesWithAutoIncrementPrimaryKeys = (_c.sent()).map(function (_a) { | ||
tablesWithAutoIncrementPrimaryKeys = (_b.sent()).map(function (_a) { | ||
var name = _a.name; | ||
@@ -78,6 +77,6 @@ return name; | ||
case 2: | ||
tables = _c.sent(); | ||
tables = _b.sent(); | ||
overview = {}; | ||
_i = 0, tables_1 = tables; | ||
_c.label = 3; | ||
_b.label = 3; | ||
case 3: | ||
@@ -88,11 +87,11 @@ if (!(_i < tables_1.length)) return [3 /*break*/, 6]; | ||
case 4: | ||
columns = _c.sent(); | ||
columns = _b.sent(); | ||
if (table in overview === false) { | ||
overview[table] = { | ||
primary: (_a = columns.find(function (column) { return column.pk == 1; })) === null || _a === void 0 ? void 0 : _a.name, | ||
primary: columns.find(function (column) { return column.pk == 1; }).name, | ||
columns: {}, | ||
}; | ||
} | ||
for (_b = 0, columns_1 = columns; _b < columns_1.length; _b++) { | ||
column = columns_1[_b]; | ||
for (_a = 0, columns_1 = columns; _a < columns_1.length; _a++) { | ||
column = columns_1[_a]; | ||
overview[table].columns[column.name] = { | ||
@@ -110,3 +109,3 @@ table_name: table, | ||
} | ||
_c.label = 5; | ||
_b.label = 5; | ||
case 5: | ||
@@ -113,0 +112,0 @@ _i++; |
{ | ||
"name": "@directus/schema", | ||
"version": "9.0.0-rc.61", | ||
"version": "9.0.0-rc.62", | ||
"description": "Utility for extracting information about existing DB schema", | ||
@@ -49,3 +49,3 @@ "main": "dist/index.js", | ||
}, | ||
"gitHead": "3e89bcc239a2e967e3d1811bbc274236c8398a00" | ||
"gitHead": "c653b167298289ff3540ba66b7516350a96f7ac5" | ||
} |
@@ -6,3 +6,3 @@ import KnexMySQL from 'knex-schema-inspector/dist/dialects/mysql'; | ||
export default class MySQL extends KnexMySQL implements SchemaInspector { | ||
async overview() { | ||
async overview(): Promise<SchemaOverview> { | ||
const columns = await this.knex.raw( | ||
@@ -9,0 +9,0 @@ ` |
@@ -7,3 +7,3 @@ import KnexOracle from 'knex-schema-inspector/dist/dialects/oracledb'; | ||
export default class Oracle extends KnexOracle implements SchemaInspector { | ||
async overview() { | ||
async overview(): Promise<SchemaOverview> { | ||
type RawColumn = { | ||
@@ -65,5 +65,13 @@ TABLE_NAME: string; | ||
/** | ||
* 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; | ||
overview[column.table_name].columns[column.column_name] = { | ||
...column, | ||
is_nullable: column.is_nullable === 'YES', | ||
is_nullable: column.is_nullable === 'Y', | ||
default_value: !column.default_value && isNumericPrimary ? 'AUTO_INCREMENT' : column.default_value, | ||
}; | ||
@@ -70,0 +78,0 @@ } |
@@ -6,3 +6,3 @@ import KnexPostgres from 'knex-schema-inspector/dist/dialects/postgres'; | ||
export default class Postgres extends KnexPostgres implements SchemaInspector { | ||
async overview() { | ||
async overview(): Promise<SchemaOverview> { | ||
const [columnsResult, primaryKeysResult] = await Promise.all([ | ||
@@ -9,0 +9,0 @@ // Only select columns from BASE TABLEs to exclude views (Postgres views |
@@ -15,3 +15,3 @@ import KnexSQLite from 'knex-schema-inspector/dist/dialects/sqlite'; | ||
export default class SQLite extends KnexSQLite implements SchemaInspector { | ||
async overview() { | ||
async overview(): Promise<SchemaOverview> { | ||
const tablesWithAutoIncrementPrimaryKeys = ( | ||
@@ -29,3 +29,3 @@ await this.knex.select('name').from('sqlite_master').whereRaw(`sql LIKE "%AUTOINCREMENT%"`) | ||
overview[table] = { | ||
primary: columns.find((column) => column.pk == 1)?.name!, | ||
primary: columns.find((column) => column.pk == 1)!.name!, | ||
columns: {}, | ||
@@ -32,0 +32,0 @@ }; |
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
90415
998