Fixes
This commit is contained in:
parent
dd373cd5e9
commit
c8ffa98844
|
@ -10,6 +10,7 @@ import {
|
||||||
} from "../../../utilities/rowProcessor"
|
} from "../../../utilities/rowProcessor"
|
||||||
import { runStaticFormulaChecks } from "./bulkFormula"
|
import { runStaticFormulaChecks } from "./bulkFormula"
|
||||||
import {
|
import {
|
||||||
|
AutoColumnFieldMetadata,
|
||||||
RenameColumn,
|
RenameColumn,
|
||||||
SaveTableRequest,
|
SaveTableRequest,
|
||||||
SaveTableResponse,
|
SaveTableResponse,
|
||||||
|
@ -35,7 +36,9 @@ function checkAutoColumns(table: Table, oldTable?: Table) {
|
||||||
if (oldSchema && oldSchema.subtype) {
|
if (oldSchema && oldSchema.subtype) {
|
||||||
table.schema[key].subtype = oldSchema.subtype
|
table.schema[key].subtype = oldSchema.subtype
|
||||||
} else {
|
} else {
|
||||||
table.schema[key] = fixAutoColumnSubType(schema)
|
table.schema[key] = fixAutoColumnSubType(
|
||||||
|
schema as AutoColumnFieldMetadata
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return table
|
return table
|
||||||
|
@ -78,10 +81,10 @@ export async function save(ctx: UserCtx<SaveTableRequest, SaveTableResponse>) {
|
||||||
// make sure that types don't change of a column, have to remove
|
// make sure that types don't change of a column, have to remove
|
||||||
// the column if you want to change the type
|
// the column if you want to change the type
|
||||||
if (oldTable && oldTable.schema) {
|
if (oldTable && oldTable.schema) {
|
||||||
for (let propKey of Object.keys(tableToSave.schema)) {
|
for (const propKey of Object.keys(tableToSave.schema)) {
|
||||||
let oldColumn = oldTable.schema[propKey]
|
let oldColumn = oldTable.schema[propKey]
|
||||||
if (oldColumn && oldColumn.type === FieldTypes.INTERNAL) {
|
if (oldColumn && oldColumn.type === FieldTypes.INTERNAL) {
|
||||||
oldColumn.type = FieldTypes.AUTO
|
oldColumn.type = FieldTypes.AUTO as any // TODO
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,13 +5,13 @@ import {
|
||||||
FormulaTypes,
|
FormulaTypes,
|
||||||
} from "../../constants"
|
} from "../../constants"
|
||||||
import { processStringSync } from "@budibase/string-templates"
|
import { processStringSync } from "@budibase/string-templates"
|
||||||
import { FieldSchema, Row, Table } from "@budibase/types"
|
import { AutoColumnFieldMetadata, Row, Table } from "@budibase/types"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If the subtype has been lost for any reason this works out what
|
* If the subtype has been lost for any reason this works out what
|
||||||
* subtype the auto column should be.
|
* subtype the auto column should be.
|
||||||
*/
|
*/
|
||||||
export function fixAutoColumnSubType(column: FieldSchema) {
|
export function fixAutoColumnSubType(column: AutoColumnFieldMetadata) {
|
||||||
if (!column.autocolumn || !column.name || column.subtype) {
|
if (!column.autocolumn || !column.name || column.subtype) {
|
||||||
return column
|
return column
|
||||||
}
|
}
|
||||||
|
@ -47,12 +47,14 @@ export function processFormulas(
|
||||||
rowArray = rows
|
rowArray = rows
|
||||||
}
|
}
|
||||||
for (let [column, schema] of Object.entries(table.schema)) {
|
for (let [column, schema] of Object.entries(table.schema)) {
|
||||||
const isStatic = schema.formulaType === FormulaTypes.STATIC
|
const isStaticFormula =
|
||||||
|
schema.type === FieldTypes.FORMULA &&
|
||||||
|
schema.formulaType === FormulaTypes.STATIC
|
||||||
if (
|
if (
|
||||||
schema.type !== FieldTypes.FORMULA ||
|
schema.type !== FieldTypes.FORMULA ||
|
||||||
schema.formula == null ||
|
schema.formula == null ||
|
||||||
(dynamic && isStatic) ||
|
(dynamic && isStaticFormula) ||
|
||||||
(!dynamic && !isStatic)
|
(!dynamic && !isStaticFormula)
|
||||||
) {
|
) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,8 +34,8 @@ export type RelationshipFieldMetadata = BaseFieldSchema & {
|
||||||
|
|
||||||
export interface AutoColumnFieldMetadata extends BaseFieldSchema {
|
export interface AutoColumnFieldMetadata extends BaseFieldSchema {
|
||||||
type: FieldType.AUTO
|
type: FieldType.AUTO
|
||||||
autocolumn?: boolean
|
autocolumn: true
|
||||||
subtype?: string
|
subtype: AutoFieldSubTypes
|
||||||
lastID?: number
|
lastID?: number
|
||||||
// if the column was turned to an auto-column for SQL, explains why (primary, foreign etc)
|
// if the column was turned to an auto-column for SQL, explains why (primary, foreign etc)
|
||||||
autoReason?: AutoReason
|
autoReason?: AutoReason
|
||||||
|
@ -105,9 +105,25 @@ interface BaseFieldSchema extends UIFieldMetadata {
|
||||||
// only used by external databases, to denote the real type
|
// only used by external databases, to denote the real type
|
||||||
externalType?: string
|
externalType?: string
|
||||||
constraints?: FieldConstraints
|
constraints?: FieldConstraints
|
||||||
|
autocolumn?: boolean
|
||||||
|
subtype?: string
|
||||||
|
}
|
||||||
|
|
||||||
|
interface OtherFieldMetadata extends BaseFieldSchema {
|
||||||
|
type: Exclude<
|
||||||
|
FieldType,
|
||||||
|
| FieldType.DATETIME
|
||||||
|
| FieldType.DATETIME
|
||||||
|
| FieldType.LINK
|
||||||
|
| FieldType.AUTO
|
||||||
|
| FieldType.STRING
|
||||||
|
| FieldType.FORMULA
|
||||||
|
| FieldType.NUMBER
|
||||||
|
>
|
||||||
}
|
}
|
||||||
|
|
||||||
export type FieldSchema =
|
export type FieldSchema =
|
||||||
|
| OtherFieldMetadata
|
||||||
| DateFieldMetadata
|
| DateFieldMetadata
|
||||||
| RelationshipFieldMetadata
|
| RelationshipFieldMetadata
|
||||||
| AutoColumnFieldMetadata
|
| AutoColumnFieldMetadata
|
||||||
|
|
Loading…
Reference in New Issue