Skip to content

Commit 9aa1d4f

Browse files
committed
TD-5638-Added DB snapshot
1 parent 9a12aae commit 9aa1d4f

File tree

4 files changed

+38
-2
lines changed

4 files changed

+38
-2
lines changed

DigitalLearningSolutions.Data.Migrations/202508261415_RemoveCustomAdminTitlesAddSupervisorNominatedSupervisor.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22
{
33
using FluentMigrator;
44

5-
[Migration(202508261415)]
6-
public class RemoveCustomAdminTitlesAddSupervisorNominatedSupervisor : ForwardOnlyMigration
5+
[Migration(202508261415, TransactionBehavior.None)]
6+
public class RemoveCustomAdminTitlesAddSupervisorNominatedSupervisor : Migration
77
{
88
public override void Up()
99
{
10+
Execute.Sql(Properties.Resources.TD_5638_SnapshotData_UP);
11+
1012
Execute.Sql($@"
1113
-- 1. Drop old FK
1214
ALTER TABLE [dbo].[SelfAssessmentSupervisorRoles]
@@ -59,5 +61,10 @@ LEFT JOIN SelfAssessmentSupervisorRoles nom
5961
"
6062
);
6163
}
64+
65+
public override void Down()
66+
{
67+
// Intentionally empty. If things go wrong later, we will manually restore the snapshot
68+
}
6269
}
6370
}

DigitalLearningSolutions.Data.Migrations/Properties/Resources.Designer.cs

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

DigitalLearningSolutions.Data.Migrations/Properties/Resources.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -517,4 +517,7 @@
517517
<data name="TD_5638_Alter_GetCandidateAssessmentResultsById_Up" type="System.Resources.ResXFileRef, System.Windows.Forms">
518518
<value>..\Scripts\TD-5638-Alter_GetCandidateAssessmentResultsById_Up.sql;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-16</value>
519519
</data>
520+
<data name="TD_5638_SnapshotData_UP" type="System.Resources.ResXFileRef, System.Windows.Forms">
521+
<value>..\Scripts\TD-5638-SnapshotData-UP.sql;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;Windows-1252</value>
522+
</data>
520523
</root>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
DECLARE @dbName NVARCHAR(128) = DB_NAME()
2+
DECLARE @defaultPath NVARCHAR(500) = CONVERT(NVARCHAR(500), SERVERPROPERTY('InstanceDefaultDataPath'))
3+
DECLARE @snapshotTime NVARCHAR(12) = FORMAT(GETDATE(), 'yyyyMMddHHmm')
4+
5+
DECLARE @snapSql NVARCHAR(4000) = 'CREATE DATABASE ' + @dbName + '_' + @snapshotTime + ' ON
6+
( NAME = mbdbx101, FILENAME = ''' + @defaultPath + @dbName + '_' + @snapshotTime + '''),
7+
( NAME = mbdbx101files, FILENAME = ''' + @defaultPath + @dbName + '_filestream1_' + @snapshotTime + ''')
8+
AS SNAPSHOT OF ' + @dbName
9+
10+
EXEC sp_executesql @stmt = @SnapSql

0 commit comments

Comments
 (0)