Skip to content

Commit

Permalink
Fixed an issue that would cause "text" fields to show up as varchar w…
Browse files Browse the repository at this point in the history
…ith length -1 in MS SQL (directus#6055)

Fixes directus#5944
  • Loading branch information
rijkvanzanten authored Jun 4, 2021
1 parent babe6cd commit 85d33d9
Show file tree
Hide file tree
Showing 10 changed files with 63 additions and 48 deletions.
5 changes: 5 additions & 0 deletions api/src/utils/get-local-type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,11 @@ export default function getLocalType(
return 'decimal';
}

/** Handle MS SQL varchar(MAX) (eg TEXT) types */
if (column.data_type === 'nvarchar' && column.max_length === -1) {
return 'text';
}

if (field?.special?.includes('json')) return 'json';
if (field?.special?.includes('hash')) return 'hash';
if (field?.special?.includes('csv')) return 'csv';
Expand Down
2 changes: 1 addition & 1 deletion app/src/stores/collections.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export const useCollectionsStore = createStore({
this.translateCollections();
},
translateCollections() {
this.state.collections = this.state.collections.map((collection: CollectionRaw) => {
this.state.collections = this.state.collections.map((collection: Collection) => {
let name: string | VueI18n.TranslateResult;

if (i18n.te(`collection_names.${collection.collection}`)) {
Expand Down
2 changes: 1 addition & 1 deletion app/src/types/collections.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,5 @@ export interface CollectionRaw {
export interface Collection extends CollectionRaw {
name: string | VueI18n.TranslateResult;
icon: string;
color: string | null;
color?: string | null;
}
88 changes: 44 additions & 44 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/schema/src/dialects/mssql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export default class MSSQL extends KnexMSSQL implements SchemaInspector {
c.COLUMN_DEFAULT as default_value,
c.IS_NULLABLE as is_nullable,
c.DATA_TYPE as data_type,
c.CHARACTER_MAXIMUM_LENGTH as max_length,
pk.PK_SET as column_key,
COLUMNPROPERTY(OBJECT_ID(c.TABLE_SCHEMA + '.' + c.TABLE_NAME), c.COLUMN_NAME, 'IsIdentity') as is_identity
FROM
Expand Down
1 change: 1 addition & 0 deletions packages/schema/src/dialects/mysql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export default class MySQL extends KnexMySQL implements SchemaInspector {
C.IS_NULLABLE as is_nullable,
C.COLUMN_TYPE as data_type,
C.COLUMN_KEY as column_key,
C.CHARACTER_MAXIMUM_LENGTH as max_length,
C.EXTRA as extra
FROM
INFORMATION_SCHEMA.COLUMNS AS C
Expand Down
5 changes: 4 additions & 1 deletion packages/schema/src/dialects/oracledb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export default class Oracle extends KnexOracle implements SchemaInspector {
NUMERIC_PRECISION: number | null;
NUMERIC_SCALE: number | null;
COLUMN_KEY: string;
MAX_LENGTH: number | null;
};

type RawColumnLowercase = {
Expand All @@ -51,6 +52,7 @@ export default class Oracle extends KnexOracle implements SchemaInspector {
numeric_precision: number | null;
numeric_scale: number | null;
column_key: string;
max_length: number | null;
};

const columns = await this.knex.raw<RawColumn[]>(`
Expand All @@ -62,7 +64,8 @@ export default class Oracle extends KnexOracle implements SchemaInspector {
"USER_TAB_COLUMNS"."DATA_TYPE" AS DATA_TYPE,
"USER_TAB_COLUMNS"."DATA_PRECISION" AS NUMERIC_PRECISION,
"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
"USER_TAB_COLUMNS"
LEFT JOIN "USER_CONS_COLUMNS" ON "USER_TAB_COLUMNS"."TABLE_NAME" = "USER_CONS_COLUMNS"."TABLE_NAME"
Expand Down
1 change: 1 addition & 0 deletions packages/schema/src/dialects/postgres.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export default class Postgres extends KnexPostgres implements SchemaInspector {
c.column_default as default_value,
c.is_nullable,
c.data_type,
c.character_maximum_length as max_length,
c.is_identity
FROM
information_schema.columns c
Expand Down
5 changes: 4 additions & 1 deletion packages/schema/src/dialects/sqlite.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import KnexSQLite from 'knex-schema-inspector/dist/dialects/sqlite';
import extractMaxLength from 'knex-schema-inspector/lib/utils/extract-max-length';
import extractType from 'knex-schema-inspector/lib/utils/extract-type';
import { SchemaOverview } from '../types/overview';
import { SchemaInspector } from '../types/schema';

Expand Down Expand Up @@ -39,7 +41,8 @@ export default class SQLite extends KnexSQLite implements SchemaInspector {
? 'AUTO_INCREMENT'
: column.dflt_value,
is_nullable: column.notnull == 0,
data_type: column.type,
data_type: extractType(column.type),
max_length: extractMaxLength(column.type),
numeric_precision: null,
numeric_scale: null,
};
Expand Down
1 change: 1 addition & 0 deletions packages/schema/src/types/overview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export type SchemaOverview = {
data_type: string;
numeric_precision: number | null;
numeric_scale: number | null;
max_length: number | null;
};
};
};
Expand Down

0 comments on commit 85d33d9

Please sign in to comment.