mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-16 17:46:45 +00:00
fix(editor): Change the underlying data store db column types to support decimal numbers (#18549)
This commit is contained in:
@@ -9,7 +9,8 @@ export class Column {
|
||||
| 'json'
|
||||
| 'timestamptz'
|
||||
| 'timestamp'
|
||||
| 'uuid';
|
||||
| 'uuid'
|
||||
| 'double';
|
||||
|
||||
private isGenerated = false;
|
||||
|
||||
@@ -39,6 +40,11 @@ export class Column {
|
||||
return this;
|
||||
}
|
||||
|
||||
get double() {
|
||||
this.type = 'double';
|
||||
return this;
|
||||
}
|
||||
|
||||
varchar(length?: number) {
|
||||
this.type = 'varchar';
|
||||
this.length = length ?? 'auto';
|
||||
@@ -162,6 +168,14 @@ export class Column {
|
||||
if (isMysql) options.type = 'varchar(36)';
|
||||
// we haven't been defining length on "uuid" varchar on sqlite
|
||||
if (isSqlite) options.type = 'varchar';
|
||||
} else if (type === 'double') {
|
||||
if (isPostgres) {
|
||||
options.type = 'double precision';
|
||||
} else if (isMysql) {
|
||||
options.type = 'double';
|
||||
} else if (isSqlite) {
|
||||
options.type = 'real';
|
||||
}
|
||||
}
|
||||
|
||||
if (
|
||||
|
||||
@@ -2072,6 +2072,14 @@ describe('POST /projects/:projectId/data-stores/:dataStoreId/insert', () => {
|
||||
name: 'c',
|
||||
type: 'number',
|
||||
},
|
||||
{
|
||||
name: 'd',
|
||||
type: 'number',
|
||||
},
|
||||
{
|
||||
name: 'e',
|
||||
type: 'number',
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
@@ -2081,7 +2089,8 @@ describe('POST /projects/:projectId/data-stores/:dataStoreId/insert', () => {
|
||||
a: 1,
|
||||
b: 0,
|
||||
c: -1,
|
||||
// d: 0.2340439341231259,
|
||||
d: 0.2340439341231259,
|
||||
e: 2340439341231259,
|
||||
},
|
||||
],
|
||||
};
|
||||
@@ -2099,8 +2108,7 @@ describe('POST /projects/:projectId/data-stores/:dataStoreId/insert', () => {
|
||||
expect(readResponse.body.data.data[0]).toMatchObject(payload.data[0]);
|
||||
});
|
||||
|
||||
// eslint-disable-next-line n8n-local-rules/no-skipped-tests
|
||||
test.skip('should insert columns with null values', async () => {
|
||||
test('should insert columns with null values', async () => {
|
||||
const dataStore = await createDataStore(memberProject, {
|
||||
columns: [
|
||||
{
|
||||
|
||||
@@ -10,13 +10,40 @@ import {
|
||||
|
||||
describe('sql-utils', () => {
|
||||
describe('addColumnQuery', () => {
|
||||
it('should generate a valid SQL query for adding columns to a table', () => {
|
||||
it('should generate a valid SQL query for adding columns to a table, sqlite', () => {
|
||||
const tableName = 'data_store_user_abc';
|
||||
const column = { name: 'email', type: 'number' as const };
|
||||
|
||||
const query = addColumnQuery(tableName, column, 'sqlite');
|
||||
|
||||
expect(query).toBe('ALTER TABLE "data_store_user_abc" ADD "email" FLOAT');
|
||||
expect(query).toBe('ALTER TABLE "data_store_user_abc" ADD "email" REAL');
|
||||
});
|
||||
|
||||
it('should generate a valid SQL query for adding columns to a table, postgres', () => {
|
||||
const tableName = 'data_store_user_abc';
|
||||
const column = { name: 'email', type: 'number' as const };
|
||||
|
||||
const query = addColumnQuery(tableName, column, 'postgres');
|
||||
|
||||
expect(query).toBe('ALTER TABLE "data_store_user_abc" ADD "email" DOUBLE PRECISION');
|
||||
});
|
||||
|
||||
it('should generate a valid SQL query for adding columns to a table, mysql', () => {
|
||||
const tableName = 'data_store_user_abc';
|
||||
const column = { name: 'email', type: 'number' as const };
|
||||
|
||||
const query = addColumnQuery(tableName, column, 'mysql');
|
||||
|
||||
expect(query).toBe('ALTER TABLE `data_store_user_abc` ADD `email` DOUBLE');
|
||||
});
|
||||
|
||||
it('should generate a valid SQL query for adding columns to a table, mariadb', () => {
|
||||
const tableName = 'data_store_user_abc';
|
||||
const column = { name: 'email', type: 'number' as const };
|
||||
|
||||
const query = addColumnQuery(tableName, column, 'mariadb');
|
||||
|
||||
expect(query).toBe('ALTER TABLE `data_store_user_abc` ADD `email` DOUBLE');
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ export function toDslColumns(columns: DataStoreCreateColumnSchema[]): DslColumn[
|
||||
|
||||
switch (col.type) {
|
||||
case 'number':
|
||||
return name.int;
|
||||
return name.double;
|
||||
case 'boolean':
|
||||
return name.bool;
|
||||
case 'string':
|
||||
@@ -38,7 +38,17 @@ function dataStoreColumnTypeToSql(
|
||||
case 'string':
|
||||
return 'TEXT';
|
||||
case 'number':
|
||||
return 'FLOAT';
|
||||
switch (dbType) {
|
||||
case 'postgres':
|
||||
return 'DOUBLE PRECISION';
|
||||
case 'mysql':
|
||||
case 'mariadb':
|
||||
return 'DOUBLE';
|
||||
case 'sqlite':
|
||||
return 'REAL';
|
||||
default:
|
||||
return 'DOUBLE';
|
||||
}
|
||||
case 'boolean':
|
||||
return 'BOOLEAN';
|
||||
case 'date':
|
||||
|
||||
Reference in New Issue
Block a user