Skip to content

Commit

Permalink
Merge pull request #80 from SSchulze1989/develop
Browse files Browse the repository at this point in the history
v 0.9.0
  • Loading branch information
SSchulze1989 authored Sep 10, 2023
2 parents 994f946 + 51636df commit 7df7c65
Show file tree
Hide file tree
Showing 28 changed files with 20,121 additions and 115 deletions.
27 changes: 27 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
// README at: https://github.com/devcontainers/templates/tree/main/src/dotnet
{
"name": "C# (.NET)",
// Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
"image": "mcr.microsoft.com/devcontainers/dotnet:0-6.0"

// Features to add to the dev container. More info: https://containers.dev/features.
// "features": {},

// Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [5000, 5001],
// "portsAttributes": {
// "5001": {
// "protocol": "https"
// }
// }

// Use 'postCreateCommand' to run commands after the container is created.
// "postCreateCommand": "dotnet restore",

// Configure tool-specific properties.
// "customizations": {},

// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
// "remoteUser": "root"
}
2 changes: 1 addition & 1 deletion src/DatabaseBenchmarks/DatabaseBenchmarks.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

<ItemGroup>
<PackageReference Include="BenchmarkDotNet" Version="0.13.2" />
<PackageReference Include="iRLeagueApiCore.Common" Version="0.8.0" />
<PackageReference Include="iRLeagueApiCore.Common" Version="0.9.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.7" />
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="6.0.7" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="6.0.1" />
Expand Down
1 change: 0 additions & 1 deletion src/iRLeagueDatabaseCore/ILeagueDbContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ public interface ILeagueDbContext
public DbSet<ResultConfigurationEntity> ResultConfigurations { get; set; }
public DbSet<ResultRowEntity> ResultRows { get; set; }
public DbSet<FilterOptionEntity> FilterOptions { get; set; }
public DbSet<FilterConditionEntity> FilterConditions { get; set; }
public DbSet<ReviewPenaltyEntity> ReviewPenaltys { get; set; }
public DbSet<ScheduleEntity> Schedules { get; set; }
public DbSet<ScoredEventResultEntity> ScoredEventResults { get; set; }
Expand Down
3 changes: 0 additions & 3 deletions src/iRLeagueDatabaseCore/LeagueDbContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ public LeagueDbContext(DbContextOptions<LeagueDbContext> options, ILeagueProvide
public virtual DbSet<ResultConfigurationEntity> ResultConfigurations { get; set; }
public virtual DbSet<ResultRowEntity> ResultRows { get; set; }
public virtual DbSet<FilterOptionEntity> FilterOptions { get; set; }
public virtual DbSet<FilterConditionEntity> FilterConditions { get; set; }
public virtual DbSet<ReviewPenaltyEntity> ReviewPenaltys { get; set; }
public virtual DbSet<ScheduleEntity> Schedules { get; set; }
public virtual DbSet<ScoredEventResultEntity> ScoredEventResults { get; set; }
Expand Down Expand Up @@ -110,8 +109,6 @@ private void ConfigureMultiTenancy(ModelBuilder builder)
.HasQueryFilter(mt => mt.LeagueId == LeagueProvider.LeagueId);
builder.Entity<FilterOptionEntity>()
.HasQueryFilter(mt => mt.LeagueId == LeagueProvider.LeagueId);
builder.Entity<FilterConditionEntity>()
.HasQueryFilter(mt => mt.LeagueId == LeagueProvider.LeagueId);
builder.Entity<ReviewPenaltyEntity>()
.HasQueryFilter(mt => mt.LeagueId == LeagueProvider.LeagueId);
builder.Entity<ScheduleEntity>()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/* Migrate the filterOptionEntity used on ResultConfigs to use json column for Conditions
* instead of previous FilterConditionEntity
*/

USE TestDatabase;

SET autocommit=0;
START TRANSACTION;

-- Pre migration
-- Create Temporary table holding the bonus points before changing column type
CREATE TEMPORARY TABLE TmpBonusPoints (
LeagueId BIGINT NOT NULL,
PointRuleId BIGINT NOT NULL PRIMARY KEY,
BonusPoints TEXT
);

INSERT INTO TmpBonusPoints (LeagueId, PointRuleId, BonusPoints)
SELECT LeagueId, PointRuleId, BonusPoints
FROM PointRules;

UPDATE PointRules
SET BonusPoints='[]';

-- Post migration
-- Create function to convert bonus values from single string into json array
DELIMITER //

DROP FUNCTION IF EXISTS splitStringToBonusPoints;

CREATE FUNCTION splitStringToBonusPoints(inputString TEXT,
pointDelimiter TEXT)
RETURNS TEXT
DETERMINISTIC
BEGIN
DECLARE bonusType TEXT;
DECLARE bonusValue TEXT;
DECLARE bonusPoints TEXT;
SET bonusType = SUBSTRING_INDEX(inputString,pointDelimiter,1);
SET bonusPoints = SUBSTRING(SUBSTRING_INDEX(inputString,pointDelimiter,2), LENGTH(bonusType)+2, 10);
SET bonusValue = IF(LENGTH(bonusType)>1, SUBSTRING(bonusType, 2, 10), '0');
SET bonusType = SUBSTRING(bonusType, 1, 1);
SET bonusType = CASE bonusType
WHEN 'p' THEN '0'
WHEN 'q' THEN '1'
WHEN 'f' THEN '2'
WHEN 'a' THEN '3'
WHEN 'c' THEN '4'
WHEN 'n' THEN '5'
WHEN 'g' THEN '6'
WHEN 'd' THEN '7'
WHEN 'l' THEN '8'
WHEN 'm' THEN '9'
END;
RETURN CONCAT('{"Type":',bonusType,',"Value":',bonusValue,',"Points":',bonusPoints,',"Conditions":[]}');
END;

DROP FUNCTION IF EXISTS splitToArray;

CREATE FUNCTION splitToArray(
inputString TEXT,
arrayDelimiter TEXT,
pointDelimiter TEXT)
RETURNS TEXT
DETERMINISTIC
BEGIN
DECLARE tempString TEXT;
SET tempString = '[';
WHILE LOCATE(arrayDelimiter,inputString) > 1 DO
SET tempString = CONCAT(tempString, splitStringToBonusPoints(SUBSTRING_INDEX(inputString,arrayDelimiter,1), pointDelimiter), ',');
SET inputString = REGEXP_REPLACE(inputString, (
SELECT LEFT(inputString, LOCATE(arrayDelimiter, inputString))
),'',1,1);
END WHILE;
SET tempString = CONCAT(tempString, splitStringToBonusPoints(SUBSTRING_INDEX(inputString,arrayDelimiter,1), pointDelimiter), ']');
RETURN tempString;
END; //

DELIMITER ;

-- Populate `Conditions` column with stored values and perform necessary value conversions
UPDATE TmpBonusPoints
SET BonusPoints = splitToArray(BonusPoints, ';', ':');
UPDATE PointRules AS pr
JOIN TmpBonusPoints AS tmp
ON tmp.PointRuleId=pr.PointRuleId
SET pr.BonusPoints = tmp.BonusPoints
WHERE tmp.BonusPoints IS NOT NULL;

DROP TABLE TmpBonusPoints;
DROP FUNCTION splitToArray;
DROP FUNCTION splitStringToBonusPoints;

ROLLBACK;
20 changes: 20 additions & 0 deletions src/iRLeagueDatabaseCore/MigrationFiltersForChampSeason.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/* Migrate the filterOptionEntity used on ResultConfigs to use json column for Conditions
* instead of previous FilterConditionEntity
*/

USE TestDatabase;

START TRANSACTION;

-- Populate `Conditions` column with stored values and perform necessary value conversions
UPDATE FilterOptions AS f
JOIN ResultConfigurations AS rc
ON rc.ResultConfigId=f.ResultFilterResultConfigId
JOIN ChampSeasons AS cs
ON cs.ChampSeasonId=rc.ChampSeasonId
JOIN Seasons AS s
ON cs.SeasonId=s.SeasonId
WHERE s.Finished=0 AND cs.IsActive
SET f.ChampSeasonId = rc.ChampSeasonId, f.ResultFilterResultConfigId=NULL;

ROLLBACK;
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/* Migrate the filterOptionEntity used on ResultConfigs to use json column for Conditions
* instead of previous FilterConditionEntity
*/

USE TestDatabase;

START TRANSACTION;

DROP TABLE IF EXISTS TmpResultConfigKinds;

CREATE TEMPORARY TABLE TmpResultConfigKinds(
LeagueId BIGINT NOT NULL,
ResultConfigId BIGINT NOT NULL,
ChampSeasonId BIGINT NOT NULL,
ResultKind VARCHAR(50) NOT NULL,
PRIMARY KEY(LeagueId, ResultConfigId)
);

INSERT INTO TmpResultConfigKinds(LeagueId, ResultConfigId, ChampSeasonId, ResultKind)
SELECT LeagueId, ResultConfigId, ChampSeasonId, ResultKind FROM ResultConfigurations;

SELECT * FROM TmpResultConfigKinds;

-- Populate `Conditions` column with stored values and perform necessary value conversions
UPDATE ChampSeasons AS cs
JOIN TmpResultConfigKinds as rc
ON cs.ChampSeasonId=rc.ChampSeasonId
SET cs.ResultKind=rc.ResultKind;

UPDATE ChampSeasons
SET ResultKind='Member'
WHERE ResultKind='';

SELECT LeagueId, ChampSeasonId, ResultKind FROM ChampSeasons;

DROP TABLE TmpResultConfigKinds;

ROLLBACK;
89 changes: 89 additions & 0 deletions src/iRLeagueDatabaseCore/MigrationUseJsonFiltersOnResultConfig.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/* Migrate the filterOptionEntity used on ResultConfigs to use json column for Conditions
* instead of previous FilterConditionEntity
*/

USE TestDatabase;

START TRANSACTION;

-- Pre migration
-- Create Temporary table holding the filter conditions before dropping table
CREATE TEMPORARY TABLE TmpFilterConditions (
LeagueId BIGINT NOT NULL,
ConditionId BIGINT NOT NULL,
FilterOptionId BIGINT NOT NULL,
FilterType LONGTEXT NOT NULL,
ColumnPropertyName LONGTEXT NULL,
Comparator LONGTEXT NOT NULL,
`Action` LONGTEXT NOT NULL,
FilterValues LONGTEXT NULL,
PRIMARY KEY (LeagueId, ConditionId)
);

INSERT INTO TmpFilterConditions (LeagueId, ConditionId, FilterOptionId, FilterType, ColumnPropertyName, Comparator, Action, FilterValues)
SELECT LeagueId, ConditionId, FilterOptionId, FilterType, ColumnPropertyName, Comparator, Action, FilterValues
FROM FilterConditions;

-- Post migration
-- Create function to convert Filter values from single string into json array
DELIMITER //

DROP FUNCTION IF EXISTS splitStringToJsonArray;

CREATE FUNCTION splitStringToJsonArray(
inputString TEXT,
delimiterChar CHAR(1))
RETURNS TEXT
DETERMINISTIC
BEGIN
DECLARE temp_string TEXT;
SET temp_string = '["';
WHILE LOCATE(delimiterChar,inputString) > 1 DO
SET temp_string = CONCAT(temp_string, SUBSTRING_INDEX(inputString,delimiterChar,1), '","');
SET inputString = REGEXP_REPLACE(inputString, (
SELECT LEFT(inputString, LOCATE(delimiterChar, inputString))
),'',1,1);
END WHILE;
SET temp_string = CONCAT(temp_string, inputString, '"]');
RETURN temp_string;
END; //

DELIMITER ;

-- Populate `Conditions` column with stored values and perform necessary value conversions
UPDATE FilterOptions AS f
JOIN (SELECT FilterOptionId,
CASE FilterType
WHEN 'ColumnProperty' THEN 0
WHEN 'Member' THEN 1
WHEN 'Team' THEN 2
END AS FilterType,
ColumnPropertyName,
CASE Comparator
WHEN 'IsSmaller' THEN 0
WHEN 'IsSmallerOrEqual' THEN 1
WHEN 'IsEqual' THEN 2
WHEN 'IsBiggerOrEqual' THEN 3
WHEN 'IsBigger' THEN 4
WHEN 'NotEqual' THEN 5
WHEN 'InList' THEN 6
WHEN 'ForEach' THEN 7
END AS Comparator,
CASE `Action`
WHEN 'Keep' THEN 0
WHEN 'Remove' THEN 1
END AS `Action`,
FilterValues
FROM TmpFilterConditions) AS fc
ON fc.FilterOptionId = f.FilterOptionId
SET f.Conditions = CONCAT(
'[{"Action": ', fc.`Action`,
', "Comparator": ', fc.Comparator,
', "FilterType": ', fc.FilterType,
', "FilterValues": ', splitStringToJsonArray(fc.FilterValues, ';'),
', "ColumnPropertyName": "', fc.ColumnPropertyName, '"}]');

DROP TABLE TmpFilterConditions;
DROP FUNCTION splitStringToJsonArray;

ROLLBACK;
Loading

0 comments on commit 7df7c65

Please sign in to comment.