fixes the db migration

vnext
Paul Schneider 6 years ago
parent 0c69d5abbc
commit 2d7df973f9
11 changed files with 100 additions and 71 deletions

@ -11,8 +11,8 @@ namespace Yavsc.Server.Models.IT
{
public class Project : NominativeServiceCommand, IProject
{
[Key]
public override long Id { get; set; }
[Key,DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public override long Id { get; set; }
public string OwnerId { get; set; }
/// <summary>
@ -31,7 +31,11 @@ namespace Yavsc.Server.Models.IT
[InverseProperty("TargetProject")]
public virtual List<ProjectBuildConfiguration> Configurations { get; set; }
[ForeignKey("Name")]
[Required]
public long GitId { get; set; }
[ForeignKey("GitId")]
public virtual GitRepositoryReference Repository { get; set; }
List<IBillItem> bill = new List<IBillItem>();
@ -57,10 +61,6 @@ namespace Yavsc.Server.Models.IT
set { description = value; }
}
public Project()
{
}
}
}

@ -9,7 +9,7 @@ namespace Yavsc.Server.Models.IT
/// A Numerical Id
/// </summary>
/// <value></value>
[Key]
[Key,DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public long Id { get; set; }
[Required]

@ -5,8 +5,11 @@ using Yavsc.Models;
namespace Yavsc.Server.Models.IT.SourceCode
{
public class GitRepositoryReference
{
[Key]
{
[Key,DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public long Id { get; set; }
[Required]
public string Path { get; set; }
[StringLength(2048)]

@ -31,14 +31,14 @@ namespace Yavsc.Controllers
// GET: api/GitRefsApi/5
[HttpGet("{id}", Name = "GetGitRepositoryReference")]
public async Task<IActionResult> GetGitRepositoryReference([FromRoute] string id)
public async Task<IActionResult> GetGitRepositoryReference([FromRoute] long id)
{
if (!ModelState.IsValid)
{
return HttpBadRequest(ModelState);
}
GitRepositoryReference gitRepositoryReference = await _context.GitRepositoryReference.SingleAsync(m => m.Path == id);
GitRepositoryReference gitRepositoryReference = await _context.GitRepositoryReference.SingleAsync(m => m.Id == id);
if (gitRepositoryReference == null)
{
@ -50,18 +50,13 @@ namespace Yavsc.Controllers
// PUT: api/GitRefsApi/5
[HttpPut("{id}")]
public async Task<IActionResult> PutGitRepositoryReference([FromRoute] string id, [FromBody] GitRepositoryReference gitRepositoryReference)
public async Task<IActionResult> PutGitRepositoryReference([FromRoute] long id, [FromBody] GitRepositoryReference gitRepositoryReference)
{
if (!ModelState.IsValid)
{
return HttpBadRequest(ModelState);
}
if (id != gitRepositoryReference.Path)
{
return HttpBadRequest();
}
_context.Entry(gitRepositoryReference).State = EntityState.Modified;
try
@ -99,7 +94,7 @@ namespace Yavsc.Controllers
}
catch (DbUpdateException)
{
if (GitRepositoryReferenceExists(gitRepositoryReference.Path))
if (GitRepositoryReferenceExists(gitRepositoryReference.Id))
{
return new HttpStatusCodeResult(StatusCodes.Status409Conflict);
}
@ -114,14 +109,14 @@ namespace Yavsc.Controllers
// DELETE: api/GitRefsApi/5
[HttpDelete("{id}")]
public async Task<IActionResult> DeleteGitRepositoryReference([FromRoute] string id)
public async Task<IActionResult> DeleteGitRepositoryReference([FromRoute] long id)
{
if (!ModelState.IsValid)
{
return HttpBadRequest(ModelState);
}
GitRepositoryReference gitRepositoryReference = await _context.GitRepositoryReference.SingleAsync(m => m.Path == id);
GitRepositoryReference gitRepositoryReference = await _context.GitRepositoryReference.SingleAsync(m => m.Id == id);
if (gitRepositoryReference == null)
{
return HttpNotFound();
@ -142,9 +137,9 @@ namespace Yavsc.Controllers
base.Dispose(disposing);
}
private bool GitRepositoryReferenceExists(string id)
private bool GitRepositoryReferenceExists(long id)
{
return _context.GitRepositoryReference.Count(e => e.Path == id) > 0;
return _context.GitRepositoryReference.Count(e => e.Id == id) > 0;
}
}
}

@ -20,7 +20,6 @@ using Newtonsoft.Json;
namespace Yavsc.Controllers
{
using System.Text;
using Yavsc.Abstract.Manage;
using Yavsc.Helpers;

@ -63,14 +63,10 @@ namespace Yavsc.Controllers
}
// GET: Git/Details/5
public async Task<IActionResult> Details(string id)
public async Task<IActionResult> Details(long id)
{
if (id == null)
{
return HttpNotFound();
}
GitRepositoryReference gitRepositoryReference = await _context.GitRepositoryReference.SingleAsync(m => m.Path == id);
GitRepositoryReference gitRepositoryReference = await _context.GitRepositoryReference.SingleAsync(m => m.Id == id);
if (gitRepositoryReference == null)
{
return HttpNotFound();
@ -103,14 +99,9 @@ namespace Yavsc.Controllers
}
// GET: Git/Edit/5
public async Task<IActionResult> Edit(string id)
public async Task<IActionResult> Edit(long id)
{
if (id == null)
{
return HttpNotFound();
}
GitRepositoryReference gitRepositoryReference = await _context.GitRepositoryReference.SingleAsync(m => m.Path == id);
GitRepositoryReference gitRepositoryReference = await _context.GitRepositoryReference.SingleAsync(m => m.Id == id);
if (gitRepositoryReference == null)
{
return HttpNotFound();

@ -71,7 +71,7 @@ namespace Yavsc.Controllers
ViewBag.Status = typeof(Yavsc.QueryStatus).CreateSelectListItems(null);
ViewBag.RepositoryItems = _context.GitRepositoryReference.CreateSelectListItems<GitRepositoryReference>(
u => u.Path, u => u.ToString());
u => u.Id.ToString(), u => u.ToString());
return View();
}

@ -1,14 +1,15 @@
using System;
using Microsoft.Data.Entity;
using Microsoft.Data.Entity.Infrastructure;
using Microsoft.Data.Entity.Metadata;
using Microsoft.Data.Entity.Migrations;
using Yavsc.Models;
namespace Yavsc.Migrations
{
[DbContext(typeof(ApplicationDbContext))]
[Migration("20180722232456_gitrepo")]
partial class gitrepo
[Migration("20180805122812_gitprojectref")]
partial class gitprojectref
{
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
@ -680,6 +681,8 @@ namespace Yavsc.Migrations
b.Property<DateTime>("DateModified");
b.Property<string>("Description");
b.Property<DateTime?>("EventDate");
b.Property<long?>("LocationId");
@ -727,6 +730,8 @@ namespace Yavsc.Migrations
b.Property<DateTime>("DateModified");
b.Property<string>("Description");
b.Property<DateTime>("EventDate");
b.Property<long?>("LocationId");
@ -1268,6 +1273,8 @@ namespace Yavsc.Migrations
b.Property<DateTime>("DateModified");
b.Property<string>("Description");
b.Property<DateTime>("EventDate");
b.Property<long?>("LocationId");
@ -1356,6 +1363,8 @@ namespace Yavsc.Migrations
b.Property<string>("Description");
b.Property<long>("GitId");
b.Property<string>("Name")
.IsRequired();
@ -1400,7 +1409,8 @@ namespace Yavsc.Migrations
modelBuilder.Entity("Yavsc.Server.Models.IT.SourceCode.GitRepositoryReference", b =>
{
b.Property<string>("Path");
b.Property<long>("Id")
.ValueGeneratedOnAdd();
b.Property<string>("Branch")
.HasAnnotation("MaxLength", 512);
@ -1408,10 +1418,13 @@ namespace Yavsc.Migrations
b.Property<string>("OwnerId")
.HasAnnotation("MaxLength", 1024);
b.Property<string>("Path")
.IsRequired();
b.Property<string>("Url")
.HasAnnotation("MaxLength", 2048);
b.HasKey("Path");
b.HasKey("Id");
});
modelBuilder.Entity("Microsoft.AspNet.Identity.EntityFramework.IdentityRoleClaim<string>", b =>
@ -1882,7 +1895,7 @@ namespace Yavsc.Migrations
b.HasOne("Yavsc.Server.Models.IT.SourceCode.GitRepositoryReference")
.WithMany()
.HasForeignKey("Name");
.HasForeignKey("GitId");
b.HasOne("Yavsc.Models.Payment.PayPalPayment")
.WithMany()

@ -1,8 +1,10 @@
using System;
using System.Collections.Generic;
using Microsoft.Data.Entity.Migrations;
namespace Yavsc.Migrations
{
public partial class gitrepo : Migration
public partial class gitprojectref : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
@ -54,20 +56,20 @@ namespace Yavsc.Migrations
migrationBuilder.DropForeignKey(name: "FK_Project_Activity_ActivityCode", table: "Project");
migrationBuilder.DropForeignKey(name: "FK_Project_ApplicationUser_ClientId", table: "Project");
migrationBuilder.DropForeignKey(name: "FK_Project_PerformerProfile_PerformerId", table: "Project");
migrationBuilder.DropForeignKey(name: "FK_ProjectBuildConfiguration_Project_ProjectId", table: "ProjectBuildConfiguration");
migrationBuilder.CreateTable(
name: "GitRepositoryReference",
columns: table => new
{
Path = table.Column<string>(nullable: false),
Id = table.Column<long>(nullable: false)
.Annotation("Npgsql:Serial", true),
Branch = table.Column<string>(nullable: true),
OwnerId = table.Column<string>(nullable: true),
Path = table.Column<string>(nullable: false),
Url = table.Column<string>(nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_GitRepositoryReference", x => x.Path);
table.PrimaryKey("PK_GitRepositoryReference", x => x.Id);
table.ForeignKey(
name: "FK_GitRepositoryReference_ApplicationUser_OwnerId",
column: x => x.OwnerId,
@ -75,6 +77,23 @@ namespace Yavsc.Migrations
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
});
migrationBuilder.AddColumn<long>(
name: "GitId",
table: "Project",
nullable: false,
defaultValue: 0L);
migrationBuilder.AddColumn<string>(
name: "Description",
table: "RdvQuery",
nullable: true);
migrationBuilder.AddColumn<string>(
name: "Description",
table: "HairMultiCutQuery",
nullable: true);
migrationBuilder.AddColumn<string>(
name: "Description",
table: "HairCutQuery",
nullable: true);
migrationBuilder.AddForeignKey(
name: "FK_IdentityRoleClaim<string>_IdentityRole_RoleId",
table: "AspNetRoleClaims",
@ -405,11 +424,11 @@ namespace Yavsc.Migrations
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
migrationBuilder.AddForeignKey(
name: "FK_Project_GitRepositoryReference_Name",
name: "FK_Project_GitRepositoryReference_GitId",
table: "Project",
column: "Name",
column: "GitId",
principalTable: "GitRepositoryReference",
principalColumn: "Path",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
migrationBuilder.AddForeignKey(
name: "FK_Project_PerformerProfile_PerformerId",
@ -418,13 +437,6 @@ namespace Yavsc.Migrations
principalTable: "PerformerProfile",
principalColumn: "PerformerId",
onDelete: ReferentialAction.Cascade);
migrationBuilder.AddForeignKey(
name: "FK_ProjectBuildConfiguration_Project_ProjectId",
table: "ProjectBuildConfiguration",
column: "ProjectId",
principalTable: "Project",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
}
protected override void Down(MigrationBuilder migrationBuilder)
@ -476,9 +488,13 @@ namespace Yavsc.Migrations
migrationBuilder.DropForeignKey(name: "FK_UserActivity_PerformerProfile_UserId", table: "UserActivity");
migrationBuilder.DropForeignKey(name: "FK_Project_Activity_ActivityCode", table: "Project");
migrationBuilder.DropForeignKey(name: "FK_Project_ApplicationUser_ClientId", table: "Project");
migrationBuilder.DropForeignKey(name: "FK_Project_GitRepositoryReference_Name", table: "Project");
migrationBuilder.DropForeignKey(name: "FK_Project_GitRepositoryReference_GitId", table: "Project");
migrationBuilder.DropForeignKey(name: "FK_Project_PerformerProfile_PerformerId", table: "Project");
migrationBuilder.DropForeignKey(name: "FK_ProjectBuildConfiguration_Project_ProjectId", table: "ProjectBuildConfiguration");
migrationBuilder.DropColumn(name: "GitId", table: "Project");
migrationBuilder.DropColumn(name: "Description", table: "RdvQuery");
migrationBuilder.DropColumn(name: "Description", table: "HairMultiCutQuery");
migrationBuilder.DropColumn(name: "Description", table: "HairCutQuery");
migrationBuilder.DropTable("GitRepositoryReference");
migrationBuilder.AddForeignKey(
name: "FK_IdentityRoleClaim<string>_IdentityRole_RoleId",

@ -678,6 +678,8 @@ namespace Yavsc.Migrations
b.Property<DateTime>("DateModified");
b.Property<string>("Description");
b.Property<DateTime?>("EventDate");
b.Property<long?>("LocationId");
@ -725,6 +727,8 @@ namespace Yavsc.Migrations
b.Property<DateTime>("DateModified");
b.Property<string>("Description");
b.Property<DateTime>("EventDate");
b.Property<long?>("LocationId");
@ -1266,6 +1270,8 @@ namespace Yavsc.Migrations
b.Property<DateTime>("DateModified");
b.Property<string>("Description");
b.Property<DateTime>("EventDate");
b.Property<long?>("LocationId");
@ -1354,6 +1360,8 @@ namespace Yavsc.Migrations
b.Property<string>("Description");
b.Property<long>("GitId");
b.Property<string>("Name")
.IsRequired();
@ -1398,7 +1406,8 @@ namespace Yavsc.Migrations
modelBuilder.Entity("Yavsc.Server.Models.IT.SourceCode.GitRepositoryReference", b =>
{
b.Property<string>("Path");
b.Property<long>("Id")
.ValueGeneratedOnAdd();
b.Property<string>("Branch")
.HasAnnotation("MaxLength", 512);
@ -1406,10 +1415,13 @@ namespace Yavsc.Migrations
b.Property<string>("OwnerId")
.HasAnnotation("MaxLength", 1024);
b.Property<string>("Path")
.IsRequired();
b.Property<string>("Url")
.HasAnnotation("MaxLength", 2048);
b.HasKey("Path");
b.HasKey("Id");
});
modelBuilder.Entity("Microsoft.AspNet.Identity.EntityFramework.IdentityRoleClaim<string>", b =>
@ -1880,7 +1892,7 @@ namespace Yavsc.Migrations
b.HasOne("Yavsc.Server.Models.IT.SourceCode.GitRepositoryReference")
.WithMany()
.HasForeignKey("Name");
.HasForeignKey("GitId");
b.HasOne("Yavsc.Models.Payment.PayPalPayment")
.WithMany()

@ -12,10 +12,10 @@
<hr />
<div asp-validation-summary="ValidationSummary.ModelOnly" class="text-danger"></div>
<div class="form-group">
<label asp-for="Repository" class="col-md-2 control-label"></label>
<label asp-for="GitId" class="col-md-2 control-label"></label>
<div class="col-md-10">
<select asp-for="Repository" class ="form-control" asp-items="@ViewBag.RepositoryItems"></select>
<span asp-validation-for="Repository" class="text-danger" />
<select asp-for="GitId" class ="form-control" asp-items="@ViewBag.RepositoryItems"></select>
<span asp-validation-for="GitId" class="text-danger" ></span>
</div>
</div>
<div class="form-group">
@ -34,14 +34,14 @@
<label asp-for="Description" class="col-md-2 control-label"></label>
<div class="col-md-10">
<input asp-for="Description" class="form-control" />
<span asp-validation-for="Description" class="text-danger" />
<span asp-validation-for="Description" class="text-danger" ></span>
</div>
</div>
<div class="form-group">
<label asp-for="Name" class="col-md-2 control-label"></label>
<div class="col-md-10">
<input asp-for="Name" class ="form-control" aria-required="true" ></input>
<span asp-validation-for="Name" class="text-danger" />
<span asp-validation-for="Name" class="text-danger" ></span>
</div>
</div>
<div class="form-group">
@ -49,7 +49,7 @@
<div class="col-md-10">
<select asp-for="OwnerId" asp-items="@ViewBag.OwnerIdItems" class="form-control" >
</select>
<span asp-validation-for="OwnerId" class="text-danger" />
<span asp-validation-for="OwnerId" class="text-danger" ></span>
</div>
</div>
<div class="form-group">
@ -62,21 +62,21 @@
<label asp-for="Previsional" class="col-md-2 control-label"></label>
<div class="col-md-10">
<input asp-for="Previsional" class="form-control" />
<span asp-validation-for="Previsional" class="text-danger" />
<span asp-validation-for="Previsional" class="text-danger" ></span>
</div>
</div>
<div class="form-group">
<label asp-for="Status" class="col-md-2 control-label"></label>
<div class="col-md-10">
<select asp-for="Status" class="form-control" asp-items="@ViewBag.Status" ></select>
<span asp-validation-for="Status" class="text-danger" />
<span asp-validation-for="Status" class="text-danger" ></span>
</div>
</div>
<div class="form-group">
<label asp-for="Version" class="col-md-2 control-label"></label>
<div class="col-md-10">
<input asp-for="Version" class="form-control" />
<span asp-validation-for="Version" class="text-danger" />
<span asp-validation-for="Version" class="text-danger" ></span>
</div>
</div>
<div class="form-group">

Loading…