修改测试迁移
continuous-integration/drone/push Build is passing

This commit is contained in:
hang
2024-09-12 23:51:51 +08:00
parent c9b1e5f92a
commit 603f6e095c
15 changed files with 616 additions and 107 deletions
@@ -1,5 +1,7 @@
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using Microsoft.EntityFrameworkCore.Metadata.Conventions;
using System;
using System.ComponentModel.DataAnnotations;
using System.Linq;
namespace IRaCIS.Core.Test
@@ -17,7 +19,30 @@ namespace IRaCIS.Core.Test
.Where(
property => property.ClrType == typeof(string))))
{
property.Builder.HasMaxLength(200);
// 获取 MaxLength 特性
var maxLengthAttribute = property.PropertyInfo?.GetCustomAttributes(typeof(MaxLengthAttribute), false)
.FirstOrDefault() as MaxLengthAttribute;
// 获取 StringLength 特性
var stringLengthAttribute = property.PropertyInfo?.GetCustomAttributes(typeof(StringLengthAttribute), false)
.FirstOrDefault() as StringLengthAttribute;
// 输出调试信息,看看是哪种特性生效
if (stringLengthAttribute != null)
{
//Console.WriteLine($"{property.Name}: StringLength({stringLengthAttribute.MaximumLength})");
property.Builder.HasMaxLength(stringLengthAttribute.MaximumLength);
}
else if (maxLengthAttribute != null)
{
//Console.WriteLine($"{property.Name}: MaxLength (no specific length, allowing max)");
}
else
{
//Console.WriteLine($"{property.Name}: Default length 200");
property.Builder.HasMaxLength(200);
}
}
}
}
@@ -26,11 +26,14 @@ public partial class IRCContext : DbContext
//public virtual DbSet<ReadModule> ReadModule { get; set; }
//public virtual DbSet<TestStringLength> TestStringLength { get; set; }
public virtual DbSet<TestStr> TestStr { get; set; }
public virtual DbSet<Project> Project { get; set; }
public virtual DbSet<ProjectUser> ProjectUser { get; set; }
public virtual DbSet<ProjectUser2> ProjectUser2 { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
@@ -0,0 +1,146 @@
// <auto-generated />
using System;
using IRaCIS.Core.Test.CodeFirstTest.MSSQL;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
#nullable disable
namespace IRaCIS.Core.Test.CodeFirstTest.MSSQL.Migrations
{
[DbContext(typeof(IRCContext))]
[Migration("20240912145208_test")]
partial class test
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "8.0.8")
.HasAnnotation("Relational:MaxIdentifierLength", 128);
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
modelBuilder.Entity("IRaCIS.Core.Test.CodeFirstTest.MSSQL.Project", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uniqueidentifier");
b.Property<DateTime>("CreateTime")
.HasColumnType("datetime2");
b.Property<Guid>("CreateUserId")
.HasColumnType("uniqueidentifier");
b.Property<DateTime>("UpdateTime")
.HasColumnType("datetime2");
b.Property<Guid>("UpdateUserId")
.HasColumnType("uniqueidentifier");
b.HasKey("Id");
b.ToTable("Project");
});
modelBuilder.Entity("IRaCIS.Core.Test.CodeFirstTest.MSSQL.ProjectUser", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uniqueidentifier");
b.Property<string>("Code")
.IsRequired()
.HasMaxLength(200)
.HasColumnType("nvarchar(200)");
b.Property<DateTime>("CreateTime")
.HasColumnType("datetime2");
b.Property<Guid>("CreateUserId")
.HasColumnType("uniqueidentifier");
b.Property<string>("Name2")
.IsRequired()
.HasMaxLength(200)
.HasColumnType("nvarchar(200)");
b.Property<string>("OtherName")
.IsRequired()
.HasMaxLength(200)
.HasColumnType("nvarchar(200)");
b.Property<Guid>("ProjectId")
.HasColumnType("uniqueidentifier");
b.Property<DateTime>("UpdateTime")
.HasColumnType("datetime2");
b.Property<Guid>("UpdateUserId")
.HasColumnType("uniqueidentifier");
b.HasKey("Id");
b.HasIndex("ProjectId");
b.ToTable("ProjectUser");
});
modelBuilder.Entity("IRaCIS.Core.Test.CodeFirstTest.MSSQL.ProjectUser2", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uniqueidentifier");
b.Property<DateTime>("CreateTime")
.HasColumnType("datetime2");
b.Property<Guid>("CreateUserId")
.HasColumnType("uniqueidentifier");
b.Property<Guid>("ProjectId")
.HasColumnType("uniqueidentifier");
b.Property<DateTime>("UpdateTime")
.HasColumnType("datetime2");
b.Property<Guid>("UpdateUserId")
.HasColumnType("uniqueidentifier");
b.HasKey("Id");
b.HasIndex("ProjectId");
b.ToTable("ProjectUser2");
});
modelBuilder.Entity("IRaCIS.Core.Test.CodeFirstTest.MSSQL.ProjectUser", b =>
{
b.HasOne("IRaCIS.Core.Test.CodeFirstTest.MSSQL.Project", "Project")
.WithMany()
.HasForeignKey("ProjectId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Project");
});
modelBuilder.Entity("IRaCIS.Core.Test.CodeFirstTest.MSSQL.ProjectUser2", b =>
{
b.HasOne("IRaCIS.Core.Test.CodeFirstTest.MSSQL.Project", "Project")
.WithMany()
.HasForeignKey("ProjectId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Project");
});
#pragma warning restore 612, 618
}
}
}
@@ -0,0 +1,40 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace IRaCIS.Core.Test.CodeFirstTest.MSSQL.Migrations
{
/// <inheritdoc />
public partial class test : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.RenameColumn(
name: "Name",
table: "ProjectUser",
newName: "OtherName");
migrationBuilder.AddColumn<string>(
name: "Name2",
table: "ProjectUser",
type: "nvarchar(200)",
maxLength: 200,
nullable: false,
defaultValue: "");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "Name2",
table: "ProjectUser");
migrationBuilder.RenameColumn(
name: "OtherName",
table: "ProjectUser",
newName: "Name");
}
}
}
@@ -0,0 +1,183 @@
// <auto-generated />
using System;
using IRaCIS.Core.Test.CodeFirstTest.MSSQL;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
#nullable disable
namespace IRaCIS.Core.Test.CodeFirstTest.MSSQL.Migrations
{
[DbContext(typeof(IRCContext))]
[Migration("20240912152420_testSTR")]
partial class testSTR
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "8.0.8")
.HasAnnotation("Relational:MaxIdentifierLength", 128);
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
modelBuilder.Entity("IRaCIS.Core.Test.CodeFirstTest.MSSQL.Project", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uniqueidentifier");
b.Property<DateTime>("CreateTime")
.HasColumnType("datetime2");
b.Property<Guid>("CreateUserId")
.HasColumnType("uniqueidentifier");
b.Property<DateTime>("UpdateTime")
.HasColumnType("datetime2");
b.Property<Guid>("UpdateUserId")
.HasColumnType("uniqueidentifier");
b.HasKey("Id");
b.ToTable("Project");
});
modelBuilder.Entity("IRaCIS.Core.Test.CodeFirstTest.MSSQL.ProjectUser", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uniqueidentifier");
b.Property<string>("Code")
.IsRequired()
.HasMaxLength(200)
.HasColumnType("nvarchar(200)");
b.Property<DateTime>("CreateTime")
.HasColumnType("datetime2");
b.Property<Guid>("CreateUserId")
.HasColumnType("uniqueidentifier");
b.Property<string>("Name2")
.IsRequired()
.HasMaxLength(200)
.HasColumnType("nvarchar(200)");
b.Property<string>("OtherName")
.IsRequired()
.HasMaxLength(200)
.HasColumnType("nvarchar(200)");
b.Property<Guid>("ProjectId")
.HasColumnType("uniqueidentifier");
b.Property<DateTime>("UpdateTime")
.HasColumnType("datetime2");
b.Property<Guid>("UpdateUserId")
.HasColumnType("uniqueidentifier");
b.HasKey("Id");
b.HasIndex("ProjectId");
b.ToTable("ProjectUser");
});
modelBuilder.Entity("IRaCIS.Core.Test.CodeFirstTest.MSSQL.ProjectUser2", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uniqueidentifier");
b.Property<DateTime>("CreateTime")
.HasColumnType("datetime2");
b.Property<Guid>("CreateUserId")
.HasColumnType("uniqueidentifier");
b.Property<Guid>("ProjectId")
.HasColumnType("uniqueidentifier");
b.Property<DateTime>("UpdateTime")
.HasColumnType("datetime2");
b.Property<Guid>("UpdateUserId")
.HasColumnType("uniqueidentifier");
b.HasKey("Id");
b.HasIndex("ProjectId");
b.ToTable("ProjectUser2");
});
modelBuilder.Entity("IRaCIS.Core.Test.CodeFirstTest.MSSQL.TestStr", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uniqueidentifier");
b.Property<DateTime>("CreateTime")
.HasColumnType("datetime2");
b.Property<Guid>("CreateUserId")
.HasColumnType("uniqueidentifier");
b.Property<string>("DefineLength")
.IsRequired()
.HasMaxLength(400)
.HasColumnType("nvarchar(400)");
b.Property<string>("DefualtLength")
.IsRequired()
.HasMaxLength(200)
.HasColumnType("nvarchar(200)");
b.Property<string>("MaxLength")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<DateTime>("UpdateTime")
.HasColumnType("datetime2");
b.Property<Guid>("UpdateUserId")
.HasColumnType("uniqueidentifier");
b.HasKey("Id");
b.ToTable("TestStr");
});
modelBuilder.Entity("IRaCIS.Core.Test.CodeFirstTest.MSSQL.ProjectUser", b =>
{
b.HasOne("IRaCIS.Core.Test.CodeFirstTest.MSSQL.Project", "Project")
.WithMany()
.HasForeignKey("ProjectId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Project");
});
modelBuilder.Entity("IRaCIS.Core.Test.CodeFirstTest.MSSQL.ProjectUser2", b =>
{
b.HasOne("IRaCIS.Core.Test.CodeFirstTest.MSSQL.Project", "Project")
.WithMany()
.HasForeignKey("ProjectId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Project");
});
#pragma warning restore 612, 618
}
}
}
@@ -0,0 +1,40 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace IRaCIS.Core.Test.CodeFirstTest.MSSQL.Migrations
{
/// <inheritdoc />
public partial class testSTR : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "TestStr",
columns: table => new
{
Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
DefualtLength = table.Column<string>(type: "nvarchar(200)", maxLength: 200, nullable: false),
MaxLength = table.Column<string>(type: "nvarchar(max)", nullable: false),
DefineLength = table.Column<string>(type: "nvarchar(400)", maxLength: 400, nullable: false),
CreateUserId = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
CreateTime = table.Column<DateTime>(type: "datetime2", nullable: false),
UpdateUserId = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
UpdateTime = table.Column<DateTime>(type: "datetime2", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_TestStr", x => x.Id);
});
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "TestStr");
}
}
}
@@ -42,7 +42,7 @@ namespace IRaCIS.Core.Test.CodeFirstTest.MSSQL.Migrations
b.HasKey("Id");
b.ToTable("Project", (string)null);
b.ToTable("Project");
});
modelBuilder.Entity("IRaCIS.Core.Test.CodeFirstTest.MSSQL.ProjectUser", b =>
@@ -62,7 +62,12 @@ namespace IRaCIS.Core.Test.CodeFirstTest.MSSQL.Migrations
b.Property<Guid>("CreateUserId")
.HasColumnType("uniqueidentifier");
b.Property<string>("Name")
b.Property<string>("Name2")
.IsRequired()
.HasMaxLength(200)
.HasColumnType("nvarchar(200)");
b.Property<string>("OtherName")
.IsRequired()
.HasMaxLength(200)
.HasColumnType("nvarchar(200)");
@@ -80,7 +85,7 @@ namespace IRaCIS.Core.Test.CodeFirstTest.MSSQL.Migrations
b.HasIndex("ProjectId");
b.ToTable("ProjectUser", (string)null);
b.ToTable("ProjectUser");
});
modelBuilder.Entity("IRaCIS.Core.Test.CodeFirstTest.MSSQL.ProjectUser2", b =>
@@ -108,7 +113,44 @@ namespace IRaCIS.Core.Test.CodeFirstTest.MSSQL.Migrations
b.HasIndex("ProjectId");
b.ToTable("ProjectUser2", (string)null);
b.ToTable("ProjectUser2");
});
modelBuilder.Entity("IRaCIS.Core.Test.CodeFirstTest.MSSQL.TestStr", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uniqueidentifier");
b.Property<DateTime>("CreateTime")
.HasColumnType("datetime2");
b.Property<Guid>("CreateUserId")
.HasColumnType("uniqueidentifier");
b.Property<string>("DefineLength")
.IsRequired()
.HasMaxLength(400)
.HasColumnType("nvarchar(400)");
b.Property<string>("DefualtLength")
.IsRequired()
.HasMaxLength(200)
.HasColumnType("nvarchar(200)");
b.Property<string>("MaxLength")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<DateTime>("UpdateTime")
.HasColumnType("datetime2");
b.Property<Guid>("UpdateUserId")
.HasColumnType("uniqueidentifier");
b.HasKey("Id");
b.ToTable("TestStr");
});
modelBuilder.Entity("IRaCIS.Core.Test.CodeFirstTest.MSSQL.ProjectUser", b =>
@@ -180,5 +180,19 @@ namespace IRaCIS.Core.Test.CodeFirstTest.MSSQL
}
#endregion
#region
public class TestStr: BaseFullAuditEntity
{
public string DefualtLength { get; set; }
[MaxLength]
public string MaxLength { get; set; }
[StringLength(400)]
public string DefineLength { get; set;}
}
#endregion
}