creation des tables
continuous-integration/drone/push Build is passing Details

pull/1/head
Loris PERRET 2 years ago
parent b9cd4fe9a1
commit 30c7fae3ff

@ -1,7 +1,18 @@
 
using System.ComponentModel.DataAnnotations.Schema;
namespace DataBase.Entity namespace DataBase.Entity
{ {
public class Chat public class Chat
{ {
public int chatId { get; set; }
public int sender { get; set; }
public int recipient { get; set; }
[ForeignKey("sender")]
public Player PlayerSender { get; set; }
[ForeignKey("recipient")]
public Player PlayerRecipient { get; set; }
} }
} }

@ -1,7 +1,21 @@
 
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace DataBase.Entity namespace DataBase.Entity
{ {
public class Game public class Game
{ {
public int gameId { get; set; }
public int durationGame { get; set; }
public int nbMaxEchanges { get; set; }
public int winner { get; set; }
public int loser { get; set; }
[ForeignKey("winner")]
public Player PlayerWinner { get; set; }
[ForeignKey("loser")]
public Player PlayerLoser { get; set; }
} }
} }

@ -1,7 +1,21 @@
 
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace DataBase.Entity namespace DataBase.Entity
{ {
public class Message public class Message
{ {
public int messageId { get; set; }
public string message { get; set; }
public TimeSpan timestamp { get; set; }
public int player { get; set; }
public int chat { get; set; }
[ForeignKey("player")]
public Player PlayerId { get; set; }
[ForeignKey("chat")]
public Chat ChatId { get; set; }
} }
} }

@ -1,7 +1,13 @@
 
using System.ComponentModel.DataAnnotations;
namespace DataBase.Entity namespace DataBase.Entity
{ {
public class Player public class Player
{ {
public int playerId { get; set; }
public string name { get; set; }
public int nbBallTouchTotal { get; set; }
public int timePlayed { get; set; }
} }
} }

@ -0,0 +1,179 @@
// <auto-generated />
using System;
using DataBase;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
#nullable disable
namespace DataBase.Migrations
{
[DbContext(typeof(PongDbContext))]
[Migration("20230216153344_initMigration")]
partial class initMigration
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder.HasAnnotation("ProductVersion", "7.0.3");
modelBuilder.Entity("DataBase.Entity.Chat", b =>
{
b.Property<int>("chatId")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<int>("recipient")
.HasColumnType("INTEGER");
b.Property<int>("sender")
.HasColumnType("INTEGER");
b.HasKey("chatId");
b.HasIndex("recipient");
b.HasIndex("sender");
b.ToTable("Chats");
});
modelBuilder.Entity("DataBase.Entity.Game", b =>
{
b.Property<int>("gameId")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<int>("durationGame")
.HasColumnType("INTEGER");
b.Property<int>("loser")
.HasColumnType("INTEGER");
b.Property<int>("nbMaxEchanges")
.HasColumnType("INTEGER");
b.Property<int>("winner")
.HasColumnType("INTEGER");
b.HasKey("gameId");
b.HasIndex("loser");
b.HasIndex("winner");
b.ToTable("Games");
});
modelBuilder.Entity("DataBase.Entity.Message", b =>
{
b.Property<int>("messageId")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<int>("chat")
.HasColumnType("INTEGER");
b.Property<string>("message")
.IsRequired()
.HasColumnType("TEXT");
b.Property<int>("player")
.HasColumnType("INTEGER");
b.Property<TimeSpan>("timestamp")
.HasColumnType("TEXT");
b.HasKey("messageId");
b.HasIndex("chat");
b.HasIndex("player");
b.ToTable("Messages");
});
modelBuilder.Entity("DataBase.Entity.Player", b =>
{
b.Property<int>("playerId")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("name")
.IsRequired()
.HasColumnType("TEXT");
b.Property<int>("nbBallTouchTotal")
.HasColumnType("INTEGER");
b.Property<int>("timePlayed")
.HasColumnType("INTEGER");
b.HasKey("playerId");
b.ToTable("Players");
});
modelBuilder.Entity("DataBase.Entity.Chat", b =>
{
b.HasOne("DataBase.Entity.Player", "PlayerRecipient")
.WithMany()
.HasForeignKey("recipient")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("DataBase.Entity.Player", "PlayerSender")
.WithMany()
.HasForeignKey("sender")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("PlayerRecipient");
b.Navigation("PlayerSender");
});
modelBuilder.Entity("DataBase.Entity.Game", b =>
{
b.HasOne("DataBase.Entity.Player", "PlayerLoser")
.WithMany()
.HasForeignKey("loser")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("DataBase.Entity.Player", "PlayerWinner")
.WithMany()
.HasForeignKey("winner")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("PlayerLoser");
b.Navigation("PlayerWinner");
});
modelBuilder.Entity("DataBase.Entity.Message", b =>
{
b.HasOne("DataBase.Entity.Chat", "ChatId")
.WithMany()
.HasForeignKey("chat")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("DataBase.Entity.Player", "PlayerId")
.WithMany()
.HasForeignKey("player")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("ChatId");
b.Navigation("PlayerId");
});
#pragma warning restore 612, 618
}
}
}

@ -0,0 +1,158 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace DataBase.Migrations
{
/// <inheritdoc />
public partial class initMigration : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Players",
columns: table => new
{
playerId = table.Column<int>(type: "INTEGER", nullable: false)
.Annotation("Sqlite:Autoincrement", true),
name = table.Column<string>(type: "TEXT", nullable: false),
nbBallTouchTotal = table.Column<int>(type: "INTEGER", nullable: false),
timePlayed = table.Column<int>(type: "INTEGER", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Players", x => x.playerId);
});
migrationBuilder.CreateTable(
name: "Chats",
columns: table => new
{
chatId = table.Column<int>(type: "INTEGER", nullable: false)
.Annotation("Sqlite:Autoincrement", true),
sender = table.Column<int>(type: "INTEGER", nullable: false),
recipient = table.Column<int>(type: "INTEGER", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Chats", x => x.chatId);
table.ForeignKey(
name: "FK_Chats_Players_recipient",
column: x => x.recipient,
principalTable: "Players",
principalColumn: "playerId",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_Chats_Players_sender",
column: x => x.sender,
principalTable: "Players",
principalColumn: "playerId",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "Games",
columns: table => new
{
gameId = table.Column<int>(type: "INTEGER", nullable: false)
.Annotation("Sqlite:Autoincrement", true),
durationGame = table.Column<int>(type: "INTEGER", nullable: false),
nbMaxEchanges = table.Column<int>(type: "INTEGER", nullable: false),
winner = table.Column<int>(type: "INTEGER", nullable: false),
loser = table.Column<int>(type: "INTEGER", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Games", x => x.gameId);
table.ForeignKey(
name: "FK_Games_Players_loser",
column: x => x.loser,
principalTable: "Players",
principalColumn: "playerId",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_Games_Players_winner",
column: x => x.winner,
principalTable: "Players",
principalColumn: "playerId",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "Messages",
columns: table => new
{
messageId = table.Column<int>(type: "INTEGER", nullable: false)
.Annotation("Sqlite:Autoincrement", true),
message = table.Column<string>(type: "TEXT", nullable: false),
timestamp = table.Column<TimeSpan>(type: "TEXT", nullable: false),
player = table.Column<int>(type: "INTEGER", nullable: false),
chat = table.Column<int>(type: "INTEGER", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Messages", x => x.messageId);
table.ForeignKey(
name: "FK_Messages_Chats_chat",
column: x => x.chat,
principalTable: "Chats",
principalColumn: "chatId",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_Messages_Players_player",
column: x => x.player,
principalTable: "Players",
principalColumn: "playerId",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateIndex(
name: "IX_Chats_recipient",
table: "Chats",
column: "recipient");
migrationBuilder.CreateIndex(
name: "IX_Chats_sender",
table: "Chats",
column: "sender");
migrationBuilder.CreateIndex(
name: "IX_Games_loser",
table: "Games",
column: "loser");
migrationBuilder.CreateIndex(
name: "IX_Games_winner",
table: "Games",
column: "winner");
migrationBuilder.CreateIndex(
name: "IX_Messages_chat",
table: "Messages",
column: "chat");
migrationBuilder.CreateIndex(
name: "IX_Messages_player",
table: "Messages",
column: "player");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "Games");
migrationBuilder.DropTable(
name: "Messages");
migrationBuilder.DropTable(
name: "Chats");
migrationBuilder.DropTable(
name: "Players");
}
}
}

Binary file not shown.

@ -1,13 +1,18 @@
using Microsoft.EntityFrameworkCore; using DataBase.Entity;
using Microsoft.EntityFrameworkCore;
namespace DataBase namespace DataBase
{ {
public class PongDbContext : DbContext public class PongDbContext : DbContext
{ {
DbSet<Player> Players { get; set; }
DbSet<Game> Games { get; set; }
DbSet<Message> Messages { get; set; }
DbSet<Chat> Chats { get; set; }
public PongDbContext() { } public PongDbContext() { }
public PongDbContext(DbContextOptions<PongDbContext> options) : base(options) { } public PongDbContext(DbContextOptions<PongDbContext> options) : base(options) { }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{ {
//base.OnConfiguring(optionsBuilder); //base.OnConfiguring(optionsBuilder);

@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DataBase
{
public class PongDbContextWithStub : PongDbContext
{
}
}
Loading…
Cancel
Save