using System; using Microsoft.EntityFrameworkCore.Migrations; #nullable disable #pragma warning disable CA1814 // Prefer jagged arrays over multidimensional namespace MetaCourse.Api.Migrations { /// public partial class InitialCreate : Migration { /// protected override void Up(MigrationBuilder migrationBuilder) { migrationBuilder.CreateTable( name: "Resources", columns: table => new { Id = table.Column(type: "uniqueidentifier", nullable: false), Type = table.Column(type: "nvarchar(max)", nullable: false), Title = table.Column(type: "nvarchar(max)", nullable: false), Content = table.Column(type: "nvarchar(max)", nullable: false), CreatedAt = table.Column(type: "datetime2", nullable: false) }, constraints: table => { table.PrimaryKey("PK_Resources", x => x.Id); }); migrationBuilder.CreateTable( name: "Users", columns: table => new { Id = table.Column(type: "uniqueidentifier", nullable: false), Name = table.Column(type: "nvarchar(max)", nullable: false), Email = table.Column(type: "nvarchar(450)", nullable: false), PasswordHash = table.Column(type: "nvarchar(max)", nullable: false), CreatedAt = table.Column(type: "datetime2", nullable: false) }, constraints: table => { table.PrimaryKey("PK_Users", x => x.Id); }); migrationBuilder.CreateTable( name: "Courses", columns: table => new { Id = table.Column(type: "uniqueidentifier", nullable: false), Title = table.Column(type: "nvarchar(max)", nullable: false), Description = table.Column(type: "nvarchar(max)", nullable: false), Status = table.Column(type: "nvarchar(max)", nullable: false), CreatedAt = table.Column(type: "datetime2", nullable: false), UpdatedAt = table.Column(type: "datetime2", nullable: false), CreatorId = table.Column(type: "uniqueidentifier", nullable: false) }, constraints: table => { table.PrimaryKey("PK_Courses", x => x.Id); table.ForeignKey( name: "FK_Courses_Users_CreatorId", column: x => x.CreatorId, principalTable: "Users", principalColumn: "Id", onDelete: ReferentialAction.Restrict); }); migrationBuilder.CreateTable( name: "UserResourceProgresses", columns: table => new { UserId = table.Column(type: "uniqueidentifier", nullable: false), ResourceId = table.Column(type: "uniqueidentifier", nullable: false), Completed = table.Column(type: "bit", nullable: false), CompletedAt = table.Column(type: "datetime2", nullable: true) }, constraints: table => { table.PrimaryKey("PK_UserResourceProgresses", x => new { x.UserId, x.ResourceId }); table.ForeignKey( name: "FK_UserResourceProgresses_Resources_ResourceId", column: x => x.ResourceId, principalTable: "Resources", principalColumn: "Id", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "FK_UserResourceProgresses_Users_UserId", column: x => x.UserId, principalTable: "Users", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "Topics", columns: table => new { Id = table.Column(type: "uniqueidentifier", nullable: false), Title = table.Column(type: "nvarchar(max)", nullable: false), Description = table.Column(type: "nvarchar(max)", nullable: true), Position = table.Column(type: "int", nullable: false), CourseId = table.Column(type: "uniqueidentifier", nullable: false) }, constraints: table => { table.PrimaryKey("PK_Topics", x => x.Id); table.ForeignKey( name: "FK_Topics_Courses_CourseId", column: x => x.CourseId, principalTable: "Courses", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "UserCourses", columns: table => new { UserId = table.Column(type: "uniqueidentifier", nullable: false), CourseId = table.Column(type: "uniqueidentifier", nullable: false), EnrolledAt = table.Column(type: "datetime2", nullable: false), CompletedAt = table.Column(type: "datetime2", nullable: true) }, constraints: table => { table.PrimaryKey("PK_UserCourses", x => new { x.UserId, x.CourseId }); table.ForeignKey( name: "FK_UserCourses_Courses_CourseId", column: x => x.CourseId, principalTable: "Courses", principalColumn: "Id", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "FK_UserCourses_Users_UserId", column: x => x.UserId, principalTable: "Users", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "TopicResources", columns: table => new { TopicId = table.Column(type: "uniqueidentifier", nullable: false), ResourceId = table.Column(type: "uniqueidentifier", nullable: false), Position = table.Column(type: "int", nullable: false) }, constraints: table => { table.PrimaryKey("PK_TopicResources", x => new { x.TopicId, x.ResourceId }); table.ForeignKey( name: "FK_TopicResources_Resources_ResourceId", column: x => x.ResourceId, principalTable: "Resources", principalColumn: "Id", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "FK_TopicResources_Topics_TopicId", column: x => x.TopicId, principalTable: "Topics", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "UserTopicProgresses", columns: table => new { UserId = table.Column(type: "uniqueidentifier", nullable: false), TopicId = table.Column(type: "uniqueidentifier", nullable: false), Completed = table.Column(type: "bit", nullable: false), CompletedAt = table.Column(type: "datetime2", nullable: true) }, constraints: table => { table.PrimaryKey("PK_UserTopicProgresses", x => new { x.UserId, x.TopicId }); table.ForeignKey( name: "FK_UserTopicProgresses_Topics_TopicId", column: x => x.TopicId, principalTable: "Topics", principalColumn: "Id", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "FK_UserTopicProgresses_Users_UserId", column: x => x.UserId, principalTable: "Users", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.InsertData( table: "Resources", columns: new[] { "Id", "Content", "CreatedAt", "Title", "Type" }, values: new object[,] { { new Guid("00000000-0000-0000-aaaa-000000000001"), "Les hooks permettent d'utiliser le state et d'autres fonctionnalités React dans des composants fonctionnels.", new DateTime(2025, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc), "Guide des Hooks", "Text" }, { new Guid("00000000-0000-0000-aaaa-000000000002"), "https://react.dev", new DateTime(2025, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc), "Documentation officielle React", "Url" }, { new Guid("ffffffff-ffff-ffff-ffff-ffffffffffff"), "https://youtube.com/watch?v=example1", new DateTime(2025, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc), "React en 30 minutes", "Video" } }); migrationBuilder.InsertData( table: "Users", columns: new[] { "Id", "CreatedAt", "Email", "Name", "PasswordHash" }, values: new object[,] { { new Guid("11111111-1111-1111-1111-111111111111"), new DateTime(2025, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc), "alice@metacourse.io", "Alice Dupont", "$2a$11$iVlx6m6E1Nlwe5EuA1m4XeJoWc1P2fgS5i1iwEVo2xYbRNt9gSdFe" }, { new Guid("22222222-2222-2222-2222-222222222222"), new DateTime(2025, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc), "bob@metacourse.io", "Bob Martin", "$2a$11$LIWuKuO3ful3H1AjoRI1n.kmjW9n05alzfOyMCI0iIIO28q5cSOKu" } }); migrationBuilder.InsertData( table: "Courses", columns: new[] { "Id", "CreatedAt", "CreatorId", "Description", "Status", "Title", "UpdatedAt" }, values: new object[,] { { new Guid("aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa"), new DateTime(2025, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc), new Guid("11111111-1111-1111-1111-111111111111"), "Maîtrisez React, Tailwind CSS et TypeScript pour créer des applications web performantes.", "Published", "Développement Web Moderne avec React", new DateTime(2025, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc) }, { new Guid("bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb"), new DateTime(2025, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc), new Guid("22222222-2222-2222-2222-222222222222"), "Apprenez à construire des APIs REST robustes avec ASP.NET Core et FastEndpoints.", "Draft", "API REST avec .NET et FastEndpoints", new DateTime(2025, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc) } }); migrationBuilder.InsertData( table: "Topics", columns: new[] { "Id", "CourseId", "Description", "Position", "Title" }, values: new object[,] { { new Guid("cccccccc-cccc-cccc-cccc-cccccccccccc"), new Guid("aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa"), "Les bases de React : composants, JSX, props.", 1, "Introduction à React" }, { new Guid("dddddddd-dddd-dddd-dddd-dddddddddddd"), new Guid("aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa"), "useState, useEffect et hooks personnalisés.", 2, "Hooks et State" }, { new Guid("eeeeeeee-eeee-eeee-eeee-eeeeeeeeeeee"), new Guid("bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb"), "Principes REST et verbes HTTP.", 1, "Fondamentaux REST" } }); migrationBuilder.InsertData( table: "UserCourses", columns: new[] { "CourseId", "UserId", "CompletedAt", "EnrolledAt" }, values: new object[] { new Guid("aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa"), new Guid("22222222-2222-2222-2222-222222222222"), null, new DateTime(2025, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc) }); migrationBuilder.InsertData( table: "TopicResources", columns: new[] { "ResourceId", "TopicId", "Position" }, values: new object[,] { { new Guid("00000000-0000-0000-aaaa-000000000002"), new Guid("cccccccc-cccc-cccc-cccc-cccccccccccc"), 2 }, { new Guid("ffffffff-ffff-ffff-ffff-ffffffffffff"), new Guid("cccccccc-cccc-cccc-cccc-cccccccccccc"), 1 }, { new Guid("00000000-0000-0000-aaaa-000000000001"), new Guid("dddddddd-dddd-dddd-dddd-dddddddddddd"), 1 } }); migrationBuilder.CreateIndex( name: "IX_Courses_CreatorId", table: "Courses", column: "CreatorId"); migrationBuilder.CreateIndex( name: "IX_TopicResources_ResourceId", table: "TopicResources", column: "ResourceId"); migrationBuilder.CreateIndex( name: "IX_Topics_CourseId", table: "Topics", column: "CourseId"); migrationBuilder.CreateIndex( name: "IX_UserCourses_CourseId", table: "UserCourses", column: "CourseId"); migrationBuilder.CreateIndex( name: "IX_UserResourceProgresses_ResourceId", table: "UserResourceProgresses", column: "ResourceId"); migrationBuilder.CreateIndex( name: "IX_Users_Email", table: "Users", column: "Email", unique: true); migrationBuilder.CreateIndex( name: "IX_UserTopicProgresses_TopicId", table: "UserTopicProgresses", column: "TopicId"); } /// protected override void Down(MigrationBuilder migrationBuilder) { migrationBuilder.DropTable( name: "TopicResources"); migrationBuilder.DropTable( name: "UserCourses"); migrationBuilder.DropTable( name: "UserResourceProgresses"); migrationBuilder.DropTable( name: "UserTopicProgresses"); migrationBuilder.DropTable( name: "Resources"); migrationBuilder.DropTable( name: "Topics"); migrationBuilder.DropTable( name: "Courses"); migrationBuilder.DropTable( name: "Users"); } } }