From 2887a42f7add2ae63ed945036330b07083dd0635 Mon Sep 17 00:00:00 2001 From: Martin McKeaveney Date: Tue, 31 Aug 2021 14:44:33 +0100 Subject: [PATCH] prevent relationships getting overridden in mySQL connector --- packages/server/src/integrations/mysql.ts | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/packages/server/src/integrations/mysql.ts b/packages/server/src/integrations/mysql.ts index d71e85b0d2..8d1fcf275a 100644 --- a/packages/server/src/integrations/mysql.ts +++ b/packages/server/src/integrations/mysql.ts @@ -140,7 +140,7 @@ module MySQLModule { this.client = mysql.createConnection(config) } - async buildSchema(datasourceId: string) { + async buildSchema(datasourceId: string, entities: Record) { const tables: { [key: string]: Table } = {} const database = this.config.database this.client.connect() @@ -193,6 +193,19 @@ module MySQLModule { schema, } } + + // add the existing relationships from the entities if they exist, to prevent them from being overridden + if (entities && entities[tableName]) { + const existingTableSchema = entities[tableName].schema + for (let key in existingTableSchema) { + if (!existingTableSchema.hasOwnProperty(key)) { + continue + } + if (existingTableSchema[key].type === "link") { + tables[tableName].schema[key] = existingTableSchema[key] + } + } + } } this.client.end()