Skip to content

Commit a5ffc69

Browse files
author
Auldrin Possa
committed
TD-5447- FrameworkCompetencyGroupID null check added in the SQL query and in the stored procedure. Migration script added to update ordering for existing ungroup competencies.
1 parent a2aad3b commit a5ffc69

File tree

7 files changed

+96
-4
lines changed

7 files changed

+96
-4
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+

2+
3+
namespace DigitalLearningSolutions.Data.Migrations
4+
{
5+
using FluentMigrator;
6+
7+
[Migration(202504241045)]
8+
public class Alter_ReorderFrameworkCompetency : Migration
9+
{
10+
public override void Up()
11+
{
12+
Execute.Sql(Properties.Resources.TD_5447_Alter_ReorderFrameworkCompetency_Up);
13+
}
14+
public override void Down()
15+
{
16+
Execute.Sql(Properties.Resources.TD_5447_Alter_ReorderFrameworkCompetency_Down);
17+
}
18+
}
19+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
namespace DigitalLearningSolutions.Data.Migrations
2+
{
3+
using FluentMigrator;
4+
[Migration(202504241115)]
5+
public class UpdateFrameworkCompetenciesOrdering : ForwardOnlyMigration
6+
{
7+
public override void Up()
8+
{
9+
Execute.Sql(@"WITH Ranked AS (
10+
    SELECT ID,
11+
            ROW_NUMBER() OVER (PARTITION BY FrameworkID ORDER BY SysStartTime) AS NewOrder
12+
    FROM FrameworkCompetencies
13+
Where FrameworkCompetencyGroupID is null
14+
)
15+
UPDATE fc
16+
SET fc.Ordering = r.NewOrder
17+
FROM FrameworkCompetencies fc
18+
JOIN Ranked r ON fc.ID = r.ID;");
19+
}
20+
}
21+
}

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

Lines changed: 44 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: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -475,4 +475,10 @@
475475
<data name="TD_5412_Alter_SendExpiredTBCReminders_Up" type="System.Resources.ResXFileRef, System.Windows.Forms">
476476
<value>..\Scripts\TD-5412-Alter_SendExpiredTBCReminders_Up.sql;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-16</value>
477477
</data>
478+
<data name="TD_5447_Alter_ReorderFrameworkCompetency_Down" type="System.Resources.ResXFileRef, System.Windows.Forms">
479+
<value>..\Scripts\TD-5447-Alter_ReorderFrameworkCompetency_Down.sql;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-16</value>
480+
</data>
481+
<data name="TD_5447_Alter_ReorderFrameworkCompetency_Up" type="System.Resources.ResXFileRef, System.Windows.Forms">
482+
<value>..\Scripts\TD-5447-Alter_ReorderFrameworkCompetency_Up.sql;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-16</value>
483+
</data>
478484
</root>
Binary file not shown.

DigitalLearningSolutions.Data/DataServices/FrameworkDataService.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -680,9 +680,11 @@ public int InsertFrameworkCompetency(
680680
var numberOfAffectedRows = connection.Execute(
681681
@"INSERT INTO FrameworkCompetencies ([CompetencyID], FrameworkCompetencyGroupID, UpdatedByAdminID, Ordering, FrameworkID)
682682
VALUES (@competencyId, @frameworkCompetencyGroupID, @adminId, COALESCE
683-
((SELECT MAX(Ordering) AS OrderNum
684-
FROM [FrameworkCompetencies]
685-
WHERE ([FrameworkCompetencyGroupID] = @frameworkCompetencyGroupID)), 0)+1, @frameworkId)",
683+
((SELECT MAX(Ordering) AS OrderNum
684+
FROM [FrameworkCompetencies]
685+
WHERE ((@frameworkCompetencyGroupID IS NULL AND FrameworkCompetencyGroupID IS NULL) OR
686+
(@frameworkCompetencyGroupID IS NOT NULL AND FrameworkCompetencyGroupID = @frameworkCompetencyGroupID)) AND
687+
FrameworkID = @frameworkId ), 0)+1, @frameworkId)",
686688
new { competencyId, frameworkCompetencyGroupID, adminId, frameworkId }
687689
);
688690
if (numberOfAffectedRows < 1)
@@ -707,7 +709,7 @@ FROM [FrameworkCompetencies]
707709
new { competencyId, frameworkCompetencyGroupID }
708710
);
709711
}
710-
if(addDefaultQuestions)
712+
if (addDefaultQuestions)
711713
{
712714
AddDefaultQuestionsToCompetency(competencyId, frameworkId);
713715
}

0 commit comments

Comments
 (0)