101 lines
3.9 KiB
C#
101 lines
3.9 KiB
C#
using System;
|
|
using Microsoft.EntityFrameworkCore.Migrations;
|
|
|
|
#nullable disable
|
|
|
|
namespace MessengerApi.Db.Sql.Migrations
|
|
{
|
|
/// <inheritdoc />
|
|
public partial class Initial : Migration
|
|
{
|
|
/// <inheritdoc />
|
|
protected override void Up(MigrationBuilder migrationBuilder)
|
|
{
|
|
migrationBuilder.CreateTable(
|
|
name: "Messages",
|
|
columns: table => new
|
|
{
|
|
Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
|
|
CreatedUtc = table.Column<DateTime>(type: "datetime2", nullable: false),
|
|
FromId = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
|
|
ToId = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
|
|
IsDelivered = table.Column<bool>(type: "bit", nullable: false),
|
|
IsAcknowledged = table.Column<bool>(type: "bit", nullable: false),
|
|
PayloadType = table.Column<string>(type: "nvarchar(max)", nullable: true),
|
|
Payload = table.Column<string>(type: "nvarchar(max)", nullable: true),
|
|
PayloadLifespanInSeconds = table.Column<int>(type: "int", nullable: false)
|
|
},
|
|
constraints: table =>
|
|
{
|
|
table.PrimaryKey("PK_Messages", x => x.Id);
|
|
});
|
|
|
|
migrationBuilder.CreateTable(
|
|
name: "Users",
|
|
columns: table => new
|
|
{
|
|
Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
|
|
ApiKey = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
|
|
Name = table.Column<string>(type: "nvarchar(max)", nullable: true),
|
|
IsEnabled = table.Column<bool>(type: "bit", nullable: false)
|
|
},
|
|
constraints: table =>
|
|
{
|
|
table.PrimaryKey("PK_Users", x => x.Id);
|
|
});
|
|
|
|
migrationBuilder.CreateTable(
|
|
name: "UserRoutes",
|
|
columns: table => new
|
|
{
|
|
Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
|
|
FromId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
|
|
ToId = table.Column<Guid>(type: "uniqueidentifier", nullable: true)
|
|
},
|
|
constraints: table =>
|
|
{
|
|
table.PrimaryKey("PK_UserRoutes", x => x.Id);
|
|
table.ForeignKey(
|
|
name: "FK_UserRoutes_Users_FromId",
|
|
column: x => x.FromId,
|
|
principalTable: "Users",
|
|
principalColumn: "Id");
|
|
table.ForeignKey(
|
|
name: "FK_UserRoutes_Users_ToId",
|
|
column: x => x.ToId,
|
|
principalTable: "Users",
|
|
principalColumn: "Id");
|
|
});
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_Messages_ToId_IsDelivered",
|
|
table: "Messages",
|
|
columns: new[] { "ToId", "IsDelivered" })
|
|
.Annotation("SqlServer:Clustered", false);
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_UserRoutes_FromId",
|
|
table: "UserRoutes",
|
|
column: "FromId");
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_UserRoutes_ToId",
|
|
table: "UserRoutes",
|
|
column: "ToId");
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
protected override void Down(MigrationBuilder migrationBuilder)
|
|
{
|
|
migrationBuilder.DropTable(
|
|
name: "Messages");
|
|
|
|
migrationBuilder.DropTable(
|
|
name: "UserRoutes");
|
|
|
|
migrationBuilder.DropTable(
|
|
name: "Users");
|
|
}
|
|
}
|
|
}
|