Fix tests
This commit is contained in:
parent
11ef351400
commit
b05f56222e
|
@ -125,7 +125,7 @@ describe("validation and update of external table schemas", () => {
|
|||
}
|
||||
|
||||
it("should correctly set utilised foreign keys to autocolumns", () => {
|
||||
const response = populateExternalTableSchemas(cloneDeep(SCHEMA) as any)
|
||||
const response = populateExternalTableSchemas(cloneDeep(SCHEMA))
|
||||
const foreignKey = getForeignKeyColumn(response)
|
||||
expect(foreignKey.autocolumn).toBe(true)
|
||||
expect(foreignKey.autoReason).toBe(AutoReason.FOREIGN_KEY)
|
||||
|
@ -133,7 +133,7 @@ describe("validation and update of external table schemas", () => {
|
|||
})
|
||||
|
||||
it("should correctly unset foreign keys when no longer used", () => {
|
||||
const setResponse = populateExternalTableSchemas(cloneDeep(SCHEMA) as any)
|
||||
const setResponse = populateExternalTableSchemas(cloneDeep(SCHEMA))
|
||||
const beforeFk = getForeignKeyColumn(setResponse)
|
||||
delete setResponse.entities!.client.schema.project
|
||||
delete setResponse.entities!.project.schema.client
|
||||
|
|
|
@ -40,14 +40,14 @@ function checkForeignKeysAreAutoColumns(datasource: Datasource) {
|
|||
const shouldBeForeign = foreignKeys.find(
|
||||
options => options.tableId === table._id && options.key === column.name
|
||||
)
|
||||
if (column.autocolumn) {
|
||||
continue
|
||||
}
|
||||
// don't change already auto-columns to it, e.g. primary keys that are foreign
|
||||
if (shouldBeForeign) {
|
||||
if (shouldBeForeign && !column.autocolumn) {
|
||||
column.autocolumn = true
|
||||
column.autoReason = AutoReason.FOREIGN_KEY
|
||||
} else if (column.autoReason === AutoReason.FOREIGN_KEY) {
|
||||
} else if (
|
||||
!shouldBeForeign &&
|
||||
column.autoReason === AutoReason.FOREIGN_KEY
|
||||
) {
|
||||
delete column.autocolumn
|
||||
delete column.autoReason
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue