using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Infrastructure.Migrations
{
///
public partial class FileSystem : Migration
{
///
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Nodes",
columns: table => new
{
Id = table.Column(type: "INTEGER", nullable: false)
.Annotation("Sqlite:Autoincrement", true),
Name = table.Column(type: "TEXT", nullable: false),
Latitude = table.Column(type: "REAL", nullable: false),
Longitude = table.Column(type: "REAL", nullable: false),
Type = table.Column(type: "INTEGER", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Nodes", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Robots",
columns: table => new
{
Id = table.Column(type: "INTEGER", nullable: false)
.Annotation("Sqlite:Autoincrement", true),
Name = table.Column(type: "TEXT", nullable: false),
Model = table.Column(type: "TEXT", nullable: false),
Type = table.Column(type: "INTEGER", nullable: false),
Status = table.Column(type: "INTEGER", nullable: false),
BatteryLevel = table.Column(type: "REAL", nullable: false),
SerialNumber = table.Column(type: "TEXT", nullable: true),
AccessKeyHash = table.Column(type: "TEXT", nullable: true),
CurrentNodeId = table.Column(type: "INTEGER", nullable: true),
CurrentLatitude = table.Column(type: "REAL", nullable: true),
CurrentLongitude = table.Column(type: "REAL", nullable: true),
TargetNodeId = table.Column(type: "INTEGER", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Robots", x => x.Id);
table.ForeignKey(
name: "FK_Robots_Nodes_CurrentNodeId",
column: x => x.CurrentNodeId,
principalTable: "Nodes",
principalColumn: "Id",
onDelete: ReferentialAction.SetNull);
table.ForeignKey(
name: "FK_Robots_Nodes_TargetNodeId",
column: x => x.TargetNodeId,
principalTable: "Nodes",
principalColumn: "Id",
onDelete: ReferentialAction.SetNull);
});
migrationBuilder.CreateTable(
name: "Files",
columns: table => new
{
Id = table.Column(type: "INTEGER", nullable: false)
.Annotation("Sqlite:Autoincrement", true),
FileName = table.Column(type: "TEXT", nullable: false),
FilePath = table.Column(type: "TEXT", nullable: false),
ContentType = table.Column(type: "TEXT", nullable: false),
FileSize = table.Column(type: "INTEGER", nullable: false),
UploadedAt = table.Column(type: "TEXT", nullable: false),
OrderId = table.Column(type: "INTEGER", nullable: true),
UserId = table.Column(type: "INTEGER", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Files", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Users",
columns: table => new
{
Id = table.Column(type: "INTEGER", nullable: false)
.Annotation("Sqlite:Autoincrement", true),
UserName = table.Column(type: "TEXT", nullable: false),
Email = table.Column(type: "TEXT", nullable: false),
GoogleId = table.Column(type: "TEXT", nullable: true),
PhoneNumber = table.Column(type: "TEXT", nullable: true),
PasswordHash = table.Column(type: "TEXT", nullable: false),
Role = table.Column(type: "INTEGER", nullable: true),
PersonalNodeId = table.Column(type: "INTEGER", nullable: true),
ProfilePhotoId = table.Column(type: "INTEGER", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Users", x => x.Id);
table.ForeignKey(
name: "FK_Users_Files_ProfilePhotoId",
column: x => x.ProfilePhotoId,
principalTable: "Files",
principalColumn: "Id",
onDelete: ReferentialAction.SetNull);
table.ForeignKey(
name: "FK_Users_Nodes_PersonalNodeId",
column: x => x.PersonalNodeId,
principalTable: "Nodes",
principalColumn: "Id",
onDelete: ReferentialAction.SetNull);
});
migrationBuilder.CreateTable(
name: "Orders",
columns: table => new
{
Id = table.Column(type: "INTEGER", nullable: false)
.Annotation("Sqlite:Autoincrement", true),
Name = table.Column(type: "TEXT", nullable: false),
Description = table.Column(type: "TEXT", nullable: false),
Weight = table.Column(type: "REAL", nullable: false),
DeliveryPrice = table.Column(type: "TEXT", nullable: false),
ProductPrice = table.Column(type: "TEXT", nullable: false),
IsProductPaid = table.Column(type: "INTEGER", nullable: false),
Status = table.Column(type: "INTEGER", nullable: false),
CreatedAt = table.Column(type: "TEXT", nullable: false),
CompletedAt = table.Column(type: "TEXT", nullable: true),
SenderId = table.Column(type: "INTEGER", nullable: false),
RecipientId = table.Column(type: "INTEGER", nullable: false),
RobotId = table.Column(type: "INTEGER", nullable: true),
PickupNodeId = table.Column(type: "INTEGER", nullable: false),
DropoffNodeId = table.Column(type: "INTEGER", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Orders", x => x.Id);
table.ForeignKey(
name: "FK_Orders_Nodes_DropoffNodeId",
column: x => x.DropoffNodeId,
principalTable: "Nodes",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
table.ForeignKey(
name: "FK_Orders_Nodes_PickupNodeId",
column: x => x.PickupNodeId,
principalTable: "Nodes",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
table.ForeignKey(
name: "FK_Orders_Robots_RobotId",
column: x => x.RobotId,
principalTable: "Robots",
principalColumn: "Id",
onDelete: ReferentialAction.SetNull);
table.ForeignKey(
name: "FK_Orders_Users_RecipientId",
column: x => x.RecipientId,
principalTable: "Users",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
table.ForeignKey(
name: "FK_Orders_Users_SenderId",
column: x => x.SenderId,
principalTable: "Users",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
});
migrationBuilder.CreateIndex(
name: "IX_Files_OrderId",
table: "Files",
column: "OrderId");
migrationBuilder.CreateIndex(
name: "IX_Orders_DropoffNodeId",
table: "Orders",
column: "DropoffNodeId");
migrationBuilder.CreateIndex(
name: "IX_Orders_PickupNodeId",
table: "Orders",
column: "PickupNodeId");
migrationBuilder.CreateIndex(
name: "IX_Orders_RecipientId",
table: "Orders",
column: "RecipientId");
migrationBuilder.CreateIndex(
name: "IX_Orders_RobotId",
table: "Orders",
column: "RobotId");
migrationBuilder.CreateIndex(
name: "IX_Orders_SenderId",
table: "Orders",
column: "SenderId");
migrationBuilder.CreateIndex(
name: "IX_Robots_CurrentNodeId",
table: "Robots",
column: "CurrentNodeId");
migrationBuilder.CreateIndex(
name: "IX_Robots_SerialNumber",
table: "Robots",
column: "SerialNumber",
unique: true);
migrationBuilder.CreateIndex(
name: "IX_Robots_TargetNodeId",
table: "Robots",
column: "TargetNodeId");
migrationBuilder.CreateIndex(
name: "IX_Users_PersonalNodeId",
table: "Users",
column: "PersonalNodeId");
migrationBuilder.CreateIndex(
name: "IX_Users_ProfilePhotoId",
table: "Users",
column: "ProfilePhotoId",
unique: true);
migrationBuilder.AddForeignKey(
name: "FK_Files_Orders_OrderId",
table: "Files",
column: "OrderId",
principalTable: "Orders",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
}
///
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(
name: "FK_Files_Orders_OrderId",
table: "Files");
migrationBuilder.DropTable(
name: "Orders");
migrationBuilder.DropTable(
name: "Robots");
migrationBuilder.DropTable(
name: "Users");
migrationBuilder.DropTable(
name: "Files");
migrationBuilder.DropTable(
name: "Nodes");
}
}
}