π₯ π₯ π₯ A Free & Self-hostable Airtable Alternative
TypeScript airtableairtable-alternativeautomatic-apihacktoberfestlow-codeno-codeno-code-databaseno-code-platformpostgresqlrest-apirestful-apispreadsheetsqliteswagger
WIP
Fendy Heryanto511aa5016faf
diff --git a/packages/nocodb/src/helpers/columnHelpers.ts b/packages/nocodb/src/helpers/columnHelpers.tsindex 37fb4753d0..30778668e4 100644--- a/packages/nocodb/src/helpers/columnHelpers.ts+++ b/packages/nocodb/src/helpers/columnHelpers.ts@@ -645,3 +645,42 @@ export const getMMColumnNames = (parent: Model, child: Model) => {childCn,};};++export const TableSystemColumns = () => [+ {+ column_name: 'id',+ title: 'Id',+ uidt: 'ID',+ allowNonSystem: false,+ },+ {+ column_name: 'created_at',+ title: 'CreatedAt',+ uidt: 'CreatedTime',+ allowNonSystem: true,+ },+ {+ column_name: 'updated_at',+ title: 'UpdatedAt',+ uidt: 'LastModifiedTime',+ allowNonSystem: true,+ },+ {+ column_name: 'created_by',+ title: 'nc_created_by',+ uidt: 'CreatedBy',+ allowNonSystem: true,+ },+ {+ column_name: 'updated_by',+ title: 'nc_updated_by',+ uidt: 'LastModifiedBy',+ allowNonSystem: true,+ },+ {+ column_name: 'nc_order',+ title: 'nc_order',+ uidt: 'Order',+ allowNonSystem: false,+ },+];diff --git a/packages/nocodb/src/helpers/tableHelpers.ts b/packages/nocodb/src/helpers/tableHelpers.tsnew file mode 100644index 0000000000..c9879195d0--- /dev/null+++ b/packages/nocodb/src/helpers/tableHelpers.ts@@ -0,0 +1,54 @@+import { TableSystemColumns } from './columnHelpers';+import { NcError } from './ncError';+import type { ColumnType, NcContext, UITypes } from 'nocodb-sdk';++export const verifyCreateTableSystemColumns = (+ context: NcContext,+ { columns }: { columns: ColumnType[] },+) => {+ const columnNameMap = new Map<string, ColumnType>();+ const titleMap = new Map<string, ColumnType>();+ const addingColumn = [];++ const addSystemColumn = (col) => {+ const [allowNonSystem, ...colToAdd] = col;+ addingColumn.push(colToAdd);+ };++ for (const systemColumn of TableSystemColumns()) {+ const existingColumns = columns.filter(+ (col) =>+ col.title === systemColumn.title ||+ col.column_name === systemColumn.column_name ||+ col.uidt === systemColumn.column_name,+ );+ if (existingColumns.length > 1 && !systemColumn.allowNonSystem) {+ NcError.get(context).invalidRequestBody(+ `Column with type ` + systemColumn.uidt + ` is only 1 allowed`,+ );+ }+ if (existingColumns.length) {+ const existingColumn = existingColumns[0];+ const isMatch =+ existingColumn.title === systemColumn.title &&+ existingColumn.column_name === systemColumn.column_name &&+ existingColumn.uidt === systemColumn.column_name;++ if (!isMatch && !systemColumn.allowNonSystem) {+ const identifier = systemColumn.title+ ? `title '` + systemColumn.title + `'`+ : systemColumn.column_name+ ? `column_name '` + systemColumn.column_name + `'`+ : `type '` + systemColumn.uidt + `'`;+ NcError.get(context).invalidRequestBody(+ `Column with ${identifier} does not meet specification`,+ );+ } else if (!isMatch && systemColumn.allowNonSystem) {+ addSystemColumn(systemColumn);+ } else {+ }+ } else {+ addSystemColumn(systemColumn);+ }+ }+};