Merge pull request #13500 from Budibase/budi-8126/remove-addcolumn-api-param
Remove addcolumn api param
This commit is contained in:
commit
3b29c9a7ad
|
@ -42,7 +42,15 @@
|
||||||
},
|
},
|
||||||
"rules": {
|
"rules": {
|
||||||
"no-unused-vars": "off",
|
"no-unused-vars": "off",
|
||||||
"@typescript-eslint/no-unused-vars": "error",
|
"@typescript-eslint/no-unused-vars": [
|
||||||
|
"error",
|
||||||
|
{
|
||||||
|
"varsIgnorePattern": "^_",
|
||||||
|
"argsIgnorePattern": "^_",
|
||||||
|
"destructuredArrayIgnorePattern": "^_",
|
||||||
|
"ignoreRestSiblings": true
|
||||||
|
}
|
||||||
|
],
|
||||||
"local-rules/no-budibase-imports": "error"
|
"local-rules/no-budibase-imports": "error"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -59,7 +67,15 @@
|
||||||
},
|
},
|
||||||
"rules": {
|
"rules": {
|
||||||
"no-unused-vars": "off",
|
"no-unused-vars": "off",
|
||||||
"@typescript-eslint/no-unused-vars": "error",
|
"@typescript-eslint/no-unused-vars": [
|
||||||
|
"error",
|
||||||
|
{
|
||||||
|
"varsIgnorePattern": "^_",
|
||||||
|
"argsIgnorePattern": "^_",
|
||||||
|
"destructuredArrayIgnorePattern": "^_",
|
||||||
|
"ignoreRestSiblings": true
|
||||||
|
}
|
||||||
|
],
|
||||||
"local-rules/no-test-com": "error",
|
"local-rules/no-test-com": "error",
|
||||||
"local-rules/email-domain-example-com": "error",
|
"local-rules/email-domain-example-com": "error",
|
||||||
"no-console": "warn",
|
"no-console": "warn",
|
||||||
|
@ -89,7 +105,8 @@
|
||||||
{
|
{
|
||||||
"varsIgnorePattern": "^_",
|
"varsIgnorePattern": "^_",
|
||||||
"argsIgnorePattern": "^_",
|
"argsIgnorePattern": "^_",
|
||||||
"destructuredArrayIgnorePattern": "^_"
|
"destructuredArrayIgnorePattern": "^_",
|
||||||
|
"ignoreRestSiblings": true
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"import/no-relative-packages": "error",
|
"import/no-relative-packages": "error",
|
||||||
|
|
|
@ -148,12 +148,6 @@ export function createTablesStore() {
|
||||||
if (indexes) {
|
if (indexes) {
|
||||||
draft.indexes = indexes
|
draft.indexes = indexes
|
||||||
}
|
}
|
||||||
// Add object to indicate if column is being added
|
|
||||||
if (draft.schema[field.name] === undefined) {
|
|
||||||
draft._add = {
|
|
||||||
name: field.name,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
draft.schema = {
|
draft.schema = {
|
||||||
...draft.schema,
|
...draft.schema,
|
||||||
[field.name]: cloneDeep(field),
|
[field.name]: cloneDeep(field),
|
||||||
|
|
|
@ -31,7 +31,6 @@ export async function save(
|
||||||
renaming?: RenameColumn
|
renaming?: RenameColumn
|
||||||
) {
|
) {
|
||||||
const inputs = ctx.request.body
|
const inputs = ctx.request.body
|
||||||
const adding = inputs?._add
|
|
||||||
// can't do this right now
|
// can't do this right now
|
||||||
delete inputs.rows
|
delete inputs.rows
|
||||||
const tableId = ctx.request.body._id
|
const tableId = ctx.request.body._id
|
||||||
|
@ -44,7 +43,7 @@ export async function save(
|
||||||
const { datasource, table } = await sdk.tables.external.save(
|
const { datasource, table } = await sdk.tables.external.save(
|
||||||
datasourceId!,
|
datasourceId!,
|
||||||
inputs,
|
inputs,
|
||||||
{ tableId, renaming, adding }
|
{ tableId, renaming }
|
||||||
)
|
)
|
||||||
builderSocket?.emitDatasourceUpdate(ctx, datasource)
|
builderSocket?.emitDatasourceUpdate(ctx, datasource)
|
||||||
return table
|
return table
|
||||||
|
|
|
@ -77,11 +77,6 @@ export async function save(ctx: UserCtx<SaveTableRequest, SaveTableResponse>) {
|
||||||
const renaming = ctx.request.body._rename
|
const renaming = ctx.request.body._rename
|
||||||
|
|
||||||
const api = pickApi({ table })
|
const api = pickApi({ table })
|
||||||
// do not pass _rename or _add if saving to CouchDB
|
|
||||||
if (api === internal) {
|
|
||||||
delete ctx.request.body._add
|
|
||||||
delete ctx.request.body._rename
|
|
||||||
}
|
|
||||||
let savedTable = await api.save(ctx, renaming)
|
let savedTable = await api.save(ctx, renaming)
|
||||||
if (!table._id) {
|
if (!table._id) {
|
||||||
savedTable = sdk.tables.enrichViewSchemas(savedTable)
|
savedTable = sdk.tables.enrichViewSchemas(savedTable)
|
||||||
|
|
|
@ -16,7 +16,7 @@ export async function save(
|
||||||
ctx: UserCtx<SaveTableRequest, SaveTableResponse>,
|
ctx: UserCtx<SaveTableRequest, SaveTableResponse>,
|
||||||
renaming?: RenameColumn
|
renaming?: RenameColumn
|
||||||
) {
|
) {
|
||||||
const { rows, ...rest } = ctx.request.body
|
const { _rename, rows, ...rest } = ctx.request.body
|
||||||
let tableToSave: Table = {
|
let tableToSave: Table = {
|
||||||
_id: generateTableID(),
|
_id: generateTableID(),
|
||||||
...rest,
|
...rest,
|
||||||
|
|
|
@ -219,9 +219,6 @@ describe.each([
|
||||||
|
|
||||||
it("should add a new column for an internal DB table", async () => {
|
it("should add a new column for an internal DB table", async () => {
|
||||||
const saveTableRequest: SaveTableRequest = {
|
const saveTableRequest: SaveTableRequest = {
|
||||||
_add: {
|
|
||||||
name: "NEW_COLUMN",
|
|
||||||
},
|
|
||||||
...basicTable(),
|
...basicTable(),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -235,7 +232,6 @@ describe.each([
|
||||||
updatedAt: expect.stringMatching(ISO_REGEX_PATTERN),
|
updatedAt: expect.stringMatching(ISO_REGEX_PATTERN),
|
||||||
views: {},
|
views: {},
|
||||||
}
|
}
|
||||||
delete expectedResponse._add
|
|
||||||
expect(response).toEqual(expectedResponse)
|
expect(response).toEqual(expectedResponse)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
@ -255,9 +255,6 @@ describe("mysql integrations", () => {
|
||||||
name: "new_column",
|
name: "new_column",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
_add: {
|
|
||||||
name: "new_column",
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
jest
|
jest
|
||||||
|
@ -273,25 +270,18 @@ describe("mysql integrations", () => {
|
||||||
type: FieldType.NUMBER,
|
type: FieldType.NUMBER,
|
||||||
name: "id",
|
name: "id",
|
||||||
autocolumn: true,
|
autocolumn: true,
|
||||||
constraints: {
|
|
||||||
presence: false,
|
|
||||||
},
|
|
||||||
externalType: "int unsigned",
|
externalType: "int unsigned",
|
||||||
},
|
},
|
||||||
new_column: {
|
new_column: {
|
||||||
type: FieldType.NUMBER,
|
type: FieldType.NUMBER,
|
||||||
name: "new_column",
|
name: "new_column",
|
||||||
autocolumn: false,
|
autocolumn: false,
|
||||||
constraints: {
|
|
||||||
presence: false,
|
|
||||||
},
|
|
||||||
externalType: "float(8,2)",
|
externalType: "float(8,2)",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
created: true,
|
created: true,
|
||||||
_id: `${datasource._id}__${addColumnToTable.name}`,
|
_id: `${datasource._id}__${addColumnToTable.name}`,
|
||||||
}
|
}
|
||||||
delete expectedTable._add
|
|
||||||
|
|
||||||
expect(emitDatasourceUpdateMock).toHaveBeenCalledTimes(1)
|
expect(emitDatasourceUpdateMock).toHaveBeenCalledTimes(1)
|
||||||
const emittedDatasource: Datasource =
|
const emittedDatasource: Datasource =
|
||||||
|
|
|
@ -380,7 +380,12 @@ function copyExistingPropsOver(
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
table.schema[key] = existingTableSchema[key]
|
table.schema[key] = {
|
||||||
|
...existingTableSchema[key],
|
||||||
|
externalType:
|
||||||
|
existingTableSchema[key].externalType ||
|
||||||
|
table.schema[key].externalType,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return table
|
return table
|
||||||
|
|
|
@ -348,8 +348,7 @@ const preSaveAction: Partial<Record<SourceName, any>> = {
|
||||||
* Make sure all datasource entities have a display name selected
|
* Make sure all datasource entities have a display name selected
|
||||||
*/
|
*/
|
||||||
export function setDefaultDisplayColumns(datasource: Datasource) {
|
export function setDefaultDisplayColumns(datasource: Datasource) {
|
||||||
//
|
for (const entity of Object.values(datasource.entities || {})) {
|
||||||
for (let entity of Object.values(datasource.entities || {})) {
|
|
||||||
if (entity.primaryDisplay) {
|
if (entity.primaryDisplay) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,6 @@ import {
|
||||||
Operation,
|
Operation,
|
||||||
RelationshipType,
|
RelationshipType,
|
||||||
RenameColumn,
|
RenameColumn,
|
||||||
AddColumn,
|
|
||||||
Table,
|
Table,
|
||||||
TableRequest,
|
TableRequest,
|
||||||
ViewV2,
|
ViewV2,
|
||||||
|
@ -33,7 +32,7 @@ import * as viewSdk from "../../views"
|
||||||
export async function save(
|
export async function save(
|
||||||
datasourceId: string,
|
datasourceId: string,
|
||||||
update: Table,
|
update: Table,
|
||||||
opts?: { tableId?: string; renaming?: RenameColumn; adding?: AddColumn }
|
opts?: { tableId?: string; renaming?: RenameColumn }
|
||||||
) {
|
) {
|
||||||
let tableToSave: TableRequest = {
|
let tableToSave: TableRequest = {
|
||||||
...update,
|
...update,
|
||||||
|
@ -179,14 +178,7 @@ export async function save(
|
||||||
// remove the rename prop
|
// remove the rename prop
|
||||||
delete tableToSave._rename
|
delete tableToSave._rename
|
||||||
|
|
||||||
// if adding a new column, we need to rebuild the schema for that table to get the 'externalType' of the column
|
|
||||||
if (opts?.adding) {
|
|
||||||
datasource.entities[tableToSave.name] = (
|
|
||||||
await datasourceSdk.buildFilteredSchema(datasource, [tableToSave.name])
|
|
||||||
).tables[tableToSave.name]
|
|
||||||
} else {
|
|
||||||
datasource.entities[tableToSave.name] = tableToSave
|
datasource.entities[tableToSave.name] = tableToSave
|
||||||
}
|
|
||||||
|
|
||||||
// store it into couch now for budibase reference
|
// store it into couch now for budibase reference
|
||||||
await db.put(populateExternalTableSchemas(datasource))
|
await db.put(populateExternalTableSchemas(datasource))
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import { Document } from "../../document"
|
import { Document } from "../../document"
|
||||||
import { View, ViewV2 } from "../view"
|
import { View, ViewV2 } from "../view"
|
||||||
import { AddColumn, RenameColumn } from "../../../sdk"
|
import { RenameColumn } from "../../../sdk"
|
||||||
import { TableSchema } from "./schema"
|
import { TableSchema } from "./schema"
|
||||||
|
|
||||||
export const INTERNAL_TABLE_SOURCE_ID = "bb_internal"
|
export const INTERNAL_TABLE_SOURCE_ID = "bb_internal"
|
||||||
|
@ -30,6 +30,5 @@ export interface Table extends Document {
|
||||||
|
|
||||||
export interface TableRequest extends Table {
|
export interface TableRequest extends Table {
|
||||||
_rename?: RenameColumn
|
_rename?: RenameColumn
|
||||||
_add?: AddColumn
|
|
||||||
created?: boolean
|
created?: boolean
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,10 +61,6 @@ export interface RenameColumn {
|
||||||
updated: string
|
updated: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface AddColumn {
|
|
||||||
name: string
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface RelationshipsJson {
|
export interface RelationshipsJson {
|
||||||
through?: string
|
through?: string
|
||||||
from?: string
|
from?: string
|
||||||
|
|
Loading…
Reference in New Issue