|
| 1 | +using Microsoft.EntityFrameworkCore.Migrations; |
| 2 | +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; |
| 3 | + |
| 4 | +namespace Infrastructure.Data.Migrations |
| 5 | +{ |
| 6 | + public partial class initial : Migration |
| 7 | + { |
| 8 | + protected override void Up(MigrationBuilder migrationBuilder) |
| 9 | + { |
| 10 | + migrationBuilder.CreateTable( |
| 11 | + name: "Couriers", |
| 12 | + columns: table => new |
| 13 | + { |
| 14 | + Id = table.Column<long>(type: "bigint", nullable: false) |
| 15 | + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), |
| 16 | + Login = table.Column<string>(type: "text", nullable: true), |
| 17 | + Password = table.Column<string>(type: "text", nullable: true) |
| 18 | + }, |
| 19 | + constraints: table => |
| 20 | + { |
| 21 | + table.PrimaryKey("PK_Couriers", x => x.Id); |
| 22 | + }); |
| 23 | + |
| 24 | + migrationBuilder.CreateTable( |
| 25 | + name: "LatLngs", |
| 26 | + columns: table => new |
| 27 | + { |
| 28 | + Id = table.Column<long>(type: "bigint", nullable: false) |
| 29 | + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), |
| 30 | + Lat = table.Column<float>(type: "real", nullable: false), |
| 31 | + Lng = table.Column<float>(type: "real", nullable: false), |
| 32 | + CourierId = table.Column<long>(type: "bigint", nullable: true) |
| 33 | + }, |
| 34 | + constraints: table => |
| 35 | + { |
| 36 | + table.PrimaryKey("PK_LatLngs", x => x.Id); |
| 37 | + table.ForeignKey( |
| 38 | + name: "FK_LatLngs_Couriers_CourierId", |
| 39 | + column: x => x.CourierId, |
| 40 | + principalTable: "Couriers", |
| 41 | + principalColumn: "Id", |
| 42 | + onDelete: ReferentialAction.Restrict); |
| 43 | + }); |
| 44 | + |
| 45 | + migrationBuilder.CreateTable( |
| 46 | + name: "Orders", |
| 47 | + columns: table => new |
| 48 | + { |
| 49 | + Id = table.Column<long>(type: "bigint", nullable: false) |
| 50 | + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), |
| 51 | + DestinationId = table.Column<long>(type: "bigint", nullable: false), |
| 52 | + CourierId = table.Column<long>(type: "bigint", nullable: true) |
| 53 | + }, |
| 54 | + constraints: table => |
| 55 | + { |
| 56 | + table.PrimaryKey("PK_Orders", x => x.Id); |
| 57 | + table.ForeignKey( |
| 58 | + name: "FK_Orders_Couriers_CourierId", |
| 59 | + column: x => x.CourierId, |
| 60 | + principalTable: "Couriers", |
| 61 | + principalColumn: "Id", |
| 62 | + onDelete: ReferentialAction.Restrict); |
| 63 | + table.ForeignKey( |
| 64 | + name: "FK_Orders_LatLngs_DestinationId", |
| 65 | + column: x => x.DestinationId, |
| 66 | + principalTable: "LatLngs", |
| 67 | + principalColumn: "Id", |
| 68 | + onDelete: ReferentialAction.Cascade); |
| 69 | + }); |
| 70 | + |
| 71 | + migrationBuilder.CreateTable( |
| 72 | + name: "OrderProducts", |
| 73 | + columns: table => new |
| 74 | + { |
| 75 | + Id = table.Column<long>(type: "bigint", nullable: false) |
| 76 | + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), |
| 77 | + Title = table.Column<string>(type: "text", nullable: true), |
| 78 | + OrderId = table.Column<long>(type: "bigint", nullable: false) |
| 79 | + }, |
| 80 | + constraints: table => |
| 81 | + { |
| 82 | + table.PrimaryKey("PK_OrderProducts", x => x.Id); |
| 83 | + table.ForeignKey( |
| 84 | + name: "FK_OrderProducts_Orders_OrderId", |
| 85 | + column: x => x.OrderId, |
| 86 | + principalTable: "Orders", |
| 87 | + principalColumn: "Id", |
| 88 | + onDelete: ReferentialAction.Cascade); |
| 89 | + }); |
| 90 | + |
| 91 | + migrationBuilder.CreateIndex( |
| 92 | + name: "IX_LatLngs_CourierId", |
| 93 | + table: "LatLngs", |
| 94 | + column: "CourierId"); |
| 95 | + |
| 96 | + migrationBuilder.CreateIndex( |
| 97 | + name: "IX_OrderProducts_OrderId", |
| 98 | + table: "OrderProducts", |
| 99 | + column: "OrderId"); |
| 100 | + |
| 101 | + migrationBuilder.CreateIndex( |
| 102 | + name: "IX_Orders_CourierId", |
| 103 | + table: "Orders", |
| 104 | + column: "CourierId"); |
| 105 | + |
| 106 | + migrationBuilder.CreateIndex( |
| 107 | + name: "IX_Orders_DestinationId", |
| 108 | + table: "Orders", |
| 109 | + column: "DestinationId"); |
| 110 | + } |
| 111 | + |
| 112 | + protected override void Down(MigrationBuilder migrationBuilder) |
| 113 | + { |
| 114 | + migrationBuilder.DropTable( |
| 115 | + name: "OrderProducts"); |
| 116 | + |
| 117 | + migrationBuilder.DropTable( |
| 118 | + name: "Orders"); |
| 119 | + |
| 120 | + migrationBuilder.DropTable( |
| 121 | + name: "LatLngs"); |
| 122 | + |
| 123 | + migrationBuilder.DropTable( |
| 124 | + name: "Couriers"); |
| 125 | + } |
| 126 | + } |
| 127 | +} |
0 commit comments