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