Fixes
This commit is contained in:
parent
dd373cd5e9
commit
c8ffa98844
|
@ -10,6 +10,7 @@ import {
|
|||
} from "../../../utilities/rowProcessor"
|
||||
import { runStaticFormulaChecks } from "./bulkFormula"
|
||||
import {
|
||||
AutoColumnFieldMetadata,
|
||||
RenameColumn,
|
||||
SaveTableRequest,
|
||||
SaveTableResponse,
|
||||
|
@ -35,7 +36,9 @@ function checkAutoColumns(table: Table, oldTable?: Table) {
|
|||
if (oldSchema && oldSchema.subtype) {
|
||||
table.schema[key].subtype = oldSchema.subtype
|
||||
} else {
|
||||
table.schema[key] = fixAutoColumnSubType(schema)
|
||||
table.schema[key] = fixAutoColumnSubType(
|
||||
schema as AutoColumnFieldMetadata
|
||||
)
|
||||
}
|
||||
}
|
||||
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
|
||||
// the column if you want to change the type
|
||||
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]
|
||||
if (oldColumn && oldColumn.type === FieldTypes.INTERNAL) {
|
||||
oldColumn.type = FieldTypes.AUTO
|
||||
oldColumn.type = FieldTypes.AUTO as any // TODO
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,13 +5,13 @@ import {
|
|||
FormulaTypes,
|
||||
} from "../../constants"
|
||||
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
|
||||
* subtype the auto column should be.
|
||||
*/
|
||||
export function fixAutoColumnSubType(column: FieldSchema) {
|
||||
export function fixAutoColumnSubType(column: AutoColumnFieldMetadata) {
|
||||
if (!column.autocolumn || !column.name || column.subtype) {
|
||||
return column
|
||||
}
|
||||
|
@ -47,12 +47,14 @@ export function processFormulas(
|
|||
rowArray = rows
|
||||
}
|
||||
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 (
|
||||
schema.type !== FieldTypes.FORMULA ||
|
||||
schema.formula == null ||
|
||||
(dynamic && isStatic) ||
|
||||
(!dynamic && !isStatic)
|
||||
(dynamic && isStaticFormula) ||
|
||||
(!dynamic && !isStaticFormula)
|
||||
) {
|
||||
continue
|
||||
}
|
||||
|
|
|
@ -34,8 +34,8 @@ export type RelationshipFieldMetadata = BaseFieldSchema & {
|
|||
|
||||
export interface AutoColumnFieldMetadata extends BaseFieldSchema {
|
||||
type: FieldType.AUTO
|
||||
autocolumn?: boolean
|
||||
subtype?: string
|
||||
autocolumn: true
|
||||
subtype: AutoFieldSubTypes
|
||||
lastID?: number
|
||||
// if the column was turned to an auto-column for SQL, explains why (primary, foreign etc)
|
||||
autoReason?: AutoReason
|
||||
|
@ -105,9 +105,25 @@ interface BaseFieldSchema extends UIFieldMetadata {
|
|||
// only used by external databases, to denote the real type
|
||||
externalType?: string
|
||||
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 =
|
||||
| OtherFieldMetadata
|
||||
| DateFieldMetadata
|
||||
| RelationshipFieldMetadata
|
||||
| AutoColumnFieldMetadata
|
||||
|
|
Loading…
Reference in New Issue