From b828faf30d04bedff7b2347265d7c0bd3243d947 Mon Sep 17 00:00:00 2001 From: Vince Grassia <593223+vgrassia@users.noreply.github.com> Date: Mon, 19 Sep 2022 18:57:18 -0400 Subject: [PATCH] Fix run_migrations.sh script (#2289) --- dev/helpers/mssql/run_migrations.sh | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/dev/helpers/mssql/run_migrations.sh b/dev/helpers/mssql/run_migrations.sh index 3da82b6d61..2ff75e7c5e 100755 --- a/dev/helpers/mssql/run_migrations.sh +++ b/dev/helpers/mssql/run_migrations.sh @@ -33,22 +33,30 @@ BEGIN CREATE DATABASE $DATABASE; END; +GO IF NOT EXISTS (SELECT * FROM sys.databases WHERE name = 'migrations_$DATABASE') BEGIN CREATE DATABASE migrations_$DATABASE; END; GO -IF OBJECT_ID('[migrations_$DATABASE].[dbo].[migrations]') IS NULL +" +/opt/mssql-tools/bin/sqlcmd -S $SERVER -d master -U $USER -P $PASSWD -I -Q "$QUERY" +echo "Return code: $?" + +# Create migrations table if it does not already exist +QUERY="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" +END; +GO +" +/opt/mssql-tools/bin/sqlcmd -S $SERVER -d migrations_$DATABASE -U $USER -P $PASSWD -I -Q "$QUERY" +echo "Return code: $?" should_migrate () { local file=$(basename $1)