Skip to content

Commit fb9a08c

Browse files
committed
Merge branch 'master' of https://github.com/ZeroK-RTS/Zero-K-Infrastructure into ranks
Conflicts: ZkData/Migrations/Configuration.cs
2 parents 11d12ac + b877087 commit fb9a08c

5 files changed

Lines changed: 215 additions & 39 deletions

File tree

ZkData/Migrations/201712232154526_AddedSunRanks.Designer.cs

Lines changed: 29 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
namespace ZkData.Migrations
2+
{
3+
using System;
4+
using System.Data.Entity.Migrations;
5+
6+
public partial class AddedSunRanks : DbMigration
7+
{
8+
public override void Up()
9+
{
10+
AddColumn("dbo.Accounts", "Rank", c => c.Int(nullable: false));
11+
}
12+
13+
public override void Down()
14+
{
15+
DropColumn("dbo.Accounts", "Rank");
16+
}
17+
}
18+
}

ZkData/Migrations/201712232154526_AddedSunRanks.resx

Lines changed: 126 additions & 0 deletions
Large diffs are not rendered by default.

ZkData/Migrations/Configuration.cs

Lines changed: 37 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -35,47 +35,19 @@ private static void InitializeBattleRatings(ZkDataContext db)
3535
});
3636
}
3737

38+
/// <summary>
39+
/// This method is called after migration to latest version
40+
/// </summary>
3841
protected override void Seed(ZkDataContext db) {
3942
var ago = DateTime.UtcNow.AddDays(-GlobalConst.LadderActivityDays);
4043
db.Accounts.Where(x => x.LastLogin > ago).ForEach(x =>
4144
{
4245
x.Rank = Math.Max(0, Math.Min(7, (int)(x.AccountRatings.Where(a => a.RatingCategory == RatingCategory.Casual).Select(a => a.RealElo).DefaultIfEmpty(1500).FirstOrDefault() - 1000) / 200));
4346
});
4447
db.SaveChanges();
45-
46-
// This method will be called after migrating to the latest version.
47-
if (GlobalConst.Mode == ModeType.Local)
48-
{
49-
// fill local DB with some basic test data
50-
db.MiscVars.AddOrUpdate(
51-
x => x.VarName,
52-
new MiscVar { VarName = "NightwatchPassword", VarValue = "dummy" },
53-
new MiscVar { VarName = "GithubHookKey", VarValue = "secret" });
54-
55-
if (!db.MiscVars.Any(y=>y.VarName=="SteamBuildPassword"))
56-
db.MiscVars.AddOrUpdate(x => x.VarName, new MiscVar { VarName = "SteamBuildPassword", VarValue = "secret" });
57-
58-
if (!db.MiscVars.Any(y => y.VarName == "GlacierSecretKey"))
59-
db.MiscVars.AddOrUpdate(x => x.VarName, new MiscVar { VarName = "GlacierSecretKey", VarValue = "secret" });
60-
61-
62-
db.Accounts.AddOrUpdate(
63-
x => x.Name,
64-
new Account
65-
{
66-
Name = "TestPlayer",
67-
NewPasswordPlain = "test",
68-
AdminLevel = AdminLevel.SuperAdmin,
69-
Kudos = 200,
70-
Level = 255,
71-
Xp = 1325900,
72-
Rank = 3,
73-
Country = "cz",
74-
Avatar = "amphimpulse",
75-
DevLevel = DevLevel.CoreDeveloper,
76-
},
77-
new Account { Name = GlobalConst.NightwatchName, NewPasswordPlain = "dummy", IsBot = true, AdminLevel = AdminLevel.SuperAdmin});
78-
}
48+
db.Database.ExecuteSqlCommand($"truncate table {nameof(LogEntries)}");
49+
50+
if (GlobalConst.Mode == ModeType.Local) LocalSeed(db);
7951

8052
db.Resources.AddOrUpdate(x=>x.InternalName, new Resource()
8153
{
@@ -137,5 +109,36 @@ protected override void Seed(ZkDataContext db) {
137109
db.SaveChanges();
138110

139111
}
112+
113+
private static void LocalSeed(ZkDataContext db)
114+
{
115+
// fill local DB with some basic test data
116+
db.MiscVars.AddOrUpdate(x => x.VarName,
117+
new MiscVar { VarName = "NightwatchPassword", VarValue = "dummy" },
118+
new MiscVar { VarName = "GithubHookKey", VarValue = "secret" });
119+
120+
if (!db.MiscVars.Any(y => y.VarName == "SteamBuildPassword"))
121+
db.MiscVars.AddOrUpdate(x => x.VarName, new MiscVar { VarName = "SteamBuildPassword", VarValue = "secret" });
122+
123+
if (!db.MiscVars.Any(y => y.VarName == "GlacierSecretKey"))
124+
db.MiscVars.AddOrUpdate(x => x.VarName, new MiscVar { VarName = "GlacierSecretKey", VarValue = "secret" });
125+
126+
db.Accounts.AddOrUpdate(x => x.Name,
127+
new Account
128+
{
129+
Name = "TestPlayer",
130+
NewPasswordPlain = "test",
131+
AdminLevel = AdminLevel.SuperAdmin,
132+
Kudos = 200,
133+
Level = 255,
134+
Xp = 1325900,
135+
Rank = 3,
136+
Country = "cz",
137+
Avatar = "amphimpulse",
138+
DevLevel = DevLevel.CoreDeveloper,
139+
},
140+
new Account { Name = "test", NewPasswordPlain = "test", AdminLevel = AdminLevel.SuperAdmin, Kudos = 200, Level = 50, Country = "cz" },
141+
new Account { Name = GlobalConst.NightwatchName, NewPasswordPlain = "dummy", IsBot = true, AdminLevel = AdminLevel.SuperAdmin });
142+
}
140143
}
141144
}

ZkData/ZkData.csproj

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -336,9 +336,9 @@
336336
<Compile Include="Migrations\201712192204530_EloIsHistory.Designer.cs">
337337
<DependentUpon>201712192204530_EloIsHistory.cs</DependentUpon>
338338
</Compile>
339-
<Compile Include="Migrations\201712222344030_rank.cs" />
340-
<Compile Include="Migrations\201712222344030_rank.Designer.cs">
341-
<DependentUpon>201712222344030_rank.cs</DependentUpon>
339+
<Compile Include="Migrations\201712232154526_AddedSunRanks.cs" />
340+
<Compile Include="Migrations\201712232154526_AddedSunRanks.Designer.cs">
341+
<DependentUpon>201712232154526_AddedSunRanks.cs</DependentUpon>
342342
</Compile>
343343
<Compile Include="SpringFilesUnitsyncAttempt.cs" />
344344
<Compile Include="SteamWebApi.cs" />
@@ -660,8 +660,8 @@
660660
<EmbeddedResource Include="Migrations\201712192204530_EloIsHistory.resx">
661661
<DependentUpon>201712192204530_EloIsHistory.cs</DependentUpon>
662662
</EmbeddedResource>
663-
<EmbeddedResource Include="Migrations\201712222344030_rank.resx">
664-
<DependentUpon>201712222344030_rank.cs</DependentUpon>
663+
<EmbeddedResource Include="Migrations\201712232154526_AddedSunRanks.resx">
664+
<DependentUpon>201712232154526_AddedSunRanks.cs</DependentUpon>
665665
</EmbeddedResource>
666666
<EmbeddedResource Include="ZkDataResources.resx">
667667
<Generator>ResXFileCodeGenerator</Generator>

0 commit comments

Comments
 (0)