Cache the Challonge results

This commit is contained in:
2019-08-06 01:56:33 +02:00
parent b4f9a0a132
commit a9f3da1b8e
13 changed files with 334 additions and 90 deletions

View File

@@ -6,6 +6,7 @@ namespace LaDOSE.DTO
public class TournamentDTO public class TournamentDTO
{ {
public int Id { get; set; } public int Id { get; set; }
public int ChallongeId { get; set; }
public string Name { get; set; } public string Name { get; set; }
public string Game { get; set; } public string Game { get; set; }
public List<ParticipentDTO> Participents {get;set;} public List<ParticipentDTO> Participents {get;set;}
@@ -14,6 +15,7 @@ namespace LaDOSE.DTO
public class ParticipentDTO public class ParticipentDTO
{ {
public int Id { get; set; } public int Id { get; set; }
public int ChallongeId { get; set; }
public string Name { get; set; } public string Name { get; set; }
public int Rank { get; set; } public int Rank { get; set; }
public bool? IsMember{ get; set; } public bool? IsMember{ get; set; }

View File

@@ -206,7 +206,7 @@ namespace LaDOSE.DesktopApp.ViewModels
{ {
WpfUtil.Await(() => WpfUtil.Await(() =>
{ {
var tournamentsIds = SelectedTournaments.Select(e => e.Id).ToList(); var tournamentsIds = SelectedTournaments.Select(e => e.ChallongeId).ToList();
var resultsDto = this.RestService.GetResults(tournamentsIds); var resultsDto = this.RestService.GetResults(tournamentsIds);
this.Results = resultsDto; this.Results = resultsDto;
ComputeDataGrid(); ComputeDataGrid();

View File

@@ -0,0 +1,16 @@
using System.Collections.Generic;
namespace LaDOSE.Entity.Challonge
{
public class ChallongeParticipent : Context.Entity
{
public ChallongeTournament ChallongeTournament { get; set; }
public int ChallongeTournamentId { get; set; }
public int ChallongeId { get; set; }
public string Name { get; set; }
public int? Rank { get; set; }
public bool? IsMember { get; set; }
}
}

View File

@@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
namespace LaDOSE.Entity.Challonge
{
public class ChallongeTournament : Context.Entity
{
public int ChallongeId { get; set; }
public string Name { get; set; }
public Game Game { get; set; }
public List<ChallongeParticipent> Participents { get; set; }
public string Url { get; set; }
public DateTime Sync { get; set; }
}
}

View File

@@ -1,10 +0,0 @@
namespace LaDOSE.Entity.Challonge
{
public class Participent
{
public int Id { get; set; }
public string Name { get; set; }
public int? Rank { get; set; }
public bool? IsMember { get; set; }
}
}

View File

@@ -1,13 +0,0 @@
using System.Collections.Generic;
namespace LaDOSE.Entity.Challonge
{
public class Tournament
{
public int Id { get; set; }
public string Name { get; set; }
public Game Game { get; set; }
public List<Participent> Participents { get; set; }
public string Url { get; set; }
}
}

View File

@@ -5,7 +5,7 @@ namespace LaDOSE.Entity.Challonge
{ {
public class TournamentsResult public class TournamentsResult
{ {
public List<Participent> Participents { get; set; } public List<ChallongeParticipent> Participents { get; set; }
public List<Game> Games{ get; set; } public List<Game> Games{ get; set; }
public List<Result> Results { get; set; } public List<Result> Results { get; set; }

View File

@@ -1,4 +1,5 @@
using LaDOSE.Entity.Wordpress; using LaDOSE.Entity.Challonge;
using LaDOSE.Entity.Wordpress;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
namespace LaDOSE.Entity.Context namespace LaDOSE.Entity.Context
@@ -20,6 +21,8 @@ namespace LaDOSE.Entity.Context
#endregion #endregion
public DbSet<SeasonGame> SeasonGame { get; set; } public DbSet<SeasonGame> SeasonGame { get; set; }
public DbSet<EventGame> EventGame { get; set; } public DbSet<EventGame> EventGame { get; set; }
public DbSet<ChallongeParticipent> ChallongeParticipent { get; set; }
public DbSet<ChallongeTournament> ChallongeTournament { get; set; }
public LaDOSEDbContext(DbContextOptions options) : base(options) public LaDOSEDbContext(DbContextOptions options) : base(options)
{ {
@@ -87,6 +90,12 @@ namespace LaDOSE.Entity.Context
.HasForeignKey(pt => pt.WPUserId); .HasForeignKey(pt => pt.WPUserId);
#endregion #endregion
#region Challonge
modelBuilder.Entity<ChallongeParticipent>()
.HasOne(pt => pt.ChallongeTournament)
.WithMany(p => p.Participents)
.HasForeignKey(pt => pt.ChallongeTournamentId);
#endregion
} }
} }

View File

@@ -13,9 +13,9 @@ namespace LaDOSE.Business.Interface
Task<TournamentResult> CreateTournament(string name, string url, DateTime? startAt); Task<TournamentResult> CreateTournament(string name, string url, DateTime? startAt);
Task<ParticipantResult> AddPlayer(int tournamentId, string userName); Task<ParticipantResult> AddPlayer(int tournamentId, string userName);
Task<List<Tournament>> GetTournaments(DateTime? start, DateTime? end); Task<List<ChallongeTournament>> GetTournaments(DateTime? start, DateTime? end);
Task<List<Participent>> GetParticipents(int idTournament); Task<List<ChallongeParticipent>> GetParticipents(int idTournament);
Task<Tournament> GetTournament(int idTournament); Task<ChallongeTournament> GetTournament(int idTournament);
Task<Tournament> GetTournament(string urlTournament); Task<ChallongeTournament> GetTournament(string urlTournament);
} }
} }

View File

@@ -7,7 +7,7 @@ namespace LaDOSE.Business.Interface
{ {
public interface ITournamentService public interface ITournamentService
{ {
Task<List<Tournament>> GetTournaments(DateTime? start, DateTime? end); Task<List<ChallongeTournament>> GetTournaments(DateTime? start, DateTime? end);
Task<TournamentsResult> GetTournamentsResult(List<int> ids); Task<TournamentsResult> GetTournamentsResult(List<int> ids);
} }

View File

@@ -46,7 +46,7 @@ namespace LaDOSE.Business.Provider
} }
public async Task<List<Tournament>> GetTournaments(DateTime? start, DateTime? end) public async Task<List<ChallongeTournament>> GetTournaments(DateTime? start, DateTime? end)
{ {
List<TournamentResult> tournamentResultList = await new TournamentsQuery() List<TournamentResult> tournamentResultList = await new TournamentsQuery()
@@ -58,28 +58,29 @@ namespace LaDOSE.Business.Provider
} }
.call(this.ApiCaller); .call(this.ApiCaller);
List<Tournament> tournaments = new List<Tournament>(); List<ChallongeTournament> tournaments = new List<ChallongeTournament>();
tournamentResultList.ForEach(w => tournaments.Add(new Tournament() tournamentResultList.ForEach(w => tournaments.Add(new ChallongeTournament()
{ {
Id = w.id, ChallongeId = w.id,
Name = w.name, Name = w.name,
Participents = new List<Participent>() Participents = new List<ChallongeParticipent>()
})); }));
return tournaments; return tournaments;
} }
public async Task<List<Participent>> GetParticipents(int idTournament) public async Task<List<ChallongeParticipent>> GetParticipents(int idTournament)
{ {
var participentResults = await new ParticipantsQuery(){tournamentID = idTournament }.call(ApiCaller); var participentResults = await new ParticipantsQuery(){tournamentID = idTournament }.call(ApiCaller);
List<Participent> participants = new List<Participent>(); List<ChallongeParticipent> participants = new List<ChallongeParticipent>();
participentResults.ForEach(w => participentResults.ForEach(w =>
{ {
if (w.active) if (w.active)
{ {
participants.Add(new Participent() participants.Add(new ChallongeParticipent()
{ {
Id = w.id, ChallongeTournamentId = idTournament,
ChallongeId = w.id,
Name = w.name, Name = w.name,
Rank = w.final_rank, Rank = w.final_rank,
IsMember = false, IsMember = false,
@@ -90,32 +91,32 @@ namespace LaDOSE.Business.Provider
return participants; return participants;
} }
public async Task<Tournament> GetTournament(int idTournament) public async Task<ChallongeTournament> GetTournament(int idTournament)
{ {
var tournamentResult = await new TournamentQuery(idTournament).call(ApiCaller); var tournamentResult = await new TournamentQuery(idTournament).call(ApiCaller);
return new Tournament() return new ChallongeTournament()
{ {
Id = tournamentResult.id, ChallongeId = tournamentResult.id,
Name = tournamentResult.name, Name = tournamentResult.name,
Url = tournamentResult.url, Url = tournamentResult.url,
Participents = new List<Participent>() Participents = new List<ChallongeParticipent>()
}; };
} }
public async Task<Tournament> GetTournament(string urlTournament) public async Task<ChallongeTournament> GetTournament(string urlTournament)
{ {
var tournamentResult = await new TournamentQuery(urlTournament).call(ApiCaller); var tournamentResult = await new TournamentQuery(urlTournament).call(ApiCaller);
return new Tournament() return new ChallongeTournament()
{ {
Id = tournamentResult.id, ChallongeId = tournamentResult.id,
Name = tournamentResult.name, Name = tournamentResult.name,
Url = tournamentResult.url, Url = tournamentResult.url,
Participents = new List<Participent>() Participents = new List<ChallongeParticipent>()
}; };

View File

@@ -3,15 +3,20 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using LaDOSE.Business.Interface; using LaDOSE.Business.Interface;
using LaDOSE.Entity;
using LaDOSE.Entity.Challonge; using LaDOSE.Entity.Challonge;
using LaDOSE.Entity.Context; using LaDOSE.Entity.Context;
using LaDOSE.Entity.Wordpress; using LaDOSE.Entity.Wordpress;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Internal; using Microsoft.EntityFrameworkCore.Internal;
namespace LaDOSE.Business.Service namespace LaDOSE.Business.Service
{ {
public class TournamentService : ITournamentService public class TournamentService : BaseService<ChallongeTournament>,ITournamentService
{ {
private IChallongeProvider _challongeProvider;
#region Rules
private class Rules private class Rules
{ {
public int PlayerMin { get; set; } public int PlayerMin { get; set; }
@@ -37,9 +42,7 @@ namespace LaDOSE.Business.Service
} }
} }
private LaDOSEDbContext _context; //Rules Definitions (Min Players,Max Players,First Reward,Second Reward,Third / Fourth Reward, Top 8 reward, Top 16 Reward
private IChallongeProvider _challongeProvider;
private List<Rules> TournamentRules = new List<Rules>() private List<Rules> TournamentRules = new List<Rules>()
{ {
new Rules(0, 8, 5, 3, 2, 0, 0), new Rules(0, 8, 5, 3, 2, 0, 0),
@@ -47,59 +50,51 @@ namespace LaDOSE.Business.Service
new Rules(16, 32, 12, 8, 5, 3, 2), new Rules(16, 32, 12, 8, 5, 3, 2),
new Rules(32, Int32.MaxValue, 18, 12, 8, 5, 3), new Rules(32, Int32.MaxValue, 18, 12, 8, 5, 3),
}; };
#endregion
public TournamentService(LaDOSEDbContext context, IChallongeProvider challongeProvider) public TournamentService(LaDOSEDbContext context, IChallongeProvider challongeProvider) : base(context)
{ {
this._context = context; this._context = context;
this._challongeProvider = challongeProvider; this._challongeProvider = challongeProvider;
} }
public async Task<List<Tournament>> GetTournaments(DateTime? start, DateTime? end) public async Task<List<ChallongeTournament>> GetTournaments(DateTime? start, DateTime? end)
{ {
List<WPUser> wpUsers = _context.WPUser.ToList(); return await _challongeProvider.GetTournaments(start, end);
var tournaments = await _challongeProvider.GetTournaments(start, end); //Useless
//foreach (var tournament in tournaments)
foreach (var tournament in tournaments) //{
{ // List<ChallongeParticipent> participents = await _challongeProvider.GetParticipents(tournament.ChallongeId);
List<Participent> participents = await _challongeProvider.GetParticipents(tournament.Id); // tournament.Participents = participents;
tournament.Participents = participents; //}
}
return tournaments;
} }
public async Task<TournamentsResult> GetTournamentsResult(List<int> ids) public async Task<TournamentsResult> GetTournamentsResult(List<int> ids)
{ {
TournamentsResult result = new TournamentsResult(); TournamentsResult result = new TournamentsResult();
result.Results = new List<Result>(); result.Results = new List<Result>();
var tournaments = new List<Tournament>();
foreach (var idTournament in ids)
{
var tournament = await _challongeProvider.GetTournament(idTournament);
tournament.Participents = await _challongeProvider.GetParticipents(tournament.Id);
tournaments.Add(tournament);
}
var games = _context.Game.ToList();
var players = _context.WPUser.ToList(); var players = _context.WPUser.ToList();
var games = _context.Game.ToList();
var tournaments = await GetChallongeTournaments(ids,games);
var allParticipent = tournaments.SelectMany(e => e.Participents).Distinct((a, b) => a.Name == b.Name) var allParticipent = tournaments.SelectMany(e => e.Participents).Distinct((a, b) => a.Name == b.Name)
.ToList(); .ToList();
foreach (var participent in allParticipent)
{ //USELESS
var player = players.FirstOrDefault(e => e.Name.Contains(participent.Name)); //foreach (var participent in allParticipent)
if (player != null) //{
{ // var player = players.FirstOrDefault(e => e.Name.Contains(participent.Name));
participent.IsMember = true; // if (player != null)
} // {
} // participent.IsMember = true;
// }
//}
result.Participents = allParticipent; result.Participents = allParticipent;
foreach (var tournament in tournaments) foreach (var tournament in tournaments)
{ {
var game = games.First(g => tournament.Name.Contains(g.Name));
tournament.Game = game;
var playerCount = tournament.Participents.Count; var playerCount = tournament.Participents.Count;
var lesSacs = tournament.Participents; var lesSacs = tournament.Participents;
@@ -117,18 +112,18 @@ namespace LaDOSE.Business.Service
var Top8 = tournament.Participents.Where(p => p.Rank > 4 && p.Rank < 9).ToList(); var Top8 = tournament.Participents.Where(p => p.Rank > 4 && p.Rank < 9).ToList();
var Top16 = tournament.Participents.Where(p => p.Rank > 8 && p.Rank <= 16).ToList(); var Top16 = tournament.Participents.Where(p => p.Rank > 8 && p.Rank <= 16).ToList();
result.Results.Add(new Result(first.Name, tournament.Game.Id, tournament.Id, tournament.Url, currentRule.FirstPoint)); result.Results.Add(new Result(first.Name, tournament.Game.Id, tournament.ChallongeId, tournament.Url, currentRule.FirstPoint));
lesSacs.Remove(first); lesSacs.Remove(first);
result.Results.Add(new Result(second.Name, tournament.Game.Id, tournament.Id, tournament.Url, currentRule.SecondPoint)); result.Results.Add(new Result(second.Name, tournament.Game.Id, tournament.ChallongeId, tournament.Url, currentRule.SecondPoint));
lesSacs.Remove(second); lesSacs.Remove(second);
thirdFourth.ForEach(r => thirdFourth.ForEach(r =>
result.Results.Add(new Result(r.Name, tournament.Game.Id, tournament.Id, tournament.Url, result.Results.Add(new Result(r.Name, tournament.Game.Id, tournament.ChallongeId, tournament.Url,
currentRule.ThirdFourthPoint))); currentRule.ThirdFourthPoint)));
thirdFourth.ForEach(p => lesSacs.Remove(p)); thirdFourth.ForEach(p => lesSacs.Remove(p));
if (currentRule.Top8Point != 0) if (currentRule.Top8Point != 0)
{ {
Top8.ForEach(r => Top8.ForEach(r =>
result.Results.Add(new Result(r.Name, tournament.Game.Id, tournament.Id, tournament.Url, currentRule.Top8Point))); result.Results.Add(new Result(r.Name, tournament.Game.Id, tournament.ChallongeId, tournament.Url, currentRule.Top8Point)));
Top8.ForEach(p => lesSacs.Remove(p)); Top8.ForEach(p => lesSacs.Remove(p));
} }
@@ -136,12 +131,12 @@ namespace LaDOSE.Business.Service
{ {
Top16.ForEach(r => Top16.ForEach(r =>
result.Results.Add( result.Results.Add(
new Result(r.Name, tournament.Game.Id, tournament.Id, tournament.Url, currentRule.Top16Point))); new Result(r.Name, tournament.Game.Id, tournament.ChallongeId, tournament.Url, currentRule.Top16Point)));
Top16.ForEach(p => lesSacs.Remove(p)); Top16.ForEach(p => lesSacs.Remove(p));
} }
lesSacs.ForEach(r => lesSacs.ForEach(r =>
result.Results.Add(new Result(r.Name, tournament.Game.Id, tournament.Id, tournament.Url, result.Results.Add(new Result(r.Name, tournament.Game.Id, tournament.ChallongeId, tournament.Url,
currentRule.Participation))); currentRule.Participation)));
} }
@@ -149,5 +144,43 @@ namespace LaDOSE.Business.Service
return result; return result;
} }
/// <summary>
/// Check if the tournament exist in database otherwise call Challonge.
/// </summary>
/// <param name="ids">tournaments ids</param>
/// <returns>List of the challonge's tournament with participents</returns>
private async Task<List<ChallongeTournament>> GetChallongeTournaments(List<int> ids, List<Game> games)
{
var tournaments = new List<ChallongeTournament>();
foreach (var idTournament in ids)
{
if (!TournamentExist(idTournament))
{
ChallongeTournament challongeTournament = await _challongeProvider.GetTournament(idTournament);
challongeTournament.Participents =
await _challongeProvider.GetParticipents(challongeTournament.ChallongeId);
var game = games.FirstOrDefault(g => challongeTournament.Name.Contains(g.Name));
if (game != null) challongeTournament.Game = game;
challongeTournament.Sync = DateTime.Now;
tournaments.Add(challongeTournament);
_context.ChallongeTournament.Add(challongeTournament);
_context.SaveChanges();
}
else
{
tournaments.Add(_context.ChallongeTournament.Where(e => e.ChallongeId == idTournament)
.Include(e => e.Participents).First());
}
}
return tournaments;
}
private bool TournamentExist(int idTournament)
{
return this._context.ChallongeTournament.Any(e => e.ChallongeId == idTournament);
}
} }
} }

190
Sql/Dump20190806.sql Normal file
View File

@@ -0,0 +1,190 @@
-- --------------------------------------------------------
-- Hôte : api.ladose.net
-- Version du serveur: 5.7.25-log - Gentoo Linux mysql-5.7.25
-- SE du serveur: Linux
-- HeidiSQL Version: 10.2.0.5599
-- --------------------------------------------------------
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET NAMES utf8 */;
/*!50503 SET NAMES utf8mb4 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
-- Listage de la structure de la base pour ladoseapi
CREATE DATABASE IF NOT EXISTS `ladoseapi` /*!40100 DEFAULT CHARACTER SET utf8 */;
USE `ladoseapi`;
-- Listage de la structure de la table ladoseapi. ApplicationUser
CREATE TABLE IF NOT EXISTS `ApplicationUser` (
`Id` int(11) NOT NULL AUTO_INCREMENT,
`FirstName` varchar(45) DEFAULT NULL,
`LastName` varchar(45) DEFAULT NULL,
`UserName` varchar(45) DEFAULT NULL,
`PasswordHash` blob,
`PasswordSalt` blob,
PRIMARY KEY (`Id`)
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8mb4;
-- Les données exportées n'étaient pas sélectionnées.
-- Listage de la structure de la table ladoseapi. ChallongeParticipent
CREATE TABLE IF NOT EXISTS `ChallongeParticipent` (
`Id` int(11) NOT NULL AUTO_INCREMENT,
`ChallongeId` int(11) NOT NULL DEFAULT '0',
`ChallongeTournamentId` int(11) NOT NULL DEFAULT '0',
`Name` varchar(500) NOT NULL DEFAULT '0',
`Rank` int(11) DEFAULT '0',
`IsMember` bit(1) DEFAULT NULL,
PRIMARY KEY (`Id`)
) ENGINE=InnoDB AUTO_INCREMENT=687 DEFAULT CHARSET=utf8;
-- Les données exportées n'étaient pas sélectionnées.
-- Listage de la structure de la table ladoseapi. ChallongeTournament
CREATE TABLE IF NOT EXISTS `ChallongeTournament` (
`Id` int(11) NOT NULL AUTO_INCREMENT,
`ChallongeId` int(11) NOT NULL DEFAULT '0',
`Name` varchar(500) DEFAULT NULL,
`GameId` int(11) DEFAULT NULL,
`Url` varchar(255) DEFAULT NULL,
`Sync` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`Id`),
KEY `ChallongeTournament_GameIdPK` (`GameId`),
CONSTRAINT `ChallongeTournament_GameIdPK` FOREIGN KEY (`GameId`) REFERENCES `Game` (`Id`)
) ENGINE=InnoDB AUTO_INCREMENT=48 DEFAULT CHARSET=utf8;
-- Les données exportées n'étaient pas sélectionnées.
-- Listage de la structure de la table ladoseapi. Event
CREATE TABLE IF NOT EXISTS `Event` (
`Id` int(11) NOT NULL AUTO_INCREMENT,
`Name` varchar(255) NOT NULL,
`Date` datetime NOT NULL,
`SeasonId` int(11) NOT NULL,
`Ranking` tinyint(4) DEFAULT NULL,
PRIMARY KEY (`Id`),
KEY `SeasonPK_idx` (`SeasonId`),
CONSTRAINT `SeasonsPK` FOREIGN KEY (`SeasonId`) REFERENCES `Season` (`Id`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8;
-- Les données exportées n'étaient pas sélectionnées.
-- Listage de la structure de la table ladoseapi. EventGame
CREATE TABLE IF NOT EXISTS `EventGame` (
`EventId` int(11) NOT NULL,
`GameId` int(11) NOT NULL,
`ChallongeId` int(11) DEFAULT NULL,
`ChallongeUrl` varchar(250) DEFAULT NULL,
PRIMARY KEY (`EventId`,`GameId`),
KEY `GamePK_idx` (`GameId`),
CONSTRAINT `EventGame_EventPK` FOREIGN KEY (`EventId`) REFERENCES `Event` (`Id`),
CONSTRAINT `EventGame_GamePk` FOREIGN KEY (`GameId`) REFERENCES `Game` (`Id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- Les données exportées n'étaient pas sélectionnées.
-- Listage de la structure de la table ladoseapi. Game
CREATE TABLE IF NOT EXISTS `Game` (
`Id` int(11) NOT NULL AUTO_INCREMENT,
`Name` varchar(45) CHARACTER SET utf8 DEFAULT NULL,
`ImgUrl` varchar(255) CHARACTER SET utf8 DEFAULT NULL,
`WordPressTag` varchar(255) DEFAULT NULL,
`WordPressTagOs` varchar(255) DEFAULT NULL,
`Order` int(11) NOT NULL DEFAULT '0',
`LongName` varchar(255) DEFAULT NULL,
PRIMARY KEY (`Id`),
UNIQUE KEY `name_UNIQUE` (`Name`)
) ENGINE=InnoDB AUTO_INCREMENT=16 DEFAULT CHARSET=utf8mb4;
-- Les données exportées n'étaient pas sélectionnées.
-- Listage de la structure de la procédure ladoseapi. ImportEvent
DELIMITER //
CREATE DEFINER=`ladoseapi`@`%` PROCEDURE `ImportEvent`()
BEGIN
INSERT INTO WPEvent (Id, Name,Slug,Date )
select event_id, event_name,event_slug, event_start_date from ladose.wp_em_events
where event_id not in (select Id from WPEvent);
INSERT INTO WPUser (Id, Name, WPUSerLogin, WPMail)
select ID, display_name, user_login , user_email from ladose.wp_users
where ID not in (select Id from WPUser);
INSERT INTO WPBooking (WPEventId, WPUserId, Message, Meta)
select event_id, person_id, booking_comment , booking_meta from ladose.wp_em_bookings
where (event_id , person_id) not in (select WPEventId,WPUserId from WPBooking);
END//
DELIMITER ;
-- Listage de la structure de la table ladoseapi. Season
CREATE TABLE IF NOT EXISTS `Season` (
`Id` int(11) NOT NULL AUTO_INCREMENT,
`Name` varchar(45) DEFAULT NULL,
`StartDate` datetime DEFAULT NULL,
`EndDate` datetime DEFAULT NULL,
PRIMARY KEY (`Id`),
UNIQUE KEY `Name_UNIQUE` (`Name`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8;
-- Les données exportées n'étaient pas sélectionnées.
-- Listage de la structure de la table ladoseapi. SeasonGame
CREATE TABLE IF NOT EXISTS `SeasonGame` (
`SeasonId` int(11) NOT NULL,
`GameId` int(11) NOT NULL,
PRIMARY KEY (`SeasonId`,`GameId`),
KEY `GamePK_idx` (`GameId`),
CONSTRAINT `GamePK` FOREIGN KEY (`GameId`) REFERENCES `Game` (`Id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
CONSTRAINT `SeasonPK` FOREIGN KEY (`SeasonId`) REFERENCES `Season` (`Id`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- Les données exportées n'étaient pas sélectionnées.
-- Listage de la structure de la table ladoseapi. Todo
CREATE TABLE IF NOT EXISTS `Todo` (
`Id` int(11) NOT NULL AUTO_INCREMENT,
`User` varchar(45) NOT NULL,
`Task` mediumtext,
`Done` tinyint(4) NOT NULL DEFAULT '0',
`Created` datetime NOT NULL,
`Deleted` datetime DEFAULT NULL,
PRIMARY KEY (`Id`)
) ENGINE=InnoDB AUTO_INCREMENT=21 DEFAULT CHARSET=utf8;
-- Les données exportées n'étaient pas sélectionnées.
-- Listage de la structure de la table ladoseapi. WPBooking
CREATE TABLE IF NOT EXISTS `WPBooking` (
`WPEventId` int(11) DEFAULT NULL,
`WPUserId` int(11) DEFAULT NULL,
`Message` varchar(5000) DEFAULT NULL,
`Meta` varchar(5000) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- Les données exportées n'étaient pas sélectionnées.
-- Listage de la structure de la table ladoseapi. WPEvent
CREATE TABLE IF NOT EXISTS `WPEvent` (
`Id` int(11) NOT NULL,
`Name` varchar(255) DEFAULT NULL,
`Slug` varchar(255) DEFAULT NULL,
`Date` date DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- Les données exportées n'étaient pas sélectionnées.
-- Listage de la structure de la table ladoseapi. WPUser
CREATE TABLE IF NOT EXISTS `WPUser` (
`Id` int(11) NOT NULL,
`Name` varchar(45) DEFAULT NULL,
`WPUserLogin` varchar(45) DEFAULT NULL,
`WPMail` varchar(45) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- Les données exportées n'étaient pas sélectionnées.
/*!40101 SET SQL_MODE=IFNULL(@OLD_SQL_MODE, '') */;
/*!40014 SET FOREIGN_KEY_CHECKS=IF(@OLD_FOREIGN_KEY_CHECKS IS NULL, 1, @OLD_FOREIGN_KEY_CHECKS) */;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;