@directus/schema
Advanced tools
Comparing version 9.0.0-rc.72 to 9.0.0-rc.73
@@ -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\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\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\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 1: | ||
@@ -101,0 +101,0 @@ columns = _b.sent(); |
@@ -96,3 +96,3 @@ "use strict"; | ||
switch (_c.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.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 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: | ||
@@ -110,3 +110,12 @@ columns = _c.sent(); | ||
} | ||
overview[column.table_name].columns[column.column_name] = __assign(__assign({}, column), { default_value: column.extra === 'auto_increment' ? 'AUTO_INCREMENT' : mysql_1.parseDefaultValue(column.default_value), is_nullable: column.is_nullable === 'YES', data_type: column.data_type.split('(')[0] }); | ||
var dataType = column.data_type.split('(')[0]; | ||
/** | ||
* Smooth out a difference between MySQL and MariaDB. MySQL reports the column type as `int | ||
* unsigned`, while MariaDB reports it as `int(11) unsigned`. This would cause the `unsigned` part | ||
* of the type to be dropped in the columnInfo retrieval for MariaDB powered databases. | ||
*/ | ||
if (column.data_type.includes('unsigned') && dataType.includes('unsigned') === false) { | ||
dataType += ' unsigned'; | ||
} | ||
overview[column.table_name].columns[column.column_name] = __assign(__assign({}, column), { default_value: column.extra === 'auto_increment' ? 'AUTO_INCREMENT' : mysql_1.parseDefaultValue(column.default_value), is_nullable: column.is_nullable === 'YES', data_type: dataType }); | ||
}; | ||
@@ -113,0 +122,0 @@ for (_i = 0, _b = columns[0]; _i < _b.length; _i++) { |
@@ -106,3 +106,3 @@ "use strict"; | ||
switch (_b.label) { | ||
case 0: return [4 /*yield*/, this.knex.raw("\n\t\t\tSELECT\n\t\t\t\t\"USER_TAB_COLUMNS\".\"TABLE_NAME\" AS TABLE_NAME,\n\t\t\t\t\"USER_TAB_COLUMNS\".\"COLUMN_NAME\" AS COLUMN_NAME,\n\t\t\t\t\"USER_TAB_COLUMNS\".\"DATA_DEFAULT\" AS DEFAULT_VALUE,\n\t\t\t\t\"USER_TAB_COLUMNS\".\"NULLABLE\" AS IS_NULLABLE,\n\t\t\t\t\"USER_TAB_COLUMNS\".\"DATA_TYPE\" AS DATA_TYPE,\n\t\t\t\t\"USER_TAB_COLUMNS\".\"DATA_PRECISION\" AS NUMERIC_PRECISION,\n\t\t\t\t\"USER_TAB_COLUMNS\".\"DATA_SCALE\" AS NUMERIC_SCALE,\n\t\t\t\t\"USER_CONSTRAINTS\".\"CONSTRAINT_TYPE\" AS COLUMN_KEY\n\t\t\tFROM\n\t\t\t\t\"USER_TAB_COLUMNS\"\n\t\t\t\tLEFT JOIN \"USER_CONS_COLUMNS\" ON \"USER_TAB_COLUMNS\".\"TABLE_NAME\" = \"USER_CONS_COLUMNS\".\"TABLE_NAME\"\n\t\t\t\t\tAND \"USER_TAB_COLUMNS\".\"COLUMN_NAME\" = \"USER_CONS_COLUMNS\".\"COLUMN_NAME\"\n\t\t\t\tLEFT JOIN \"USER_CONSTRAINTS\" ON \"USER_CONS_COLUMNS\".\"CONSTRAINT_NAME\" = \"USER_CONSTRAINTS\".\"CONSTRAINT_NAME\"\n\t\t")]; | ||
case 0: return [4 /*yield*/, this.knex.raw("\n\t\t\tSELECT\n\t\t\t\t\"USER_TAB_COLUMNS\".\"TABLE_NAME\" AS TABLE_NAME,\n\t\t\t\t\"USER_TAB_COLUMNS\".\"COLUMN_NAME\" AS COLUMN_NAME,\n\t\t\t\t\"USER_TAB_COLUMNS\".\"DATA_DEFAULT\" AS DEFAULT_VALUE,\n\t\t\t\t\"USER_TAB_COLUMNS\".\"NULLABLE\" AS IS_NULLABLE,\n\t\t\t\t\"USER_TAB_COLUMNS\".\"DATA_TYPE\" AS DATA_TYPE,\n\t\t\t\t\"USER_TAB_COLUMNS\".\"DATA_PRECISION\" AS NUMERIC_PRECISION,\n\t\t\t\t\"USER_TAB_COLUMNS\".\"DATA_SCALE\" AS NUMERIC_SCALE,\n\t\t\t\t\"USER_CONSTRAINTS\".\"CONSTRAINT_TYPE\" AS COLUMN_KEY,\n\t\t\t\t\"USER_TAB_COLUMNS\".\"CHAR_LENGTH\" as MAX_LENGTH\n\t\t\tFROM\n\t\t\t\t\"USER_TAB_COLUMNS\"\n\t\t\t\tLEFT JOIN \"USER_CONS_COLUMNS\" ON \"USER_TAB_COLUMNS\".\"TABLE_NAME\" = \"USER_CONS_COLUMNS\".\"TABLE_NAME\"\n\t\t\t\t\tAND \"USER_TAB_COLUMNS\".\"COLUMN_NAME\" = \"USER_CONS_COLUMNS\".\"COLUMN_NAME\"\n\t\t\t\tLEFT JOIN \"USER_CONSTRAINTS\" ON \"USER_CONS_COLUMNS\".\"CONSTRAINT_NAME\" = \"USER_CONSTRAINTS\".\"CONSTRAINT_NAME\"\n\t\t")]; | ||
case 1: | ||
@@ -109,0 +109,0 @@ columns = _b.sent(); |
@@ -99,3 +99,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 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 c.table_name,\n c.column_name,\n c.column_default as default_value,\n c.is_nullable,\n c.data_type,\n\t\t\t c.character_maximum_length as max_length,\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(',')]), | ||
@@ -102,0 +102,0 @@ ])]; |
@@ -58,2 +58,4 @@ "use strict"; | ||
var sqlite_1 = __importDefault(require("knex-schema-inspector/dist/dialects/sqlite")); | ||
var extract_max_length_1 = __importDefault(require("knex-schema-inspector/dist/utils/extract-max-length")); | ||
var extract_type_1 = __importDefault(require("knex-schema-inspector/dist/utils/extract-type")); | ||
var SQLite = /** @class */ (function (_super) { | ||
@@ -102,3 +104,4 @@ __extends(SQLite, _super); | ||
is_nullable: column.notnull == 0, | ||
data_type: column.type, | ||
data_type: extract_type_1.default(column.type), | ||
max_length: extract_max_length_1.default(column.type), | ||
numeric_precision: null, | ||
@@ -105,0 +108,0 @@ numeric_scale: null, |
@@ -13,2 +13,3 @@ export declare type SchemaOverview = { | ||
numeric_scale: number | null; | ||
max_length: number | null; | ||
}; | ||
@@ -15,0 +16,0 @@ }; |
{ | ||
"name": "@directus/schema", | ||
"version": "9.0.0-rc.72", | ||
"version": "9.0.0-rc.73", | ||
"description": "Utility for extracting information about existing DB schema", | ||
@@ -49,3 +49,3 @@ "main": "dist/index.js", | ||
}, | ||
"gitHead": "2f0099e0db2777ec29b5dc6a46f604f70870ec8e" | ||
"gitHead": "ce021e7b702268039ddbdaff434a3d2fba8f8d45" | ||
} |
@@ -17,2 +17,3 @@ import KnexMSSQL, { parseDefaultValue } from 'knex-schema-inspector/dist/dialects/mssql'; | ||
c.DATA_TYPE as data_type, | ||
c.CHARACTER_MAXIMUM_LENGTH as max_length, | ||
pk.PK_SET as column_key, | ||
@@ -19,0 +20,0 @@ COLUMNPROPERTY(OBJECT_ID(c.TABLE_SCHEMA + '.' + c.TABLE_NAME), c.COLUMN_NAME, 'IsIdentity') as is_identity |
@@ -16,2 +16,3 @@ import KnexMySQL, { parseDefaultValue } from 'knex-schema-inspector/dist/dialects/mysql'; | ||
C.COLUMN_KEY as column_key, | ||
C.CHARACTER_MAXIMUM_LENGTH as max_length, | ||
C.EXTRA as extra | ||
@@ -41,2 +42,13 @@ FROM | ||
let dataType = column.data_type.split('(')[0]; | ||
/** | ||
* Smooth out a difference between MySQL and MariaDB. MySQL reports the column type as `int | ||
* unsigned`, while MariaDB reports it as `int(11) unsigned`. This would cause the `unsigned` part | ||
* of the type to be dropped in the columnInfo retrieval for MariaDB powered databases. | ||
*/ | ||
if (column.data_type.includes('unsigned') && dataType.includes('unsigned') === false) { | ||
dataType += ' unsigned'; | ||
} | ||
overview[column.table_name].columns[column.column_name] = { | ||
@@ -46,3 +58,3 @@ ...column, | ||
is_nullable: column.is_nullable === 'YES', | ||
data_type: column.data_type.split('(')[0], | ||
data_type: dataType, | ||
}; | ||
@@ -49,0 +61,0 @@ } |
@@ -43,2 +43,3 @@ import KnexOracle from 'knex-schema-inspector/dist/dialects/oracledb'; | ||
COLUMN_KEY: string; | ||
MAX_LENGTH: number | null; | ||
}; | ||
@@ -55,2 +56,3 @@ | ||
column_key: string; | ||
max_length: number | null; | ||
}; | ||
@@ -67,3 +69,4 @@ | ||
"USER_TAB_COLUMNS"."DATA_SCALE" AS NUMERIC_SCALE, | ||
"USER_CONSTRAINTS"."CONSTRAINT_TYPE" AS COLUMN_KEY | ||
"USER_CONSTRAINTS"."CONSTRAINT_TYPE" AS COLUMN_KEY, | ||
"USER_TAB_COLUMNS"."CHAR_LENGTH" as MAX_LENGTH | ||
FROM | ||
@@ -70,0 +73,0 @@ "USER_TAB_COLUMNS" |
@@ -18,2 +18,3 @@ import KnexPostgres, { parseDefaultValue } from 'knex-schema-inspector/dist/dialects/postgres'; | ||
c.data_type, | ||
c.character_maximum_length as max_length, | ||
c.is_identity | ||
@@ -20,0 +21,0 @@ FROM |
import KnexSQLite from 'knex-schema-inspector/dist/dialects/sqlite'; | ||
import extractMaxLength from 'knex-schema-inspector/dist/utils/extract-max-length'; | ||
import extractType from 'knex-schema-inspector/dist/utils/extract-type'; | ||
import { SchemaOverview } from '../types/overview'; | ||
@@ -42,3 +44,4 @@ import { SchemaInspector } from '../types/schema'; | ||
is_nullable: column.notnull == 0, | ||
data_type: column.type, | ||
data_type: extractType(column.type), | ||
max_length: extractMaxLength(column.type), | ||
numeric_precision: null, | ||
@@ -45,0 +48,0 @@ numeric_scale: null, |
@@ -13,2 +13,3 @@ export type SchemaOverview = { | ||
numeric_scale: number | null; | ||
max_length: number | null; | ||
}; | ||
@@ -15,0 +16,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
97634
1132