Skip to content

Commit 0bc61e3

Browse files
committed
update notification tble
1 parent b730b43 commit 0bc61e3

File tree

5 files changed

+45
-48
lines changed

5 files changed

+45
-48
lines changed

devblog/devblog/Data/AppDbContext.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
2121
{
2222
base.OnModelCreating(modelBuilder);
2323

24-
modelBuilder.Entity<Notification>().HasKey(e => new { e.PostId, e.UserName });
25-
2624
modelBuilder.Entity<UpVote>().HasKey(e => new { e.PostId, e.UserName });
2725

2826
modelBuilder.Entity<DownVote>().HasKey(e => new { e.PostId, e.UserName });

devblog/devblog/Data/AppDbMigrations/20240302162248_initial.Designer.cs renamed to devblog/devblog/Data/AppDbMigrations/20240302173732_initial.Designer.cs

Lines changed: 11 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

devblog/devblog/Data/AppDbMigrations/20240302162248_initial.cs renamed to devblog/devblog/Data/AppDbMigrations/20240302173732_initial.cs

Lines changed: 23 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -12,28 +12,30 @@ public partial class initial : Migration
1212
/// <inheritdoc />
1313
protected override void Up(MigrationBuilder migrationBuilder)
1414
{
15-
//migrationBuilder.AlterDatabase()
16-
// .Annotation("MySql:CharSet", "utf8mb4");
15+
migrationBuilder.AlterDatabase()
16+
.Annotation("MySql:CharSet", "utf8mb4");
1717

18-
//migrationBuilder.CreateTable(
19-
// name: "Notification",
20-
// columns: table => new
21-
// {
22-
// PostId = table.Column<int>(type: "int", nullable: false),
23-
// UserName = table.Column<string>(type: "varchar(255)", nullable: false)
24-
// .Annotation("MySql:CharSet", "utf8mb4"),
25-
// Author = table.Column<string>(type: "longtext", nullable: false)
26-
// .Annotation("MySql:CharSet", "utf8mb4"),
27-
// ImgUrl = table.Column<string>(type: "longtext", nullable: false)
28-
// .Annotation("MySql:CharSet", "utf8mb4"),
29-
// NotificationType = table.Column<string>(type: "longtext", nullable: false)
30-
// .Annotation("MySql:CharSet", "utf8mb4")
31-
// },
32-
// constraints: table =>
33-
// {
34-
// table.PrimaryKey("PK_Notification", x => new { x.PostId, x.UserName });
35-
// })
36-
// .Annotation("MySql:CharSet", "utf8mb4");
18+
migrationBuilder.CreateTable(
19+
name: "Notification",
20+
columns: table => new
21+
{
22+
Id = table.Column<int>(type: "int", nullable: false)
23+
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
24+
PostId = table.Column<int>(type: "int", nullable: false),
25+
UserName = table.Column<string>(type: "varchar(255)", nullable: false)
26+
.Annotation("MySql:CharSet", "utf8mb4"),
27+
Author = table.Column<string>(type: "varchar(255)", nullable: false)
28+
.Annotation("MySql:CharSet", "utf8mb4"),
29+
ImgUrl = table.Column<string>(type: "longtext", nullable: false)
30+
.Annotation("MySql:CharSet", "utf8mb4"),
31+
NotificationType = table.Column<string>(type: "varchar(255)", nullable: false)
32+
.Annotation("MySql:CharSet", "utf8mb4")
33+
},
34+
constraints: table =>
35+
{
36+
table.PrimaryKey("PK_Notification", x => x.Id);
37+
})
38+
.Annotation("MySql:CharSet", "utf8mb4");
3739

3840
//migrationBuilder.CreateTable(
3941
// name: "Post",
@@ -173,20 +175,6 @@ protected override void Up(MigrationBuilder migrationBuilder)
173175
// table: "YtVideo",
174176
// column: "Url",
175177
// unique: true);
176-
177-
migrationBuilder.AddColumn<string>(
178-
name: "Author",
179-
table: "Notification",
180-
type: "varchar(255)",
181-
nullable: false)
182-
.Annotation("MySql:CharSet", "utf8mb4");
183-
184-
migrationBuilder.AddColumn<string>(
185-
name: "ImgUrl",
186-
table: "Notification",
187-
type: "longtext",
188-
nullable: false)
189-
.Annotation("MySql:CharSet", "utf8mb4");
190178
}
191179

192180
/// <inheritdoc />

devblog/devblog/Data/AppDbMigrations/AppDbContextModelSnapshot.cs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,10 @@ protected override void BuildModel(ModelBuilder modelBuilder)
8181

8282
modelBuilder.Entity("devblog.Models.Notification", b =>
8383
{
84-
b.Property<int>("PostId")
84+
b.Property<int>("Id")
85+
.ValueGeneratedOnAdd()
8586
.HasColumnType("int");
8687

87-
b.Property<string>("UserName")
88-
.HasColumnType("varchar(255)");
89-
9088
b.Property<string>("Author")
9189
.IsRequired()
9290
.HasColumnType("longtext");
@@ -99,7 +97,14 @@ protected override void BuildModel(ModelBuilder modelBuilder)
9997
.IsRequired()
10098
.HasColumnType("longtext");
10199

102-
b.HasKey("PostId", "UserName");
100+
b.Property<int>("PostId")
101+
.HasColumnType("int");
102+
103+
b.Property<string>("UserName")
104+
.IsRequired()
105+
.HasColumnType("longtext");
106+
107+
b.HasKey("Id");
103108

104109
b.ToTable("Notification");
105110
});

devblog/devblog/Models/Notification.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
{
33
public class Notification
44
{
5+
public int Id { get; set; }
56
public int PostId { get; set; }
67
public required string UserName { get; set; }
78
public required string Author { get; set; }

0 commit comments

Comments
 (0)