From dded4e7780644d04751113c1fa8bb5e9b6e268a0 Mon Sep 17 00:00:00 2001 From: Thomas Avery <43214426+Thomas-Avery@users.noreply.github.com> Date: Mon, 23 May 2022 11:35:39 -0500 Subject: [PATCH] Fix initial database creation in run_migrations.sh (#2009) --- dev/helpers/mssql/run_migrations.sh | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/dev/helpers/mssql/run_migrations.sh b/dev/helpers/mssql/run_migrations.sh index 6710410ce3..3da82b6d61 100755 --- a/dev/helpers/mssql/run_migrations.sh +++ b/dev/helpers/mssql/run_migrations.sh @@ -36,11 +36,16 @@ END; IF NOT EXISTS (SELECT * FROM sys.databases WHERE name = 'migrations_$DATABASE') BEGIN CREATE DATABASE migrations_$DATABASE; - CREATE TABLE [migrations_$DATABASE].[dbo].[migrations] ( +END; + +GO +IF OBJECT_ID('[migrations_$DATABASE].[dbo].[migrations]') IS NULL +BEGIN + CREATE TABLE [migrations_$DATABASE].[dbo].[migrations] ( [Id] INT IDENTITY(1,1) PRIMARY KEY, [Filename] NVARCHAR(MAX) NOT NULL, [CreationDate] DATETIME2 (7) NULL, - ); + ); END;" /opt/mssql-tools/bin/sqlcmd -S $SERVER -d master -U $USER -P $PASSWD -I -Q "$QUERY"