From c552913737de15ec158493fedadc6221b835dc1d Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Fri, 14 Apr 2023 18:10:10 +0100 Subject: [PATCH] Fixing defaults in MS-SQL as well. --- .../integrations/mssql/data/entrypoint.sh | 1 + .../scripts/integrations/mssql/data/setup.sql | 34 +++++++++---------- .../src/integrations/microsoftSqlServer.ts | 3 +- 3 files changed, 20 insertions(+), 18 deletions(-) diff --git a/packages/server/scripts/integrations/mssql/data/entrypoint.sh b/packages/server/scripts/integrations/mssql/data/entrypoint.sh index 04780d085e..ffe8d2cd5d 100644 --- a/packages/server/scripts/integrations/mssql/data/entrypoint.sh +++ b/packages/server/scripts/integrations/mssql/data/entrypoint.sh @@ -11,6 +11,7 @@ if [ "$1" = '/opt/mssql/bin/sqlservr' ]; then echo "RUNNING BUDIBASE SETUP" + cat setup.sql #run the setup script to create the DB and the schema in the DB /opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P Passw0rd -i setup.sql diff --git a/packages/server/scripts/integrations/mssql/data/setup.sql b/packages/server/scripts/integrations/mssql/data/setup.sql index 91c53cced7..a33a99cea5 100644 --- a/packages/server/scripts/integrations/mssql/data/setup.sql +++ b/packages/server/scripts/integrations/mssql/data/setup.sql @@ -34,7 +34,7 @@ GO CREATE TABLE people ( name varchar(30) NOT NULL, - age varchar(20), + age int default 20 NOT NULL, CONSTRAINT pk_people PRIMARY KEY NONCLUSTERED (name, age) ); @@ -50,22 +50,22 @@ VALUES ('Processing', 1); INSERT INTO people (name, age) -VALUES ('Bob', '30'), - ('Bert', '10'), - ('Jack', '12'), - ('Mike', '31'), - ('Dave', '44'), - ('Jim', '43'), - ('Kerry', '32'), - ('Julie', '12'), - ('Kim', '55'), - ('Andy', '33'), - ('John', '22'), - ('Ruth', '66'), - ('Robert', '88'), - ('Bobert', '99'), - ('Jan', '22'), - ('Megan', '11'); +VALUES ('Bob', 30), + ('Bert', 10), + ('Jack', 12), + ('Mike', 31), + ('Dave', 44), + ('Jim', 43), + ('Kerry', 32), + ('Julie', 12), + ('Kim', 55), + ('Andy', 33), + ('John', 22), + ('Ruth', 66), + ('Robert', 88), + ('Bobert', 99), + ('Jan', 22), + ('Megan', 11); IF OBJECT_ID ('Chains.sizes', 'U') IS NOT NULL diff --git a/packages/server/src/integrations/microsoftSqlServer.ts b/packages/server/src/integrations/microsoftSqlServer.ts index 87da1ae81e..eb87c1ccf1 100644 --- a/packages/server/src/integrations/microsoftSqlServer.ts +++ b/packages/server/src/integrations/microsoftSqlServer.ts @@ -243,13 +243,14 @@ class SqlServerIntegration extends Sql implements DatasourcePlus { if (typeof name !== "string") { continue } + const hasDefault = def.COLUMN_DEFAULT const isAuto = !!autoColumns.find(col => col === name) const required = !!requiredColumns.find(col => col === name) schema[name] = { autocolumn: isAuto, name: name, constraints: { - presence: required && !isAuto, + presence: required && !isAuto && !hasDefault, }, ...convertSqlType(def.DATA_TYPE), externalType: def.DATA_TYPE,