Skip to content

πŸ”₯ πŸ”₯ πŸ”₯ A Free & Self-hostable Airtable Alternative

feat: enhance table creation with virtual column support and update schema

Pranav C728bd6c38348
diff --git a/packages/nocodb/src/schema/swagger-v3.json b/packages/nocodb/src/schema/swagger-v3.json
index 7d2408e89d..e5a729956d 100644
--- a/packages/nocodb/src/schema/swagger-v3.json
+++ b/packages/nocodb/src/schema/swagger-v3.json
@@ -6333,32 +6333,6 @@
}
}
},
- "Lookup": {
- "title": "Lookup",
- "properties": {
- "type": {
- "enum": [
- "Lookup"
- ]
- },
- "options": {
- "$ref": "#/components/schemas/FieldOptions_Lookup"
- }
- }
- },
- "Rollup": {
- "title": "Rollup",
- "properties": {
- "type": {
- "enum": [
- "Rollup"
- ]
- },
- "options": {
- "$ref": "#/components/schemas/FieldOptions_Rollup"
- }
- }
- },
"Button": {
"title": "Button",
"properties": {
@@ -6385,19 +6359,6 @@
}
}
},
- "Barcode": {
- "title": "Barcode",
- "properties": {
- "type": {
- "enum": [
- "Barcode"
- ]
- },
- "options": {
- "$ref": "#/components/schemas/FieldOptions_Barcode"
- }
- }
- },
"Year": {
"title": "Year",
"properties": {
@@ -6408,19 +6369,6 @@
}
}
},
- "QrCode": {
- "title": "QrCode",
- "properties": {
- "type": {
- "enum": [
- "QrCode"
- ]
- },
- "options": {
- "$ref": "#/components/schemas/FieldOptions_QrCode"
- }
- }
- },
"CreatedTime": {
"title": "CreatedTime",
"properties": {
@@ -6574,24 +6522,12 @@
{
"$ref": "#/components/schemas/FieldOptions/Links"
},
- {
- "$ref": "#/components/schemas/FieldOptions/Lookup"
- },
- {
- "$ref": "#/components/schemas/FieldOptions/Rollup"
- },
{
"$ref": "#/components/schemas/FieldOptions/Button"
},
{
"$ref": "#/components/schemas/FieldOptions/Formula"
},
- {
- "$ref": "#/components/schemas/FieldOptions/Barcode"
- },
- {
- "$ref": "#/components/schemas/FieldOptions/QrCode"
- },
{
"$ref": "#/components/schemas/FieldOptions/CreatedTime"
},
@@ -7958,6 +7894,44 @@
"allOf": [
{
"$ref": "#/components/schemas/FieldBase"
+ }, {
+ "type": "object",
+ "properties": {
+ "type": "string",
+ "enum": [
+ "SingleLineText",
+ "LongText",
+ "PhoneNumber",
+ "URL",
+ "Email",
+ "Number",
+ "Decimal",
+ "Currency",
+ "Percent",
+ "Duration",
+ "Date",
+ "DateTime",
+ "Time",
+ "SingleSelect",
+ "MultiSelect",
+ "Rating",
+ "Checkbox",
+ "Attachment",
+ "Geometry",
+ "Links",
+ "LinkToAnotherRecord",
+ "Button",
+ "Formula",
+ "Year",
+ "CreatedTime",
+ "LastModifiedTime",
+ "CreatedBy",
+ "LastModifiedBy",
+ "User",
+ "JSON"
+ ],
+ "description": "Field data type."
+ }
},
{
"required": [
diff --git a/packages/nocodb/src/services/v3/tables-v3.service.ts b/packages/nocodb/src/services/v3/tables-v3.service.ts
index 57eaec61af..37a1141bc6 100644
--- a/packages/nocodb/src/services/v3/tables-v3.service.ts
+++ b/packages/nocodb/src/services/v3/tables-v3.service.ts
@@ -1,6 +1,7 @@
import { Injectable, Logger } from '@nestjs/common';
-import { NcApiVersion, UITypes } from 'nocodb-sdk';
+import { isLinksOrLTAR, NcApiVersion, UITypes } from 'nocodb-sdk';
import type {
+ FieldV3Type,
TableCreateV3Type,
TableReqType,
TableUpdateV3Type,
@@ -20,6 +21,7 @@ import {
import { TablesService } from '~/services/tables.service';
import { tableReadBuilder, tableViewBuilder } from '~/utils/builders/table';
import { validatePayload } from '~/helpers';
+import { ColumnsV3Service } from '~/services/v3/columns-v3.service';
@Injectable()
export class TablesV3Service {
@@ -30,6 +32,7 @@ export class TablesV3Service {
protected readonly appHooksService: AppHooksService,
protected readonly columnsService: ColumnsService,
protected readonly tablesService: TablesService,
+ protected readonly columnsV3Service: ColumnsV3Service,
) {}
async tableUpdate(
@@ -159,6 +162,10 @@ export class TablesV3Service {
true,
context,
);
+
+ const columns = [];
+ const virtualColumns = [];
+
for (const field of param.table.fields ?? []) {
validatePayload(
`swagger-v3.json#/components/schemas/FieldOptions/${field.type}`,
@@ -166,15 +173,19 @@ export class TablesV3Service {
true,
context,
);
+
+ if (isLinksOrLTAR(field.type)) {
+ virtualColumns.push(field);
+ } else {
+ columns.push(field);
+ }
}
const tableCreateReq: any = param.table;
// remap the columns if provided
- if (tableCreateReq.fields) {
- tableCreateReq.columns = columnV3ToV2Builder().build(
- tableCreateReq.fields,
- );
+ if (columns.length) {
+ tableCreateReq.columns = columnV3ToV2Builder().build(columns);
} else {
tableCreateReq.columns = [];
}
@@ -188,6 +199,16 @@ export class TablesV3Service {
sourceId: param.sourceId,
});
+ // create virtual columns after table creation
+ for (const vCol of virtualColumns) {
+ await this.columnsV3Service.columnAdd(context, {
+ tableId: tableCreateOutput.id,
+ column: vCol as FieldV3Type,
+ req: param.req as NcRequest,
+ user: param.user! as UserType,
+ });
+ }
+
return this.getTableWithAccessibleViews(context, {
tableId: tableCreateOutput.id,
user: param.user,