|
| 1 | +using System; |
| 2 | +using System.Collections.Generic; |
| 3 | +using Microsoft.EntityFrameworkCore.Migrations; |
| 4 | + |
| 5 | +#nullable disable |
| 6 | + |
| 7 | +namespace Infrastructure.Migrations; |
| 8 | + |
| 9 | +/// <inheritdoc /> |
| 10 | +public partial class addInitialPostgress : Migration |
| 11 | +{ |
| 12 | + /// <inheritdoc /> |
| 13 | + protected override void Up(MigrationBuilder migrationBuilder) |
| 14 | + { |
| 15 | + migrationBuilder.EnsureSchema( |
| 16 | + name: "public"); |
| 17 | + |
| 18 | + migrationBuilder.CreateTable( |
| 19 | + name: "users", |
| 20 | + schema: "public", |
| 21 | + columns: table => new |
| 22 | + { |
| 23 | + id = table.Column<Guid>(type: "uuid", nullable: false), |
| 24 | + email = table.Column<string>(type: "text", nullable: false), |
| 25 | + first_name = table.Column<string>(type: "text", nullable: false), |
| 26 | + last_name = table.Column<string>(type: "text", nullable: false), |
| 27 | + password_hash = table.Column<string>(type: "text", nullable: false) |
| 28 | + }, |
| 29 | + constraints: table => table.PrimaryKey("pk_users", x => x.id)); |
| 30 | + |
| 31 | + migrationBuilder.CreateTable( |
| 32 | + name: "todo_items", |
| 33 | + schema: "public", |
| 34 | + columns: table => new |
| 35 | + { |
| 36 | + id = table.Column<Guid>(type: "uuid", nullable: false), |
| 37 | + user_id = table.Column<Guid>(type: "uuid", nullable: false), |
| 38 | + description = table.Column<string>(type: "text", nullable: false), |
| 39 | + due_date = table.Column<DateTime>(type: "timestamp with time zone", nullable: true), |
| 40 | + labels = table.Column<List<string>>(type: "text[]", nullable: false), |
| 41 | + is_completed = table.Column<bool>(type: "boolean", nullable: false), |
| 42 | + created_at = table.Column<DateTime>(type: "timestamp with time zone", nullable: false), |
| 43 | + completed_at = table.Column<DateTime>(type: "timestamp with time zone", nullable: true), |
| 44 | + priority = table.Column<int>(type: "integer", nullable: false) |
| 45 | + }, |
| 46 | + constraints: table => |
| 47 | + { |
| 48 | + table.PrimaryKey("pk_todo_items", x => x.id); |
| 49 | + table.ForeignKey( |
| 50 | + name: "fk_todo_items_users_user_id", |
| 51 | + column: x => x.user_id, |
| 52 | + principalSchema: "public", |
| 53 | + principalTable: "users", |
| 54 | + principalColumn: "id", |
| 55 | + onDelete: ReferentialAction.Cascade); |
| 56 | + }); |
| 57 | + |
| 58 | + migrationBuilder.CreateTable( |
| 59 | + name: "user_images", |
| 60 | + schema: "public", |
| 61 | + columns: table => new |
| 62 | + { |
| 63 | + id = table.Column<Guid>(type: "uuid", nullable: false), |
| 64 | + user_id = table.Column<Guid>(type: "uuid", nullable: false), |
| 65 | + image_url = table.Column<string>(type: "text", nullable: true), |
| 66 | + image_data = table.Column<byte[]>(type: "bytea", nullable: true), |
| 67 | + created_at = table.Column<DateTime>(type: "timestamp with time zone", nullable: false) |
| 68 | + }, |
| 69 | + constraints: table => |
| 70 | + { |
| 71 | + table.PrimaryKey("pk_user_images", x => x.id); |
| 72 | + table.ForeignKey( |
| 73 | + name: "fk_user_images_users_user_id", |
| 74 | + column: x => x.user_id, |
| 75 | + principalSchema: "public", |
| 76 | + principalTable: "users", |
| 77 | + principalColumn: "id", |
| 78 | + onDelete: ReferentialAction.Cascade); |
| 79 | + }); |
| 80 | + |
| 81 | + migrationBuilder.CreateIndex( |
| 82 | + name: "ix_todo_items_user_id", |
| 83 | + schema: "public", |
| 84 | + table: "todo_items", |
| 85 | + column: "user_id"); |
| 86 | + |
| 87 | + migrationBuilder.CreateIndex( |
| 88 | + name: "ix_user_images_user_id", |
| 89 | + schema: "public", |
| 90 | + table: "user_images", |
| 91 | + column: "user_id"); |
| 92 | + |
| 93 | + migrationBuilder.CreateIndex( |
| 94 | + name: "ix_users_email", |
| 95 | + schema: "public", |
| 96 | + table: "users", |
| 97 | + column: "email", |
| 98 | + unique: true); |
| 99 | + } |
| 100 | + |
| 101 | + /// <inheritdoc /> |
| 102 | + protected override void Down(MigrationBuilder migrationBuilder) |
| 103 | + { |
| 104 | + migrationBuilder.DropTable( |
| 105 | + name: "todo_items", |
| 106 | + schema: "public"); |
| 107 | + |
| 108 | + migrationBuilder.DropTable( |
| 109 | + name: "user_images", |
| 110 | + schema: "public"); |
| 111 | + |
| 112 | + migrationBuilder.DropTable( |
| 113 | + name: "users", |
| 114 | + schema: "public"); |
| 115 | + } |
| 116 | +} |
0 commit comments