mirror of
https://github.com/directus/directus.git
synced 2026-01-21 05:48:02 -05:00
Detect autoincrement for CockroachDB
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { KNEX_TYPES } from '@directus/shared/constants';
|
||||
import { Field } from '@directus/shared/types';
|
||||
import { Options, SchemaHelper } from '../types';
|
||||
|
||||
export class SchemaHelperCockroachDb extends SchemaHelper {
|
||||
@@ -10,4 +11,15 @@ export class SchemaHelperCockroachDb extends SchemaHelper {
|
||||
): Promise<void> {
|
||||
await this.changeToTypeByCopy(table, column, type, options);
|
||||
}
|
||||
|
||||
processField(field: Field): void {
|
||||
if (
|
||||
field.schema?.default_value &&
|
||||
['integer', 'bigInteger'].includes(field.type) &&
|
||||
typeof field.schema.default_value === 'string' &&
|
||||
field.schema.default_value.startsWith('nextval(')
|
||||
) {
|
||||
field.schema.has_auto_increment = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { KNEX_TYPES } from '@directus/shared/constants';
|
||||
import { Field, Type } from '@directus/shared/types';
|
||||
import { Field } from '@directus/shared/types';
|
||||
import { Options, SchemaHelper } from '../types';
|
||||
|
||||
export class SchemaHelperOracle extends SchemaHelper {
|
||||
@@ -12,17 +12,15 @@ export class SchemaHelperOracle extends SchemaHelper {
|
||||
await this.changeToTypeByCopy(table, column, type, options);
|
||||
}
|
||||
|
||||
processFieldType(field: Field): Type {
|
||||
processField(field: Field): void {
|
||||
if (field.type === 'integer') {
|
||||
if (field.schema?.numeric_precision === 20) {
|
||||
return 'bigInteger';
|
||||
field.type = 'bigInteger';
|
||||
} else if (field.schema?.numeric_precision === 1) {
|
||||
return 'boolean';
|
||||
field.type = 'boolean';
|
||||
} else if (field.schema?.numeric_precision || field.schema?.numeric_scale) {
|
||||
return 'decimal';
|
||||
field.type = 'decimal';
|
||||
}
|
||||
}
|
||||
|
||||
return field.type;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { getDatabaseClient } from '../../index';
|
||||
import { DatabaseHelper } from '../types';
|
||||
import { KNEX_TYPES } from '@directus/shared/constants';
|
||||
import { Field, Type } from '@directus/shared/types';
|
||||
import { Field } from '@directus/shared/types';
|
||||
|
||||
type Clients = 'mysql' | 'postgres' | 'cockroachdb' | 'sqlite' | 'oracle' | 'mssql' | 'redshift';
|
||||
|
||||
@@ -92,7 +92,7 @@ export abstract class SchemaHelper extends DatabaseHelper {
|
||||
return;
|
||||
}
|
||||
|
||||
processFieldType(field: Field): Type {
|
||||
return field.type;
|
||||
processField(_field: Field): void {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -178,7 +178,7 @@ export class FieldsService {
|
||||
field.type = 'dateTime';
|
||||
}
|
||||
|
||||
field.type = this.helpers.schema.processFieldType(field);
|
||||
this.helpers.schema.processField(field);
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
Reference in New Issue
Block a user