mirror of
https://github.com/alex289/CleanArchitecture.git
synced 2025-07-05 21:43:56 +00:00
chore: Add migration
This commit is contained in:
parent
b0d96d8b4d
commit
6d1f0b1e5f
@ -1,7 +1,10 @@
|
|||||||
|
using System;
|
||||||
|
|
||||||
namespace CleanArchitecture.Application.ViewModels.Users;
|
namespace CleanArchitecture.Application.ViewModels.Users;
|
||||||
|
|
||||||
public sealed record CreateUserViewModel(
|
public sealed record CreateUserViewModel(
|
||||||
string Email,
|
string Email,
|
||||||
string FirstName,
|
string FirstName,
|
||||||
string LastName,
|
string LastName,
|
||||||
string Password);
|
string Password,
|
||||||
|
Guid TenantId);
|
@ -7,8 +7,8 @@ public class Tenant : Entity
|
|||||||
{
|
{
|
||||||
public string Name { get; private set; }
|
public string Name { get; private set; }
|
||||||
|
|
||||||
public ICollection<User> Users { get; private set; } = new HashSet<User>();
|
public virtual ICollection<User> Users { get; private set; } = new HashSet<User>();
|
||||||
|
|
||||||
public Tenant(
|
public Tenant(
|
||||||
Guid id,
|
Guid id,
|
||||||
string name) : base(id)
|
string name) : base(id)
|
||||||
|
@ -15,8 +15,8 @@ public class User : Entity
|
|||||||
public string FullName => $"{FirstName}, {LastName}";
|
public string FullName => $"{FirstName}, {LastName}";
|
||||||
|
|
||||||
public Guid TenantId { get; private set; }
|
public Guid TenantId { get; private set; }
|
||||||
public Tenant Tenant { get; private set; } = null!;
|
public virtual Tenant Tenant { get; private set; } = null!;
|
||||||
|
|
||||||
public User(
|
public User(
|
||||||
Guid id,
|
Guid id,
|
||||||
Guid tenantId,
|
Guid tenantId,
|
||||||
|
131
CleanArchitecture.Infrastructure/Migrations/20230827171448_AddTenants.Designer.cs
generated
Normal file
131
CleanArchitecture.Infrastructure/Migrations/20230827171448_AddTenants.Designer.cs
generated
Normal file
@ -0,0 +1,131 @@
|
|||||||
|
// <auto-generated />
|
||||||
|
using System;
|
||||||
|
using CleanArchitecture.Infrastructure.Database;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||||
|
using Microsoft.EntityFrameworkCore.Metadata;
|
||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace CleanArchitecture.Infrastructure.Migrations
|
||||||
|
{
|
||||||
|
[DbContext(typeof(ApplicationDbContext))]
|
||||||
|
[Migration("20230827171448_AddTenants")]
|
||||||
|
partial class AddTenants
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||||
|
{
|
||||||
|
#pragma warning disable 612, 618
|
||||||
|
modelBuilder
|
||||||
|
.HasAnnotation("ProductVersion", "7.0.10")
|
||||||
|
.HasAnnotation("Proxies:ChangeTracking", false)
|
||||||
|
.HasAnnotation("Proxies:CheckEquality", false)
|
||||||
|
.HasAnnotation("Proxies:LazyLoading", true)
|
||||||
|
.HasAnnotation("Relational:MaxIdentifierLength", 128);
|
||||||
|
|
||||||
|
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
|
||||||
|
|
||||||
|
modelBuilder.Entity("CleanArchitecture.Domain.Entities.Tenant", b =>
|
||||||
|
{
|
||||||
|
b.Property<Guid>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("uniqueidentifier");
|
||||||
|
|
||||||
|
b.Property<bool>("Deleted")
|
||||||
|
.HasColumnType("bit");
|
||||||
|
|
||||||
|
b.Property<string>("Name")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(255)
|
||||||
|
.HasColumnType("nvarchar(255)");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("Tenants");
|
||||||
|
|
||||||
|
b.HasData(
|
||||||
|
new
|
||||||
|
{
|
||||||
|
Id = new Guid("b542bf25-134c-47a2-a0df-84ed14d03c4a"),
|
||||||
|
Deleted = false,
|
||||||
|
Name = "Admin Tenant"
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("CleanArchitecture.Domain.Entities.User", b =>
|
||||||
|
{
|
||||||
|
b.Property<Guid>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("uniqueidentifier");
|
||||||
|
|
||||||
|
b.Property<bool>("Deleted")
|
||||||
|
.HasColumnType("bit");
|
||||||
|
|
||||||
|
b.Property<string>("Email")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(320)
|
||||||
|
.HasColumnType("nvarchar(320)");
|
||||||
|
|
||||||
|
b.Property<string>("FirstName")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(100)
|
||||||
|
.HasColumnType("nvarchar(100)");
|
||||||
|
|
||||||
|
b.Property<string>("LastName")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(100)
|
||||||
|
.HasColumnType("nvarchar(100)");
|
||||||
|
|
||||||
|
b.Property<string>("Password")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(128)
|
||||||
|
.HasColumnType("nvarchar(128)");
|
||||||
|
|
||||||
|
b.Property<int>("Role")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.Property<Guid>("TenantId")
|
||||||
|
.HasColumnType("uniqueidentifier");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("TenantId");
|
||||||
|
|
||||||
|
b.ToTable("Users");
|
||||||
|
|
||||||
|
b.HasData(
|
||||||
|
new
|
||||||
|
{
|
||||||
|
Id = new Guid("7e3892c0-9374-49fa-a3fd-53db637a40ae"),
|
||||||
|
Deleted = false,
|
||||||
|
Email = "admin@email.com",
|
||||||
|
FirstName = "Admin",
|
||||||
|
LastName = "User",
|
||||||
|
Password = "$2a$12$Blal/uiFIJdYsCLTMUik/egLbfg3XhbnxBC6Sb5IKz2ZYhiU/MzL2",
|
||||||
|
Role = 0,
|
||||||
|
TenantId = new Guid("b542bf25-134c-47a2-a0df-84ed14d03c4a")
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("CleanArchitecture.Domain.Entities.User", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("CleanArchitecture.Domain.Entities.Tenant", "Tenant")
|
||||||
|
.WithMany("Users")
|
||||||
|
.HasForeignKey("TenantId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.Navigation("Tenant");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("CleanArchitecture.Domain.Entities.Tenant", b =>
|
||||||
|
{
|
||||||
|
b.Navigation("Users");
|
||||||
|
});
|
||||||
|
#pragma warning restore 612, 618
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,92 @@
|
|||||||
|
using System;
|
||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace CleanArchitecture.Infrastructure.Migrations
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
public partial class AddTenants : Migration
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.DeleteData(
|
||||||
|
table: "Users",
|
||||||
|
keyColumn: "Id",
|
||||||
|
keyValue: new Guid("28fc3d91-6a15-448e-b0b5-0c91a3948961"));
|
||||||
|
|
||||||
|
migrationBuilder.AddColumn<Guid>(
|
||||||
|
name: "TenantId",
|
||||||
|
table: "Users",
|
||||||
|
type: "uniqueidentifier",
|
||||||
|
nullable: false,
|
||||||
|
defaultValue: new Guid("00000000-0000-0000-0000-000000000000"));
|
||||||
|
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "Tenants",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
|
||||||
|
Name = table.Column<string>(type: "nvarchar(255)", maxLength: 255, nullable: false),
|
||||||
|
Deleted = table.Column<bool>(type: "bit", nullable: false)
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_Tenants", x => x.Id);
|
||||||
|
});
|
||||||
|
|
||||||
|
migrationBuilder.InsertData(
|
||||||
|
table: "Tenants",
|
||||||
|
columns: new[] { "Id", "Deleted", "Name" },
|
||||||
|
values: new object[] { new Guid("b542bf25-134c-47a2-a0df-84ed14d03c4a"), false, "Admin Tenant" });
|
||||||
|
|
||||||
|
migrationBuilder.InsertData(
|
||||||
|
table: "Users",
|
||||||
|
columns: new[] { "Id", "Deleted", "Email", "FirstName", "LastName", "Password", "Role", "TenantId" },
|
||||||
|
values: new object[] { new Guid("7e3892c0-9374-49fa-a3fd-53db637a40ae"), false, "admin@email.com", "Admin", "User", "$2a$12$Blal/uiFIJdYsCLTMUik/egLbfg3XhbnxBC6Sb5IKz2ZYhiU/MzL2", 0, new Guid("b542bf25-134c-47a2-a0df-84ed14d03c4a") });
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "IX_Users_TenantId",
|
||||||
|
table: "Users",
|
||||||
|
column: "TenantId");
|
||||||
|
|
||||||
|
migrationBuilder.AddForeignKey(
|
||||||
|
name: "FK_Users_Tenants_TenantId",
|
||||||
|
table: "Users",
|
||||||
|
column: "TenantId",
|
||||||
|
principalTable: "Tenants",
|
||||||
|
principalColumn: "Id",
|
||||||
|
onDelete: ReferentialAction.Cascade);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.DropForeignKey(
|
||||||
|
name: "FK_Users_Tenants_TenantId",
|
||||||
|
table: "Users");
|
||||||
|
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "Tenants");
|
||||||
|
|
||||||
|
migrationBuilder.DropIndex(
|
||||||
|
name: "IX_Users_TenantId",
|
||||||
|
table: "Users");
|
||||||
|
|
||||||
|
migrationBuilder.DeleteData(
|
||||||
|
table: "Users",
|
||||||
|
keyColumn: "Id",
|
||||||
|
keyValue: new Guid("7e3892c0-9374-49fa-a3fd-53db637a40ae"));
|
||||||
|
|
||||||
|
migrationBuilder.DropColumn(
|
||||||
|
name: "TenantId",
|
||||||
|
table: "Users");
|
||||||
|
|
||||||
|
migrationBuilder.InsertData(
|
||||||
|
table: "Users",
|
||||||
|
columns: new[] { "Id", "Deleted", "Email", "FirstName", "LastName", "Password", "Role" },
|
||||||
|
values: new object[] { new Guid("28fc3d91-6a15-448e-b0b5-0c91a3948961"), false, "admin@email.com", "Admin", "User", "$2a$12$Blal/uiFIJdYsCLTMUik/egLbfg3XhbnxBC6Sb5IKz2ZYhiU/MzL2", 0 });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -17,7 +17,7 @@ namespace CleanArchitecture.Infrastructure.Migrations
|
|||||||
{
|
{
|
||||||
#pragma warning disable 612, 618
|
#pragma warning disable 612, 618
|
||||||
modelBuilder
|
modelBuilder
|
||||||
.HasAnnotation("ProductVersion", "7.0.5")
|
.HasAnnotation("ProductVersion", "7.0.10")
|
||||||
.HasAnnotation("Proxies:ChangeTracking", false)
|
.HasAnnotation("Proxies:ChangeTracking", false)
|
||||||
.HasAnnotation("Proxies:CheckEquality", false)
|
.HasAnnotation("Proxies:CheckEquality", false)
|
||||||
.HasAnnotation("Proxies:LazyLoading", true)
|
.HasAnnotation("Proxies:LazyLoading", true)
|
||||||
@ -25,6 +25,33 @@ namespace CleanArchitecture.Infrastructure.Migrations
|
|||||||
|
|
||||||
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
|
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
|
||||||
|
|
||||||
|
modelBuilder.Entity("CleanArchitecture.Domain.Entities.Tenant", b =>
|
||||||
|
{
|
||||||
|
b.Property<Guid>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("uniqueidentifier");
|
||||||
|
|
||||||
|
b.Property<bool>("Deleted")
|
||||||
|
.HasColumnType("bit");
|
||||||
|
|
||||||
|
b.Property<string>("Name")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(255)
|
||||||
|
.HasColumnType("nvarchar(255)");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("Tenants");
|
||||||
|
|
||||||
|
b.HasData(
|
||||||
|
new
|
||||||
|
{
|
||||||
|
Id = new Guid("b542bf25-134c-47a2-a0df-84ed14d03c4a"),
|
||||||
|
Deleted = false,
|
||||||
|
Name = "Admin Tenant"
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("CleanArchitecture.Domain.Entities.User", b =>
|
modelBuilder.Entity("CleanArchitecture.Domain.Entities.User", b =>
|
||||||
{
|
{
|
||||||
b.Property<Guid>("Id")
|
b.Property<Guid>("Id")
|
||||||
@ -57,22 +84,44 @@ namespace CleanArchitecture.Infrastructure.Migrations
|
|||||||
b.Property<int>("Role")
|
b.Property<int>("Role")
|
||||||
.HasColumnType("int");
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.Property<Guid>("TenantId")
|
||||||
|
.HasColumnType("uniqueidentifier");
|
||||||
|
|
||||||
b.HasKey("Id");
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("TenantId");
|
||||||
|
|
||||||
b.ToTable("Users");
|
b.ToTable("Users");
|
||||||
|
|
||||||
b.HasData(
|
b.HasData(
|
||||||
new
|
new
|
||||||
{
|
{
|
||||||
Id = new Guid("28fc3d91-6a15-448e-b0b5-0c91a3948961"),
|
Id = new Guid("7e3892c0-9374-49fa-a3fd-53db637a40ae"),
|
||||||
Deleted = false,
|
Deleted = false,
|
||||||
Email = "admin@email.com",
|
Email = "admin@email.com",
|
||||||
FirstName = "Admin",
|
FirstName = "Admin",
|
||||||
LastName = "User",
|
LastName = "User",
|
||||||
Password = "$2a$12$Blal/uiFIJdYsCLTMUik/egLbfg3XhbnxBC6Sb5IKz2ZYhiU/MzL2",
|
Password = "$2a$12$Blal/uiFIJdYsCLTMUik/egLbfg3XhbnxBC6Sb5IKz2ZYhiU/MzL2",
|
||||||
Role = 0
|
Role = 0,
|
||||||
|
TenantId = new Guid("b542bf25-134c-47a2-a0df-84ed14d03c4a")
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("CleanArchitecture.Domain.Entities.User", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("CleanArchitecture.Domain.Entities.Tenant", "Tenant")
|
||||||
|
.WithMany("Users")
|
||||||
|
.HasForeignKey("TenantId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.Navigation("Tenant");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("CleanArchitecture.Domain.Entities.Tenant", b =>
|
||||||
|
{
|
||||||
|
b.Navigation("Users");
|
||||||
|
});
|
||||||
#pragma warning restore 612, 618
|
#pragma warning restore 612, 618
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user