From 2d7df973f9ba36e9b9e3d50ca0022c51895e3a0b Mon Sep 17 00:00:00 2001 From: Paul Schneider Date: Sun, 5 Aug 2018 06:04:10 +0200 Subject: [PATCH] fixes the db migration --- Yavsc.Server/Models/IT/Project.cs | 14 +++--- .../Models/IT/ProjectBuildConfiguration.cs | 2 +- .../Models/IT/SourceCode/GitRepository.cs | 7 ++- .../ApiControllers/IT/GitRefsApiController.cs | 21 ++++---- .../Accounting/AccountController.cs | 1 - Yavsc/Controllers/IT/GitController.cs | 17 ++----- Yavsc/Controllers/IT/ProjectController.cs | 2 +- ... 20180805122812_gitprojectref.Designer.cs} | 23 +++++++-- ...epo.cs => 20180805122812_gitprojectref.cs} | 48 ++++++++++++------- .../ApplicationDbContextModelSnapshot.cs | 18 +++++-- Yavsc/Views/Project/Create.cshtml | 18 +++---- 11 files changed, 100 insertions(+), 71 deletions(-) rename Yavsc/Migrations/{20180722232456_gitrepo.Designer.cs => 20180805122812_gitprojectref.Designer.cs} (99%) rename Yavsc/Migrations/{20180722232456_gitrepo.cs => 20180805122812_gitprojectref.cs} (97%) diff --git a/Yavsc.Server/Models/IT/Project.cs b/Yavsc.Server/Models/IT/Project.cs index f3cb066e..47d81537 100644 --- a/Yavsc.Server/Models/IT/Project.cs +++ b/Yavsc.Server/Models/IT/Project.cs @@ -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; } /// @@ -31,7 +31,11 @@ namespace Yavsc.Server.Models.IT [InverseProperty("TargetProject")] public virtual List Configurations { get; set; } - [ForeignKey("Name")] + + [Required] + public long GitId { get; set; } + + [ForeignKey("GitId")] public virtual GitRepositoryReference Repository { get; set; } List bill = new List(); @@ -57,10 +61,6 @@ namespace Yavsc.Server.Models.IT set { description = value; } } - public Project() - { - - } } } diff --git a/Yavsc.Server/Models/IT/ProjectBuildConfiguration.cs b/Yavsc.Server/Models/IT/ProjectBuildConfiguration.cs index 22dd4eac..e2f96bed 100644 --- a/Yavsc.Server/Models/IT/ProjectBuildConfiguration.cs +++ b/Yavsc.Server/Models/IT/ProjectBuildConfiguration.cs @@ -9,7 +9,7 @@ namespace Yavsc.Server.Models.IT /// A Numerical Id /// /// - [Key] + [Key,DatabaseGenerated(DatabaseGeneratedOption.Identity)] public long Id { get; set; } [Required] diff --git a/Yavsc.Server/Models/IT/SourceCode/GitRepository.cs b/Yavsc.Server/Models/IT/SourceCode/GitRepository.cs index df57ea8e..11f6f577 100644 --- a/Yavsc.Server/Models/IT/SourceCode/GitRepository.cs +++ b/Yavsc.Server/Models/IT/SourceCode/GitRepository.cs @@ -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)] diff --git a/Yavsc/ApiControllers/IT/GitRefsApiController.cs b/Yavsc/ApiControllers/IT/GitRefsApiController.cs index 90816191..88c6606d 100644 --- a/Yavsc/ApiControllers/IT/GitRefsApiController.cs +++ b/Yavsc/ApiControllers/IT/GitRefsApiController.cs @@ -31,14 +31,14 @@ namespace Yavsc.Controllers // GET: api/GitRefsApi/5 [HttpGet("{id}", Name = "GetGitRepositoryReference")] - public async Task GetGitRepositoryReference([FromRoute] string id) + public async Task 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 PutGitRepositoryReference([FromRoute] string id, [FromBody] GitRepositoryReference gitRepositoryReference) + public async Task 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 DeleteGitRepositoryReference([FromRoute] string id) + public async Task 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; } } } \ No newline at end of file diff --git a/Yavsc/Controllers/Accounting/AccountController.cs b/Yavsc/Controllers/Accounting/AccountController.cs index bfc66662..950f43c3 100644 --- a/Yavsc/Controllers/Accounting/AccountController.cs +++ b/Yavsc/Controllers/Accounting/AccountController.cs @@ -20,7 +20,6 @@ using Newtonsoft.Json; namespace Yavsc.Controllers { - using System.Text; using Yavsc.Abstract.Manage; using Yavsc.Helpers; diff --git a/Yavsc/Controllers/IT/GitController.cs b/Yavsc/Controllers/IT/GitController.cs index 41acb941..917eb1ae 100644 --- a/Yavsc/Controllers/IT/GitController.cs +++ b/Yavsc/Controllers/IT/GitController.cs @@ -63,14 +63,10 @@ namespace Yavsc.Controllers } // GET: Git/Details/5 - public async Task Details(string id) + public async Task 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 Edit(string id) + public async Task 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(); diff --git a/Yavsc/Controllers/IT/ProjectController.cs b/Yavsc/Controllers/IT/ProjectController.cs index c40971cf..e91da03a 100644 --- a/Yavsc/Controllers/IT/ProjectController.cs +++ b/Yavsc/Controllers/IT/ProjectController.cs @@ -71,7 +71,7 @@ namespace Yavsc.Controllers ViewBag.Status = typeof(Yavsc.QueryStatus).CreateSelectListItems(null); ViewBag.RepositoryItems = _context.GitRepositoryReference.CreateSelectListItems( - u => u.Path, u => u.ToString()); + u => u.Id.ToString(), u => u.ToString()); return View(); } diff --git a/Yavsc/Migrations/20180722232456_gitrepo.Designer.cs b/Yavsc/Migrations/20180805122812_gitprojectref.Designer.cs similarity index 99% rename from Yavsc/Migrations/20180722232456_gitrepo.Designer.cs rename to Yavsc/Migrations/20180805122812_gitprojectref.Designer.cs index 722053f1..17de61aa 100644 --- a/Yavsc/Migrations/20180722232456_gitrepo.Designer.cs +++ b/Yavsc/Migrations/20180805122812_gitprojectref.Designer.cs @@ -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("DateModified"); + b.Property("Description"); + b.Property("EventDate"); b.Property("LocationId"); @@ -727,6 +730,8 @@ namespace Yavsc.Migrations b.Property("DateModified"); + b.Property("Description"); + b.Property("EventDate"); b.Property("LocationId"); @@ -1268,6 +1273,8 @@ namespace Yavsc.Migrations b.Property("DateModified"); + b.Property("Description"); + b.Property("EventDate"); b.Property("LocationId"); @@ -1356,6 +1363,8 @@ namespace Yavsc.Migrations b.Property("Description"); + b.Property("GitId"); + b.Property("Name") .IsRequired(); @@ -1400,7 +1409,8 @@ namespace Yavsc.Migrations modelBuilder.Entity("Yavsc.Server.Models.IT.SourceCode.GitRepositoryReference", b => { - b.Property("Path"); + b.Property("Id") + .ValueGeneratedOnAdd(); b.Property("Branch") .HasAnnotation("MaxLength", 512); @@ -1408,10 +1418,13 @@ namespace Yavsc.Migrations b.Property("OwnerId") .HasAnnotation("MaxLength", 1024); + b.Property("Path") + .IsRequired(); + b.Property("Url") .HasAnnotation("MaxLength", 2048); - b.HasKey("Path"); + b.HasKey("Id"); }); modelBuilder.Entity("Microsoft.AspNet.Identity.EntityFramework.IdentityRoleClaim", 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() diff --git a/Yavsc/Migrations/20180722232456_gitrepo.cs b/Yavsc/Migrations/20180805122812_gitprojectref.cs similarity index 97% rename from Yavsc/Migrations/20180722232456_gitrepo.cs rename to Yavsc/Migrations/20180805122812_gitprojectref.cs index 2ffac7f1..7a7e2e02 100644 --- a/Yavsc/Migrations/20180722232456_gitrepo.cs +++ b/Yavsc/Migrations/20180805122812_gitprojectref.cs @@ -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(nullable: false), + Id = table.Column(nullable: false) + .Annotation("Npgsql:Serial", true), Branch = table.Column(nullable: true), OwnerId = table.Column(nullable: true), + Path = table.Column(nullable: false), Url = table.Column(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( + name: "GitId", + table: "Project", + nullable: false, + defaultValue: 0L); + migrationBuilder.AddColumn( + name: "Description", + table: "RdvQuery", + nullable: true); + migrationBuilder.AddColumn( + name: "Description", + table: "HairMultiCutQuery", + nullable: true); + migrationBuilder.AddColumn( + name: "Description", + table: "HairCutQuery", + nullable: true); migrationBuilder.AddForeignKey( name: "FK_IdentityRoleClaim_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_IdentityRole_RoleId", diff --git a/Yavsc/Migrations/ApplicationDbContextModelSnapshot.cs b/Yavsc/Migrations/ApplicationDbContextModelSnapshot.cs index c8c55f1e..2d6d0f7c 100644 --- a/Yavsc/Migrations/ApplicationDbContextModelSnapshot.cs +++ b/Yavsc/Migrations/ApplicationDbContextModelSnapshot.cs @@ -678,6 +678,8 @@ namespace Yavsc.Migrations b.Property("DateModified"); + b.Property("Description"); + b.Property("EventDate"); b.Property("LocationId"); @@ -725,6 +727,8 @@ namespace Yavsc.Migrations b.Property("DateModified"); + b.Property("Description"); + b.Property("EventDate"); b.Property("LocationId"); @@ -1266,6 +1270,8 @@ namespace Yavsc.Migrations b.Property("DateModified"); + b.Property("Description"); + b.Property("EventDate"); b.Property("LocationId"); @@ -1354,6 +1360,8 @@ namespace Yavsc.Migrations b.Property("Description"); + b.Property("GitId"); + b.Property("Name") .IsRequired(); @@ -1398,7 +1406,8 @@ namespace Yavsc.Migrations modelBuilder.Entity("Yavsc.Server.Models.IT.SourceCode.GitRepositoryReference", b => { - b.Property("Path"); + b.Property("Id") + .ValueGeneratedOnAdd(); b.Property("Branch") .HasAnnotation("MaxLength", 512); @@ -1406,10 +1415,13 @@ namespace Yavsc.Migrations b.Property("OwnerId") .HasAnnotation("MaxLength", 1024); + b.Property("Path") + .IsRequired(); + b.Property("Url") .HasAnnotation("MaxLength", 2048); - b.HasKey("Path"); + b.HasKey("Id"); }); modelBuilder.Entity("Microsoft.AspNet.Identity.EntityFramework.IdentityRoleClaim", 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() diff --git a/Yavsc/Views/Project/Create.cshtml b/Yavsc/Views/Project/Create.cshtml index ba12e0b8..7702a64b 100644 --- a/Yavsc/Views/Project/Create.cshtml +++ b/Yavsc/Views/Project/Create.cshtml @@ -12,10 +12,10 @@
- +
- - + +
@@ -34,14 +34,14 @@
- +
- +
@@ -49,7 +49,7 @@
- +
@@ -62,21 +62,21 @@
- +
- +
- +