181 lines
8.3 KiB
C#
181 lines
8.3 KiB
C#
using System;
|
|
using Microsoft.EntityFrameworkCore.Migrations;
|
|
|
|
#nullable disable
|
|
|
|
namespace FutureMailAPI.Migrations
|
|
{
|
|
/// <inheritdoc />
|
|
public partial class AddOAuthEntities : Migration
|
|
{
|
|
/// <inheritdoc />
|
|
protected override void Up(MigrationBuilder migrationBuilder)
|
|
{
|
|
migrationBuilder.CreateTable(
|
|
name: "OAuthClients",
|
|
columns: table => new
|
|
{
|
|
Id = table.Column<int>(type: "INTEGER", nullable: false)
|
|
.Annotation("Sqlite:Autoincrement", true),
|
|
ClientId = table.Column<string>(type: "TEXT", nullable: false),
|
|
ClientSecret = table.Column<string>(type: "TEXT", nullable: false),
|
|
Name = table.Column<string>(type: "TEXT", nullable: false),
|
|
RedirectUris = table.Column<string>(type: "TEXT", nullable: false),
|
|
Scopes = table.Column<string>(type: "TEXT", nullable: false),
|
|
IsActive = table.Column<bool>(type: "INTEGER", nullable: false),
|
|
CreatedAt = table.Column<DateTime>(type: "TEXT", nullable: false, defaultValueSql: "CURRENT_TIMESTAMP"),
|
|
UpdatedAt = table.Column<DateTime>(type: "TEXT", nullable: false, defaultValueSql: "CURRENT_TIMESTAMP")
|
|
},
|
|
constraints: table =>
|
|
{
|
|
table.PrimaryKey("PK_OAuthClients", x => x.Id);
|
|
});
|
|
|
|
migrationBuilder.CreateTable(
|
|
name: "OAuthAccessTokens",
|
|
columns: table => new
|
|
{
|
|
Id = table.Column<int>(type: "INTEGER", nullable: false)
|
|
.Annotation("Sqlite:Autoincrement", true),
|
|
Token = table.Column<string>(type: "TEXT", nullable: false),
|
|
ClientId = table.Column<int>(type: "INTEGER", nullable: false),
|
|
UserId = table.Column<int>(type: "INTEGER", nullable: false),
|
|
Scopes = table.Column<string>(type: "TEXT", nullable: false),
|
|
IsRevoked = table.Column<bool>(type: "INTEGER", nullable: false),
|
|
ExpiresAt = table.Column<DateTime>(type: "TEXT", nullable: false),
|
|
CreatedAt = table.Column<DateTime>(type: "TEXT", nullable: false, defaultValueSql: "CURRENT_TIMESTAMP")
|
|
},
|
|
constraints: table =>
|
|
{
|
|
table.PrimaryKey("PK_OAuthAccessTokens", x => x.Id);
|
|
table.ForeignKey(
|
|
name: "FK_OAuthAccessTokens_OAuthClients_ClientId",
|
|
column: x => x.ClientId,
|
|
principalTable: "OAuthClients",
|
|
principalColumn: "Id",
|
|
onDelete: ReferentialAction.Cascade);
|
|
table.ForeignKey(
|
|
name: "FK_OAuthAccessTokens_Users_UserId",
|
|
column: x => x.UserId,
|
|
principalTable: "Users",
|
|
principalColumn: "Id",
|
|
onDelete: ReferentialAction.Cascade);
|
|
});
|
|
|
|
migrationBuilder.CreateTable(
|
|
name: "OAuthAuthorizationCodes",
|
|
columns: table => new
|
|
{
|
|
Id = table.Column<int>(type: "INTEGER", nullable: false)
|
|
.Annotation("Sqlite:Autoincrement", true),
|
|
Code = table.Column<string>(type: "TEXT", nullable: false),
|
|
ClientId = table.Column<int>(type: "INTEGER", nullable: false),
|
|
UserId = table.Column<int>(type: "INTEGER", nullable: false),
|
|
RedirectUri = table.Column<string>(type: "TEXT", nullable: false),
|
|
Scopes = table.Column<string>(type: "TEXT", nullable: false),
|
|
IsUsed = table.Column<bool>(type: "INTEGER", nullable: false),
|
|
ExpiresAt = table.Column<DateTime>(type: "TEXT", nullable: false),
|
|
CreatedAt = table.Column<DateTime>(type: "TEXT", nullable: false, defaultValueSql: "CURRENT_TIMESTAMP")
|
|
},
|
|
constraints: table =>
|
|
{
|
|
table.PrimaryKey("PK_OAuthAuthorizationCodes", x => x.Id);
|
|
table.ForeignKey(
|
|
name: "FK_OAuthAuthorizationCodes_OAuthClients_ClientId",
|
|
column: x => x.ClientId,
|
|
principalTable: "OAuthClients",
|
|
principalColumn: "Id",
|
|
onDelete: ReferentialAction.Cascade);
|
|
table.ForeignKey(
|
|
name: "FK_OAuthAuthorizationCodes_Users_UserId",
|
|
column: x => x.UserId,
|
|
principalTable: "Users",
|
|
principalColumn: "Id",
|
|
onDelete: ReferentialAction.Cascade);
|
|
});
|
|
|
|
migrationBuilder.CreateTable(
|
|
name: "OAuthRefreshTokens",
|
|
columns: table => new
|
|
{
|
|
Id = table.Column<int>(type: "INTEGER", nullable: false)
|
|
.Annotation("Sqlite:Autoincrement", true),
|
|
Token = table.Column<string>(type: "TEXT", nullable: false),
|
|
ClientId = table.Column<int>(type: "INTEGER", nullable: false),
|
|
UserId = table.Column<int>(type: "INTEGER", nullable: false),
|
|
IsUsed = table.Column<bool>(type: "INTEGER", nullable: false),
|
|
ExpiresAt = table.Column<DateTime>(type: "TEXT", nullable: false),
|
|
CreatedAt = table.Column<DateTime>(type: "TEXT", nullable: false, defaultValueSql: "CURRENT_TIMESTAMP")
|
|
},
|
|
constraints: table =>
|
|
{
|
|
table.PrimaryKey("PK_OAuthRefreshTokens", x => x.Id);
|
|
table.ForeignKey(
|
|
name: "FK_OAuthRefreshTokens_OAuthClients_ClientId",
|
|
column: x => x.ClientId,
|
|
principalTable: "OAuthClients",
|
|
principalColumn: "Id",
|
|
onDelete: ReferentialAction.Cascade);
|
|
table.ForeignKey(
|
|
name: "FK_OAuthRefreshTokens_Users_UserId",
|
|
column: x => x.UserId,
|
|
principalTable: "Users",
|
|
principalColumn: "Id",
|
|
onDelete: ReferentialAction.Cascade);
|
|
});
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_OAuthAccessTokens_ClientId",
|
|
table: "OAuthAccessTokens",
|
|
column: "ClientId");
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_OAuthAccessTokens_UserId",
|
|
table: "OAuthAccessTokens",
|
|
column: "UserId");
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_OAuthAuthorizationCodes_ClientId",
|
|
table: "OAuthAuthorizationCodes",
|
|
column: "ClientId");
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_OAuthAuthorizationCodes_UserId",
|
|
table: "OAuthAuthorizationCodes",
|
|
column: "UserId");
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_OAuthClients_ClientId",
|
|
table: "OAuthClients",
|
|
column: "ClientId",
|
|
unique: true);
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_OAuthRefreshTokens_ClientId",
|
|
table: "OAuthRefreshTokens",
|
|
column: "ClientId");
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_OAuthRefreshTokens_UserId",
|
|
table: "OAuthRefreshTokens",
|
|
column: "UserId");
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
protected override void Down(MigrationBuilder migrationBuilder)
|
|
{
|
|
migrationBuilder.DropTable(
|
|
name: "OAuthAccessTokens");
|
|
|
|
migrationBuilder.DropTable(
|
|
name: "OAuthAuthorizationCodes");
|
|
|
|
migrationBuilder.DropTable(
|
|
name: "OAuthRefreshTokens");
|
|
|
|
migrationBuilder.DropTable(
|
|
name: "OAuthClients");
|
|
}
|
|
}
|
|
}
|