-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #630 from area363/merge/110-to-main
Merge/110 to main
- Loading branch information
Showing
15 changed files
with
4,367 additions
and
182 deletions.
There are no files selected for viewing
385 changes: 216 additions & 169 deletions
385
NineChronicles.DataProvider.Executable/Commands/UserDataMigration.cs
Large diffs are not rendered by default.
Oops, something went wrong.
3,766 changes: 3,766 additions & 0 deletions
3,766
...ronicles.DataProvider.Executable/Migrations/20240214134559_ActivateCollection.Designer.cs
Large diffs are not rendered by default.
Oops, something went wrong.
85 changes: 85 additions & 0 deletions
85
NineChronicles.DataProvider.Executable/Migrations/20240214134559_ActivateCollection.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
using System; | ||
using Microsoft.EntityFrameworkCore.Metadata; | ||
using Microsoft.EntityFrameworkCore.Migrations; | ||
|
||
#nullable disable | ||
|
||
namespace NineChronicles.DataProvider.Executable.Migrations | ||
{ | ||
public partial class ActivateCollection : Migration | ||
{ | ||
protected override void Up(MigrationBuilder migrationBuilder) | ||
{ | ||
migrationBuilder.CreateTable( | ||
name: "ActivateCollections", | ||
columns: table => new | ||
{ | ||
Id = table.Column<int>(type: "int", nullable: false) | ||
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn), | ||
AvatarAddress = table.Column<string>(type: "varchar(255)", nullable: false) | ||
.Annotation("MySql:CharSet", "utf8mb4"), | ||
CollectionId = table.Column<int>(type: "int", nullable: false), | ||
ActionId = table.Column<string>(type: "longtext", nullable: false) | ||
.Annotation("MySql:CharSet", "utf8mb4"), | ||
BlockIndex = table.Column<long>(type: "bigint", nullable: false), | ||
CreatedAt = table.Column<DateTimeOffset>(type: "datetime(6)", nullable: false) | ||
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn) | ||
}, | ||
constraints: table => | ||
{ | ||
table.PrimaryKey("PK_ActivateCollections", x => x.Id); | ||
table.ForeignKey( | ||
name: "FK_ActivateCollections_Avatars_AvatarAddress", | ||
column: x => x.AvatarAddress, | ||
principalTable: "Avatars", | ||
principalColumn: "Address", | ||
onDelete: ReferentialAction.Cascade); | ||
}) | ||
.Annotation("MySql:CharSet", "utf8mb4"); | ||
|
||
migrationBuilder.CreateTable( | ||
name: "CollectionOptionModel", | ||
columns: table => new | ||
{ | ||
Id = table.Column<int>(type: "int", nullable: false) | ||
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn), | ||
StatType = table.Column<string>(type: "longtext", nullable: false) | ||
.Annotation("MySql:CharSet", "utf8mb4"), | ||
OperationType = table.Column<string>(type: "longtext", nullable: false) | ||
.Annotation("MySql:CharSet", "utf8mb4"), | ||
Value = table.Column<long>(type: "bigint", nullable: false), | ||
ActivateCollectionId = table.Column<int>(type: "int", nullable: false) | ||
}, | ||
constraints: table => | ||
{ | ||
table.PrimaryKey("PK_CollectionOptionModel", x => x.Id); | ||
table.ForeignKey( | ||
name: "FK_CollectionOptionModel_ActivateCollections_ActivateCollection~", | ||
column: x => x.ActivateCollectionId, | ||
principalTable: "ActivateCollections", | ||
principalColumn: "Id", | ||
onDelete: ReferentialAction.Cascade); | ||
}) | ||
.Annotation("MySql:CharSet", "utf8mb4"); | ||
|
||
migrationBuilder.CreateIndex( | ||
name: "IX_ActivateCollections_AvatarAddress", | ||
table: "ActivateCollections", | ||
column: "AvatarAddress"); | ||
|
||
migrationBuilder.CreateIndex( | ||
name: "IX_CollectionOptionModel_ActivateCollectionId", | ||
table: "CollectionOptionModel", | ||
column: "ActivateCollectionId"); | ||
} | ||
|
||
protected override void Down(MigrationBuilder migrationBuilder) | ||
{ | ||
migrationBuilder.DropTable( | ||
name: "CollectionOptionModel"); | ||
|
||
migrationBuilder.DropTable( | ||
name: "ActivateCollections"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
NineChronicles.DataProvider.Tests/ActivateCollectionTest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Data; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using Libplanet.Action.State; | ||
using Libplanet.Crypto; | ||
using Microsoft.EntityFrameworkCore; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Nekoyume.Model.Stat; | ||
using NineChronicles.DataProvider.Store; | ||
using NineChronicles.DataProvider.Store.Models; | ||
using Xunit; | ||
|
||
namespace NineChronicles.DataProvider.Tests; | ||
|
||
public class ActivateCollectionTest : TestBase | ||
{ | ||
|
||
[Fact] | ||
public void RelationShip() | ||
{ | ||
var avatarAddress = new PrivateKey().Address; | ||
var provider = Services.BuildServiceProvider(); | ||
var store = provider.GetRequiredService<MySqlStore>(); | ||
store.StoreAgent(avatarAddress); | ||
var now = DateTimeOffset.UtcNow; | ||
store.StoreAvatar(avatarAddress, avatarAddress, "name", now, 1, null, null, 0); | ||
var avatar = store.GetAvatar(avatarAddress, true); | ||
var actionId = Guid.NewGuid().ToString(); | ||
for (int i = 0; i < 2; i++) | ||
{ | ||
var modifiers = new List<StatModifier> | ||
{ | ||
new StatModifier(StatType.HP, StatModifier.OperationType.Add, 1L), | ||
new StatModifier(StatType.HP, StatModifier.OperationType.Percentage, 1L) | ||
}; | ||
var options = new List<CollectionOptionModel>(); | ||
var collection = new ActivateCollectionModel | ||
{ | ||
Avatar = avatar, | ||
CollectionId = 1 + i, | ||
BlockIndex = 1L + i, | ||
ActionId = actionId, | ||
Options = options, | ||
}; | ||
foreach (var modifier in modifiers) | ||
{ | ||
options.Add(new CollectionOptionModel | ||
{ | ||
Value = modifier.Value, | ||
OperationType = modifier.Operation.ToString(), | ||
StatType = modifier.StatType.ToString(), | ||
}); | ||
} | ||
avatar.ActivateCollections.Add(collection); | ||
} | ||
|
||
store.UpdateAvatar(avatar); | ||
Assert.Equal(2, Context.Avatars!.Include(avatarModel => avatarModel.ActivateCollections).First().ActivateCollections.Count); | ||
Assert.Equal(2, Context.ActivateCollections.Count(p => p.ActionId == actionId)); | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
CleanUp(); | ||
} | ||
|
||
protected override IWorldState GetMockState() | ||
{ | ||
return new MockWorldState(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.