109 lines
3.6 KiB
C#
109 lines
3.6 KiB
C#
using System;
|
|
using Microsoft.EntityFrameworkCore.Migrations;
|
|
using NodaTime;
|
|
|
|
#nullable disable
|
|
|
|
namespace Foxchat.Identity.Migrations
|
|
{
|
|
/// <inheritdoc />
|
|
public partial class AddApplications : Migration
|
|
{
|
|
/// <inheritdoc />
|
|
protected override void Up(MigrationBuilder migrationBuilder)
|
|
{
|
|
migrationBuilder.AddColumn<Guid>(
|
|
name: "application_id",
|
|
table: "tokens",
|
|
type: "uuid",
|
|
nullable: false,
|
|
defaultValue: new Guid("00000000-0000-0000-0000-000000000000"));
|
|
|
|
migrationBuilder.AddColumn<Instant>(
|
|
name: "expires",
|
|
table: "tokens",
|
|
type: "timestamp with time zone",
|
|
nullable: false,
|
|
defaultValue: NodaTime.Instant.FromUnixTimeTicks(0L));
|
|
|
|
migrationBuilder.AddColumn<byte[]>(
|
|
name: "hash",
|
|
table: "tokens",
|
|
type: "bytea",
|
|
nullable: false,
|
|
defaultValue: new byte[0]);
|
|
|
|
migrationBuilder.AddColumn<string[]>(
|
|
name: "scopes",
|
|
table: "tokens",
|
|
type: "text[]",
|
|
nullable: false,
|
|
defaultValue: new string[0]);
|
|
|
|
migrationBuilder.CreateTable(
|
|
name: "applications",
|
|
columns: table => new
|
|
{
|
|
id = table.Column<Guid>(type: "uuid", nullable: false),
|
|
client_id = table.Column<string>(type: "text", nullable: false),
|
|
client_secret = table.Column<string>(type: "text", nullable: false),
|
|
name = table.Column<string>(type: "text", nullable: false),
|
|
scopes = table.Column<string[]>(type: "text[]", nullable: false)
|
|
},
|
|
constraints: table =>
|
|
{
|
|
table.PrimaryKey("pk_applications", x => x.id);
|
|
});
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "ix_tokens_application_id",
|
|
table: "tokens",
|
|
column: "application_id");
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "ix_applications_client_id",
|
|
table: "applications",
|
|
column: "client_id",
|
|
unique: true);
|
|
|
|
migrationBuilder.AddForeignKey(
|
|
name: "fk_tokens_applications_application_id",
|
|
table: "tokens",
|
|
column: "application_id",
|
|
principalTable: "applications",
|
|
principalColumn: "id",
|
|
onDelete: ReferentialAction.Cascade);
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
protected override void Down(MigrationBuilder migrationBuilder)
|
|
{
|
|
migrationBuilder.DropForeignKey(
|
|
name: "fk_tokens_applications_application_id",
|
|
table: "tokens");
|
|
|
|
migrationBuilder.DropTable(
|
|
name: "applications");
|
|
|
|
migrationBuilder.DropIndex(
|
|
name: "ix_tokens_application_id",
|
|
table: "tokens");
|
|
|
|
migrationBuilder.DropColumn(
|
|
name: "application_id",
|
|
table: "tokens");
|
|
|
|
migrationBuilder.DropColumn(
|
|
name: "expires",
|
|
table: "tokens");
|
|
|
|
migrationBuilder.DropColumn(
|
|
name: "hash",
|
|
table: "tokens");
|
|
|
|
migrationBuilder.DropColumn(
|
|
name: "scopes",
|
|
table: "tokens");
|
|
}
|
|
}
|
|
}
|