Adeed base database build

This commit is contained in:
Samuele Lorefice
2023-11-07 01:47:56 +01:00
parent 1fe234914d
commit 57ddbbf115
13 changed files with 532 additions and 121 deletions

View File

@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="DataSourceManagerImpl" format="xml" multifile-model="true">
<data-source source="LOCAL" name="database.db" uuid="6d446c21-8139-4055-91bb-4f1450f6ae4a">
<driver-ref>sqlite.xerial</driver-ref>
<synchronize>true</synchronize>
<jdbc-driver>org.sqlite.JDBC</jdbc-driver>
<jdbc-url>jdbc:sqlite:$PROJECT_DIR$/database.db</jdbc-url>
<working-dir>$ProjectFileDir$</working-dir>
</data-source>
</component>
</project>

View File

@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="EfCoreCommonOptions">
<option name="solutionLevelOptions">
<map>
<entry key="migrationsProject" value="86009aaf-9139-4b36-97ff-8531e01209b4" />
<entry key="startupProject" value="86009aaf-9139-4b36-97ff-8531e01209b4" />
</map>
</option>
</component>
</project>

View File

@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="EfCoreDialogsState">
<option name="keyValueStorage">
<map>
<entry key="Common:86009aaf-9139-4b36-97ff-8531e01209b4:dbContext" value="IsleBot.DbManager" />
<entry key="Common:buildConfiguration" value="Debug" />
<entry key="Common:noBuild" value="false" />
<entry key="Common:outputFolder" value="Migrations" />
<entry key="Common:useDefaultConnection" value="true" />
</map>
</option>
</component>
</project>

View File

@@ -1,111 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="AutoGeneratedRunConfigurationManager">
<projectFile>IsleBotSharp.csproj</projectFile>
</component>
<component name="AutoImportSettings">
<option name="autoReloadType" value="SELECTIVE" />
</component>
<component name="ChangeListManager">
<list default="true" id="79ad02fc-d6b5-4413-931b-52fb76129e49" name="Changes" comment="">
<change beforePath="$PROJECT_DIR$/.gitignore" beforeDir="false" afterPath="$PROJECT_DIR$/.gitignore" afterDir="false" />
<change beforePath="$PROJECT_DIR$/config.json" beforeDir="false" afterPath="$PROJECT_DIR$/config.json" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
<option name="LAST_RESOLUTION" value="IGNORE" />
</component>
<component name="Git.Settings">
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
</component>
<component name="HighlightingSettingsPerFile">
<setting file="file://$APPLICATION_CONFIG_DIR$/resharper-host/SourcesCache/3d5314c4b5f391de6f26e7ce0d430d6d2aa1d7a44530b874fdbb1a4a97374/File.cs" root0="SKIP_HIGHLIGHTING" />
<setting file="file://$APPLICATION_CONFIG_DIR$/resharper-host/SourcesCache/bd1d5c50194fea68ff3559c160230b0ab50f5acf4ce3061bffd6d62958e2182/ExceptionDispatchInfo.cs" root0="SKIP_HIGHLIGHTING" />
<setting file="file://$PROJECT_DIR$/DbManager.cs" root0="FORCE_HIGHLIGHTING" />
<setting file="file://$PROJECT_DIR$/EStatus.cs" root0="FORCE_HIGHLIGHTING" />
<setting file="file://$PROJECT_DIR$/Match.cs" root0="FORCE_HIGHLIGHTING" />
<setting file="file://$PROJECT_DIR$/Program.cs" root0="FORCE_HIGHLIGHTING" />
</component>
<component name="ProjectColorInfo">{
&quot;associatedIndex&quot;: 8
}</component>
<component name="ProjectId" id="2XlSZhdO6OtLGbtDTHRVgKGj55t" />
<component name="ProjectViewState">
<option name="hideEmptyMiddlePackages" value="true" />
<option name="showLibraryContents" value="true" />
</component>
<component name="PropertiesComponent"><![CDATA[{
"keyToString": {
"ASKED_SHARE_PROJECT_CONFIGURATION_FILES": "true",
"RunOnceActivity.OpenProjectViewOnStart": "true",
"RunOnceActivity.ShowReadmeOnStart": "true",
"SHARE_PROJECT_CONFIGURATION_FILES": "true",
"WebServerToolWindowFactoryState": "false",
"git-widget-placeholder": "feature/dbImpl",
"node.js.detected.package.eslint": "true",
"node.js.detected.package.tslint": "true",
"node.js.selected.package.eslint": "(autodetect)",
"node.js.selected.package.tslint": "(autodetect)",
"settings.editor.selected.configurable": "preferences.sourceCode.C#",
"vue.rearranger.settings.migration": "true"
},
"keyToStringList": {
"rider.external.source.directories": [
"C:\\Users\\airon\\AppData\\Roaming\\JetBrains\\Rider2023.2\\resharper-host\\DecompilerCache",
"C:\\Users\\airon\\AppData\\Roaming\\JetBrains\\Rider2023.2\\resharper-host\\SourcesCache",
"C:\\Users\\airon\\AppData\\Local\\Symbols\\src"
]
}
}]]></component>
<component name="RunManager">
<configuration name="IsleBotSharp" type="DotNetProject" factoryName=".NET Project">
<option name="EXE_PATH" value="" />
<option name="PROGRAM_PARAMETERS" value="" />
<option name="WORKING_DIRECTORY" value="" />
<option name="PASS_PARENT_ENVS" value="1" />
<option name="USE_EXTERNAL_CONSOLE" value="0" />
<option name="USE_MONO" value="0" />
<option name="RUNTIME_ARGUMENTS" value="" />
<option name="PROJECT_PATH" value="$PROJECT_DIR$/IsleBot.csproj" />
<option name="PROJECT_EXE_PATH_TRACKING" value="1" />
<option name="PROJECT_ARGUMENTS_TRACKING" value="1" />
<option name="PROJECT_WORKING_DIRECTORY_TRACKING" value="1" />
<option name="PROJECT_KIND" value="DotNetCore" />
<option name="PROJECT_TFM" value="" />
<method v="2">
<option name="Build" />
</method>
</configuration>
</component>
<component name="SpellCheckerSettings" RuntimeDictionaries="0" Folders="0" CustomDictionaries="0" DefaultDictionary="application-level" UseSingleDictionary="true" transferred="true" />
<component name="TaskManager">
<task active="true" id="Default" summary="Default task">
<changelist id="79ad02fc-d6b5-4413-931b-52fb76129e49" name="Changes" comment="" />
<created>1699202233917</created>
<option name="number" value="Default" />
<option name="presentableId" value="Default" />
<updated>1699202233917</updated>
<workItem from="1699202234933" duration="14451000" />
<workItem from="1699298781898" duration="889000" />
</task>
<servers />
</component>
<component name="TypeScriptGeneratedFilesManager">
<option name="version" value="3" />
</component>
<component name="Vcs.Log.Tabs.Properties">
<option name="TAB_STATES">
<map>
<entry key="MAIN">
<value>
<State />
</value>
</entry>
</map>
</option>
</component>
<component name="VcsManagerConfiguration">
<option name="CLEAR_INITIAL_COMMIT_MESSAGE" value="true" />
</component>
</project>

11
Card.cs
View File

@@ -1,12 +1,17 @@
namespace IsleBot; using System.ComponentModel.DataAnnotations.Schema;
using Microsoft.EntityFrameworkCore;
public class Card namespace IsleBot;
{
public class Card {
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int Id { get; set; }
public string Name { get; set; } public string Name { get; set; }
public int Attack { get; set; } public int Attack { get; set; }
public int Defense { get; set; } public int Defense { get; set; }
public int MaxHealth { get; set; } public int MaxHealth { get; set; }
public int CurrentHealth { get; set; } public int CurrentHealth { get; set; }
public User Owner { get; set; }
public override string ToString() { public override string ToString() {
return $"{Name} ATK: {Attack} DEF: {Defense} HP: {CurrentHealth}/{MaxHealth}"; return $"{Name} ATK: {Attack} DEF: {Defense} HP: {CurrentHealth}/{MaxHealth}";

View File

@@ -18,4 +18,5 @@ public class DbManager : DbContext {
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
=> optionsBuilder.UseSqlite($"Data Source={dbpath}"); => optionsBuilder.UseSqlite($"Data Source={dbpath}");
} }

View File

@@ -10,6 +10,10 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="Discord.Net" Version="3.12.0" /> <PackageReference Include="Discord.Net" Version="3.12.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.13" /> <PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.13" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.13">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="7.0.13" /> <PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="7.0.13" />
</ItemGroup> </ItemGroup>
@@ -17,6 +21,9 @@
<None Update="config.json"> <None Update="config.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None> </None>
<None Update="database.db">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

@@ -1,17 +1,38 @@
using Microsoft.EntityFrameworkCore; using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.Serialization;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Internal;
namespace IsleBot; namespace IsleBot;
public class Match { public class Match {
public int MatchId { get; set; } [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
[DataMember(IsRequired = true)]
public int Id { get; set; }
[ForeignKey("PlayerAId"), Column(Order = 1)]
public User PlayerA { get; set; } public User PlayerA { get; set; }
[ForeignKey("PlayerACardId"), Column(Order = 2)]
public Card PlayerACard { get; set; } public Card PlayerACard { get; set; }
[ForeignKey("PlayerBId"), Column(Order=3)]
public User PlayerB { get; set; } public User PlayerB { get; set; }
[ForeignKey("PlayerBCardId"), Column(Order=4)]
public Card PlayerBCard { get; set; } public Card PlayerBCard { get; set; }
public int PlayedTurns { get; set; } public int PlayedTurns { get; set; }
public EStatus Status { get; set; } public EStatus Status { get; set; }
public Match() { } //required for EFCore build
public Match(User playerA, User playerB, Card playerACard, Card playerBCard) {
PlayerA = playerA;
PlayerB = playerB;
PlayerACard = playerACard;
PlayerBCard = playerBCard;
PlayedTurns = 0;
Status = EStatus.NotStarted;
}
} }

View File

@@ -0,0 +1,159 @@
// <auto-generated />
using IsleBot;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
#nullable disable
namespace IsleBot.Migrations
{
[DbContext(typeof(DbManager))]
[Migration("20231107003428_Initial")]
partial class Initial
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder.HasAnnotation("ProductVersion", "7.0.13");
modelBuilder.Entity("IsleBot.Card", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<int>("Attack")
.HasColumnType("INTEGER");
b.Property<int>("CurrentHealth")
.HasColumnType("INTEGER");
b.Property<int>("Defense")
.HasColumnType("INTEGER");
b.Property<int>("MaxHealth")
.HasColumnType("INTEGER");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("TEXT");
b.Property<int>("OwnerId")
.HasColumnType("INTEGER");
b.HasKey("Id");
b.HasIndex("OwnerId");
b.ToTable("Cards");
});
modelBuilder.Entity("IsleBot.Match", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<int>("PlayedTurns")
.HasColumnType("INTEGER");
b.Property<int>("PlayerACardId")
.HasColumnType("INTEGER");
b.Property<int>("PlayerAId")
.HasColumnType("INTEGER");
b.Property<int>("PlayerBCardId")
.HasColumnType("INTEGER");
b.Property<int>("PlayerBId")
.HasColumnType("INTEGER");
b.Property<int>("Status")
.HasColumnType("INTEGER");
b.HasKey("Id");
b.HasIndex("PlayerACardId");
b.HasIndex("PlayerAId");
b.HasIndex("PlayerBCardId");
b.HasIndex("PlayerBId");
b.ToTable("Matches");
});
modelBuilder.Entity("IsleBot.User", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("UserName")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("Id");
b.ToTable("Players");
});
modelBuilder.Entity("IsleBot.Card", b =>
{
b.HasOne("IsleBot.User", "Owner")
.WithMany("Cards")
.HasForeignKey("OwnerId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Owner");
});
modelBuilder.Entity("IsleBot.Match", b =>
{
b.HasOne("IsleBot.Card", "PlayerACard")
.WithMany()
.HasForeignKey("PlayerACardId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("IsleBot.User", "PlayerA")
.WithMany()
.HasForeignKey("PlayerAId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("IsleBot.Card", "PlayerBCard")
.WithMany()
.HasForeignKey("PlayerBCardId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("IsleBot.User", "PlayerB")
.WithMany()
.HasForeignKey("PlayerBId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("PlayerA");
b.Navigation("PlayerACard");
b.Navigation("PlayerB");
b.Navigation("PlayerBCard");
});
modelBuilder.Entity("IsleBot.User", b =>
{
b.Navigation("Cards");
});
#pragma warning restore 612, 618
}
}
}

View File

@@ -0,0 +1,131 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace IsleBot.Migrations
{
/// <inheritdoc />
public partial class Initial : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Players",
columns: table => new
{
Id = table.Column<int>(type: "INTEGER", nullable: false)
.Annotation("Sqlite:Autoincrement", true),
UserName = table.Column<string>(type: "TEXT", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Players", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Cards",
columns: table => new
{
Id = table.Column<int>(type: "INTEGER", nullable: false)
.Annotation("Sqlite:Autoincrement", true),
Name = table.Column<string>(type: "TEXT", nullable: false),
Attack = table.Column<int>(type: "INTEGER", nullable: false),
Defense = table.Column<int>(type: "INTEGER", nullable: false),
MaxHealth = table.Column<int>(type: "INTEGER", nullable: false),
CurrentHealth = table.Column<int>(type: "INTEGER", nullable: false),
OwnerId = table.Column<int>(type: "INTEGER", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Cards", x => x.Id);
table.ForeignKey(
name: "FK_Cards_Players_OwnerId",
column: x => x.OwnerId,
principalTable: "Players",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "Matches",
columns: table => new
{
Id = table.Column<int>(type: "INTEGER", nullable: false)
.Annotation("Sqlite:Autoincrement", true),
PlayerAId = table.Column<int>(type: "INTEGER", nullable: false),
PlayerACardId = table.Column<int>(type: "INTEGER", nullable: false),
PlayerBId = table.Column<int>(type: "INTEGER", nullable: false),
PlayerBCardId = table.Column<int>(type: "INTEGER", nullable: false),
PlayedTurns = table.Column<int>(type: "INTEGER", nullable: false),
Status = table.Column<int>(type: "INTEGER", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Matches", x => x.Id);
table.ForeignKey(
name: "FK_Matches_Cards_PlayerACardId",
column: x => x.PlayerACardId,
principalTable: "Cards",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_Matches_Cards_PlayerBCardId",
column: x => x.PlayerBCardId,
principalTable: "Cards",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_Matches_Players_PlayerAId",
column: x => x.PlayerAId,
principalTable: "Players",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_Matches_Players_PlayerBId",
column: x => x.PlayerBId,
principalTable: "Players",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateIndex(
name: "IX_Cards_OwnerId",
table: "Cards",
column: "OwnerId");
migrationBuilder.CreateIndex(
name: "IX_Matches_PlayerACardId",
table: "Matches",
column: "PlayerACardId");
migrationBuilder.CreateIndex(
name: "IX_Matches_PlayerAId",
table: "Matches",
column: "PlayerAId");
migrationBuilder.CreateIndex(
name: "IX_Matches_PlayerBCardId",
table: "Matches",
column: "PlayerBCardId");
migrationBuilder.CreateIndex(
name: "IX_Matches_PlayerBId",
table: "Matches",
column: "PlayerBId");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "Matches");
migrationBuilder.DropTable(
name: "Cards");
migrationBuilder.DropTable(
name: "Players");
}
}
}

View File

@@ -0,0 +1,156 @@
// <auto-generated />
using IsleBot;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
#nullable disable
namespace IsleBot.Migrations
{
[DbContext(typeof(DbManager))]
partial class DbManagerModelSnapshot : ModelSnapshot
{
protected override void BuildModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder.HasAnnotation("ProductVersion", "7.0.13");
modelBuilder.Entity("IsleBot.Card", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<int>("Attack")
.HasColumnType("INTEGER");
b.Property<int>("CurrentHealth")
.HasColumnType("INTEGER");
b.Property<int>("Defense")
.HasColumnType("INTEGER");
b.Property<int>("MaxHealth")
.HasColumnType("INTEGER");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("TEXT");
b.Property<int>("OwnerId")
.HasColumnType("INTEGER");
b.HasKey("Id");
b.HasIndex("OwnerId");
b.ToTable("Cards");
});
modelBuilder.Entity("IsleBot.Match", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<int>("PlayedTurns")
.HasColumnType("INTEGER");
b.Property<int>("PlayerACardId")
.HasColumnType("INTEGER");
b.Property<int>("PlayerAId")
.HasColumnType("INTEGER");
b.Property<int>("PlayerBCardId")
.HasColumnType("INTEGER");
b.Property<int>("PlayerBId")
.HasColumnType("INTEGER");
b.Property<int>("Status")
.HasColumnType("INTEGER");
b.HasKey("Id");
b.HasIndex("PlayerACardId");
b.HasIndex("PlayerAId");
b.HasIndex("PlayerBCardId");
b.HasIndex("PlayerBId");
b.ToTable("Matches");
});
modelBuilder.Entity("IsleBot.User", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("UserName")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("Id");
b.ToTable("Players");
});
modelBuilder.Entity("IsleBot.Card", b =>
{
b.HasOne("IsleBot.User", "Owner")
.WithMany("Cards")
.HasForeignKey("OwnerId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Owner");
});
modelBuilder.Entity("IsleBot.Match", b =>
{
b.HasOne("IsleBot.Card", "PlayerACard")
.WithMany()
.HasForeignKey("PlayerACardId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("IsleBot.User", "PlayerA")
.WithMany()
.HasForeignKey("PlayerAId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("IsleBot.Card", "PlayerBCard")
.WithMany()
.HasForeignKey("PlayerBCardId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("IsleBot.User", "PlayerB")
.WithMany()
.HasForeignKey("PlayerBId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("PlayerA");
b.Navigation("PlayerACard");
b.Navigation("PlayerB");
b.Navigation("PlayerBCard");
});
modelBuilder.Entity("IsleBot.User", b =>
{
b.Navigation("Cards");
});
#pragma warning restore 612, 618
}
}
}

11
User.cs
View File

@@ -1,11 +1,16 @@
namespace IsleBot; using System.Runtime.Serialization;
public class User namespace IsleBot;
{
public class User {
[DataMember(IsRequired = true)]
public int Id { get; private set; } public int Id { get; private set; }
public string UserName { get; set; } public string UserName { get; set; }
public List<Card> Cards { get; set; } public List<Card> Cards { get; set; }
//public List<Match> Matches { get; set; }
public User(int id, string userName) { public User(int id, string userName) {
Id = id; Id = id;
UserName = userName; UserName = userName;

BIN
database.db Normal file

Binary file not shown.