using System;
using System.Collections.Generic;
using System.Text.Json;
using DysonNetwork.Sphere.Account;
using DysonNetwork.Sphere.Storage;
using Microsoft.EntityFrameworkCore.Migrations;
using NetTopologySuite.Geometries;
using NodaTime;
using NpgsqlTypes;
#nullable disable
namespace DysonNetwork.Sphere.Migrations
{
    /// 
    public partial class InitialMigration : Migration
    {
        /// 
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.AlterDatabase()
                .Annotation("Npgsql:PostgresExtension:postgis", ",,");
            migrationBuilder.CreateTable(
                name: "accounts",
                columns: table => new
                {
                    id = table.Column(type: "uuid", nullable: false),
                    name = table.Column(type: "character varying(256)", maxLength: 256, nullable: false),
                    nick = table.Column(type: "character varying(256)", maxLength: 256, nullable: false),
                    language = table.Column(type: "character varying(32)", maxLength: 32, nullable: false),
                    activated_at = table.Column(type: "timestamp with time zone", nullable: true),
                    is_superuser = table.Column(type: "boolean", nullable: false),
                    created_at = table.Column(type: "timestamp with time zone", nullable: false),
                    updated_at = table.Column(type: "timestamp with time zone", nullable: false),
                    deleted_at = table.Column(type: "timestamp with time zone", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("pk_accounts", x => x.id);
                });
            migrationBuilder.CreateTable(
                name: "permission_groups",
                columns: table => new
                {
                    id = table.Column(type: "uuid", nullable: false),
                    key = table.Column(type: "character varying(1024)", maxLength: 1024, nullable: false),
                    created_at = table.Column(type: "timestamp with time zone", nullable: false),
                    updated_at = table.Column(type: "timestamp with time zone", nullable: false),
                    deleted_at = table.Column(type: "timestamp with time zone", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("pk_permission_groups", x => x.id);
                });
            migrationBuilder.CreateTable(
                name: "post_categories",
                columns: table => new
                {
                    id = table.Column(type: "uuid", nullable: false),
                    slug = table.Column(type: "character varying(128)", maxLength: 128, nullable: false),
                    name = table.Column(type: "character varying(256)", maxLength: 256, nullable: true),
                    created_at = table.Column(type: "timestamp with time zone", nullable: false),
                    updated_at = table.Column(type: "timestamp with time zone", nullable: false),
                    deleted_at = table.Column(type: "timestamp with time zone", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("pk_post_categories", x => x.id);
                });
            migrationBuilder.CreateTable(
                name: "post_tags",
                columns: table => new
                {
                    id = table.Column(type: "uuid", nullable: false),
                    slug = table.Column(type: "character varying(128)", maxLength: 128, nullable: false),
                    name = table.Column(type: "character varying(256)", maxLength: 256, nullable: true),
                    created_at = table.Column(type: "timestamp with time zone", nullable: false),
                    updated_at = table.Column(type: "timestamp with time zone", nullable: false),
                    deleted_at = table.Column(type: "timestamp with time zone", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("pk_post_tags", x => x.id);
                });
            migrationBuilder.CreateTable(
                name: "account_auth_factors",
                columns: table => new
                {
                    id = table.Column(type: "uuid", nullable: false),
                    type = table.Column(type: "integer", nullable: false),
                    secret = table.Column(type: "character varying(8196)", maxLength: 8196, nullable: true),
                    account_id = table.Column(type: "uuid", nullable: false),
                    created_at = table.Column(type: "timestamp with time zone", nullable: false),
                    updated_at = table.Column(type: "timestamp with time zone", nullable: false),
                    deleted_at = table.Column(type: "timestamp with time zone", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("pk_account_auth_factors", x => x.id);
                    table.ForeignKey(
                        name: "fk_account_auth_factors_accounts_account_id",
                        column: x => x.account_id,
                        principalTable: "accounts",
                        principalColumn: "id",
                        onDelete: ReferentialAction.Cascade);
                });
            migrationBuilder.CreateTable(
                name: "account_check_in_results",
                columns: table => new
                {
                    id = table.Column(type: "uuid", nullable: false),
                    level = table.Column(type: "integer", nullable: false),
                    reward_points = table.Column(type: "numeric", nullable: true),
                    reward_experience = table.Column(type: "integer", nullable: true),
                    tips = table.Column>(type: "jsonb", nullable: false),
                    account_id = table.Column(type: "uuid", nullable: false),
                    created_at = table.Column(type: "timestamp with time zone", nullable: false),
                    updated_at = table.Column(type: "timestamp with time zone", nullable: false),
                    deleted_at = table.Column(type: "timestamp with time zone", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("pk_account_check_in_results", x => x.id);
                    table.ForeignKey(
                        name: "fk_account_check_in_results_accounts_account_id",
                        column: x => x.account_id,
                        principalTable: "accounts",
                        principalColumn: "id",
                        onDelete: ReferentialAction.Cascade);
                });
            migrationBuilder.CreateTable(
                name: "account_contacts",
                columns: table => new
                {
                    id = table.Column(type: "uuid", nullable: false),
                    type = table.Column(type: "integer", nullable: false),
                    verified_at = table.Column(type: "timestamp with time zone", nullable: true),
                    content = table.Column(type: "character varying(1024)", maxLength: 1024, nullable: false),
                    account_id = table.Column(type: "uuid", nullable: false),
                    created_at = table.Column(type: "timestamp with time zone", nullable: false),
                    updated_at = table.Column(type: "timestamp with time zone", nullable: false),
                    deleted_at = table.Column(type: "timestamp with time zone", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("pk_account_contacts", x => x.id);
                    table.ForeignKey(
                        name: "fk_account_contacts_accounts_account_id",
                        column: x => x.account_id,
                        principalTable: "accounts",
                        principalColumn: "id",
                        onDelete: ReferentialAction.Cascade);
                });
            migrationBuilder.CreateTable(
                name: "account_relationships",
                columns: table => new
                {
                    account_id = table.Column(type: "uuid", nullable: false),
                    related_id = table.Column(type: "uuid", nullable: false),
                    expired_at = table.Column(type: "timestamp with time zone", nullable: true),
                    status = table.Column(type: "integer", nullable: false),
                    created_at = table.Column(type: "timestamp with time zone", nullable: false),
                    updated_at = table.Column(type: "timestamp with time zone", nullable: false),
                    deleted_at = table.Column(type: "timestamp with time zone", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("pk_account_relationships", x => new { x.account_id, x.related_id });
                    table.ForeignKey(
                        name: "fk_account_relationships_accounts_account_id",
                        column: x => x.account_id,
                        principalTable: "accounts",
                        principalColumn: "id",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "fk_account_relationships_accounts_related_id",
                        column: x => x.related_id,
                        principalTable: "accounts",
                        principalColumn: "id",
                        onDelete: ReferentialAction.Cascade);
                });
            migrationBuilder.CreateTable(
                name: "account_statuses",
                columns: table => new
                {
                    id = table.Column(type: "uuid", nullable: false),
                    attitude = table.Column(type: "integer", nullable: false),
                    is_invisible = table.Column(type: "boolean", nullable: false),
                    is_not_disturb = table.Column(type: "boolean", nullable: false),
                    label = table.Column(type: "character varying(1024)", maxLength: 1024, nullable: true),
                    cleared_at = table.Column(type: "timestamp with time zone", nullable: true),
                    account_id = table.Column(type: "uuid", nullable: false),
                    created_at = table.Column(type: "timestamp with time zone", nullable: false),
                    updated_at = table.Column(type: "timestamp with time zone", nullable: false),
                    deleted_at = table.Column(type: "timestamp with time zone", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("pk_account_statuses", x => x.id);
                    table.ForeignKey(
                        name: "fk_account_statuses_accounts_account_id",
                        column: x => x.account_id,
                        principalTable: "accounts",
                        principalColumn: "id",
                        onDelete: ReferentialAction.Cascade);
                });
            migrationBuilder.CreateTable(
                name: "activities",
                columns: table => new
                {
                    id = table.Column(type: "uuid", nullable: false),
                    type = table.Column(type: "character varying(1024)", maxLength: 1024, nullable: false),
                    resource_identifier = table.Column(type: "character varying(4096)", maxLength: 4096, nullable: false),
                    visibility = table.Column(type: "integer", nullable: false),
                    meta = table.Column>(type: "jsonb", nullable: false),
                    users_visible = table.Column>(type: "jsonb", nullable: false),
                    account_id = table.Column(type: "uuid", nullable: false),
                    created_at = table.Column(type: "timestamp with time zone", nullable: false),
                    updated_at = table.Column(type: "timestamp with time zone", nullable: false),
                    deleted_at = table.Column(type: "timestamp with time zone", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("pk_activities", x => x.id);
                    table.ForeignKey(
                        name: "fk_activities_accounts_account_id",
                        column: x => x.account_id,
                        principalTable: "accounts",
                        principalColumn: "id",
                        onDelete: ReferentialAction.Cascade);
                });
            migrationBuilder.CreateTable(
                name: "auth_challenges",
                columns: table => new
                {
                    id = table.Column(type: "uuid", nullable: false),
                    expired_at = table.Column(type: "timestamp with time zone", nullable: true),
                    step_remain = table.Column(type: "integer", nullable: false),
                    step_total = table.Column(type: "integer", nullable: false),
                    failed_attempts = table.Column(type: "integer", nullable: false),
                    platform = table.Column(type: "integer", nullable: false),
                    type = table.Column(type: "integer", nullable: false),
                    blacklist_factors = table.Column>(type: "jsonb", nullable: false),
                    audiences = table.Column>(type: "jsonb", nullable: false),
                    scopes = table.Column>(type: "jsonb", nullable: false),
                    ip_address = table.Column(type: "character varying(128)", maxLength: 128, nullable: true),
                    user_agent = table.Column(type: "character varying(512)", maxLength: 512, nullable: true),
                    device_id = table.Column(type: "character varying(256)", maxLength: 256, nullable: true),
                    nonce = table.Column(type: "character varying(1024)", maxLength: 1024, nullable: true),
                    location = table.Column(type: "geometry", nullable: true),
                    account_id = table.Column(type: "uuid", nullable: false),
                    created_at = table.Column(type: "timestamp with time zone", nullable: false),
                    updated_at = table.Column(type: "timestamp with time zone", nullable: false),
                    deleted_at = table.Column(type: "timestamp with time zone", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("pk_auth_challenges", x => x.id);
                    table.ForeignKey(
                        name: "fk_auth_challenges_accounts_account_id",
                        column: x => x.account_id,
                        principalTable: "accounts",
                        principalColumn: "id",
                        onDelete: ReferentialAction.Cascade);
                });
            migrationBuilder.CreateTable(
                name: "badges",
                columns: table => new
                {
                    id = table.Column(type: "uuid", nullable: false),
                    type = table.Column(type: "character varying(1024)", maxLength: 1024, nullable: false),
                    label = table.Column(type: "character varying(1024)", maxLength: 1024, nullable: true),
                    caption = table.Column(type: "character varying(4096)", maxLength: 4096, nullable: true),
                    meta = table.Column>(type: "jsonb", nullable: false),
                    expired_at = table.Column(type: "timestamp with time zone", nullable: true),
                    account_id = table.Column(type: "uuid", nullable: false),
                    created_at = table.Column(type: "timestamp with time zone", nullable: false),
                    updated_at = table.Column(type: "timestamp with time zone", nullable: false),
                    deleted_at = table.Column(type: "timestamp with time zone", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("pk_badges", x => x.id);
                    table.ForeignKey(
                        name: "fk_badges_accounts_account_id",
                        column: x => x.account_id,
                        principalTable: "accounts",
                        principalColumn: "id",
                        onDelete: ReferentialAction.Cascade);
                });
            migrationBuilder.CreateTable(
                name: "magic_spells",
                columns: table => new
                {
                    id = table.Column(type: "uuid", nullable: false),
                    spell = table.Column(type: "character varying(1024)", maxLength: 1024, nullable: false),
                    type = table.Column(type: "integer", nullable: false),
                    expires_at = table.Column(type: "timestamp with time zone", nullable: true),
                    affected_at = table.Column(type: "timestamp with time zone", nullable: true),
                    meta = table.Column>(type: "jsonb", nullable: false),
                    account_id = table.Column(type: "uuid", nullable: true),
                    created_at = table.Column(type: "timestamp with time zone", nullable: false),
                    updated_at = table.Column(type: "timestamp with time zone", nullable: false),
                    deleted_at = table.Column(type: "timestamp with time zone", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("pk_magic_spells", x => x.id);
                    table.ForeignKey(
                        name: "fk_magic_spells_accounts_account_id",
                        column: x => x.account_id,
                        principalTable: "accounts",
                        principalColumn: "id");
                });
            migrationBuilder.CreateTable(
                name: "notification_push_subscriptions",
                columns: table => new
                {
                    id = table.Column(type: "uuid", nullable: false),
                    device_id = table.Column(type: "character varying(4096)", maxLength: 4096, nullable: false),
                    device_token = table.Column(type: "character varying(4096)", maxLength: 4096, nullable: false),
                    provider = table.Column(type: "integer", nullable: false),
                    last_used_at = table.Column(type: "timestamp with time zone", nullable: true),
                    account_id = table.Column(type: "uuid", nullable: false),
                    created_at = table.Column(type: "timestamp with time zone", nullable: false),
                    updated_at = table.Column(type: "timestamp with time zone", nullable: false),
                    deleted_at = table.Column(type: "timestamp with time zone", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("pk_notification_push_subscriptions", x => x.id);
                    table.ForeignKey(
                        name: "fk_notification_push_subscriptions_accounts_account_id",
                        column: x => x.account_id,
                        principalTable: "accounts",
                        principalColumn: "id",
                        onDelete: ReferentialAction.Cascade);
                });
            migrationBuilder.CreateTable(
                name: "notifications",
                columns: table => new
                {
                    id = table.Column(type: "uuid", nullable: false),
                    topic = table.Column(type: "character varying(1024)", maxLength: 1024, nullable: false),
                    title = table.Column(type: "character varying(1024)", maxLength: 1024, nullable: true),
                    subtitle = table.Column(type: "character varying(2048)", maxLength: 2048, nullable: true),
                    content = table.Column(type: "character varying(4096)", maxLength: 4096, nullable: true),
                    meta = table.Column>(type: "jsonb", nullable: true),
                    priority = table.Column(type: "integer", nullable: false),
                    viewed_at = table.Column(type: "timestamp with time zone", nullable: true),
                    account_id = table.Column(type: "uuid", nullable: false),
                    created_at = table.Column(type: "timestamp with time zone", nullable: false),
                    updated_at = table.Column(type: "timestamp with time zone", nullable: false),
                    deleted_at = table.Column(type: "timestamp with time zone", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("pk_notifications", x => x.id);
                    table.ForeignKey(
                        name: "fk_notifications_accounts_account_id",
                        column: x => x.account_id,
                        principalTable: "accounts",
                        principalColumn: "id",
                        onDelete: ReferentialAction.Cascade);
                });
            migrationBuilder.CreateTable(
                name: "wallets",
                columns: table => new
                {
                    id = table.Column(type: "uuid", nullable: false),
                    account_id = table.Column(type: "uuid", nullable: false),
                    created_at = table.Column(type: "timestamp with time zone", nullable: false),
                    updated_at = table.Column(type: "timestamp with time zone", nullable: false),
                    deleted_at = table.Column(type: "timestamp with time zone", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("pk_wallets", x => x.id);
                    table.ForeignKey(
                        name: "fk_wallets_accounts_account_id",
                        column: x => x.account_id,
                        principalTable: "accounts",
                        principalColumn: "id",
                        onDelete: ReferentialAction.Cascade);
                });
            migrationBuilder.CreateTable(
                name: "permission_group_members",
                columns: table => new
                {
                    group_id = table.Column(type: "uuid", nullable: false),
                    actor = table.Column(type: "character varying(1024)", maxLength: 1024, nullable: false),
                    expired_at = table.Column(type: "timestamp with time zone", nullable: true),
                    affected_at = table.Column(type: "timestamp with time zone", nullable: true),
                    created_at = table.Column(type: "timestamp with time zone", nullable: false),
                    updated_at = table.Column(type: "timestamp with time zone", nullable: false),
                    deleted_at = table.Column(type: "timestamp with time zone", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("pk_permission_group_members", x => new { x.group_id, x.actor });
                    table.ForeignKey(
                        name: "fk_permission_group_members_permission_groups_group_id",
                        column: x => x.group_id,
                        principalTable: "permission_groups",
                        principalColumn: "id",
                        onDelete: ReferentialAction.Cascade);
                });
            migrationBuilder.CreateTable(
                name: "permission_nodes",
                columns: table => new
                {
                    id = table.Column(type: "uuid", nullable: false),
                    actor = table.Column(type: "character varying(1024)", maxLength: 1024, nullable: false),
                    area = table.Column(type: "character varying(1024)", maxLength: 1024, nullable: false),
                    key = table.Column(type: "character varying(1024)", maxLength: 1024, nullable: false),
                    value = table.Column(type: "jsonb", nullable: false),
                    expired_at = table.Column(type: "timestamp with time zone", nullable: true),
                    affected_at = table.Column(type: "timestamp with time zone", nullable: true),
                    group_id = table.Column(type: "uuid", nullable: true),
                    created_at = table.Column(type: "timestamp with time zone", nullable: false),
                    updated_at = table.Column(type: "timestamp with time zone", nullable: false),
                    deleted_at = table.Column(type: "timestamp with time zone", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("pk_permission_nodes", x => x.id);
                    table.ForeignKey(
                        name: "fk_permission_nodes_permission_groups_group_id",
                        column: x => x.group_id,
                        principalTable: "permission_groups",
                        principalColumn: "id");
                });
            migrationBuilder.CreateTable(
                name: "auth_sessions",
                columns: table => new
                {
                    id = table.Column(type: "uuid", nullable: false),
                    label = table.Column(type: "character varying(1024)", maxLength: 1024, nullable: true),
                    last_granted_at = table.Column(type: "timestamp with time zone", nullable: true),
                    expired_at = table.Column(type: "timestamp with time zone", nullable: true),
                    account_id = table.Column(type: "uuid", nullable: false),
                    challenge_id = table.Column(type: "uuid", nullable: false),
                    created_at = table.Column(type: "timestamp with time zone", nullable: false),
                    updated_at = table.Column(type: "timestamp with time zone", nullable: false),
                    deleted_at = table.Column(type: "timestamp with time zone", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("pk_auth_sessions", x => x.id);
                    table.ForeignKey(
                        name: "fk_auth_sessions_accounts_account_id",
                        column: x => x.account_id,
                        principalTable: "accounts",
                        principalColumn: "id",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "fk_auth_sessions_auth_challenges_challenge_id",
                        column: x => x.challenge_id,
                        principalTable: "auth_challenges",
                        principalColumn: "id",
                        onDelete: ReferentialAction.Cascade);
                });
            migrationBuilder.CreateTable(
                name: "payment_transactions",
                columns: table => new
                {
                    id = table.Column(type: "uuid", nullable: false),
                    currency = table.Column(type: "character varying(128)", maxLength: 128, nullable: false),
                    amount = table.Column(type: "numeric", nullable: false),
                    remarks = table.Column(type: "character varying(4096)", maxLength: 4096, nullable: true),
                    type = table.Column(type: "integer", nullable: false),
                    payer_wallet_id = table.Column(type: "uuid", nullable: true),
                    payee_wallet_id = table.Column(type: "uuid", nullable: true),
                    created_at = table.Column(type: "timestamp with time zone", nullable: false),
                    updated_at = table.Column(type: "timestamp with time zone", nullable: false),
                    deleted_at = table.Column(type: "timestamp with time zone", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("pk_payment_transactions", x => x.id);
                    table.ForeignKey(
                        name: "fk_payment_transactions_wallets_payee_wallet_id",
                        column: x => x.payee_wallet_id,
                        principalTable: "wallets",
                        principalColumn: "id");
                    table.ForeignKey(
                        name: "fk_payment_transactions_wallets_payer_wallet_id",
                        column: x => x.payer_wallet_id,
                        principalTable: "wallets",
                        principalColumn: "id");
                });
            migrationBuilder.CreateTable(
                name: "wallet_pockets",
                columns: table => new
                {
                    id = table.Column(type: "uuid", nullable: false),
                    currency = table.Column(type: "character varying(128)", maxLength: 128, nullable: false),
                    amount = table.Column(type: "numeric", nullable: false),
                    wallet_id = table.Column(type: "uuid", nullable: false),
                    created_at = table.Column(type: "timestamp with time zone", nullable: false),
                    updated_at = table.Column(type: "timestamp with time zone", nullable: false),
                    deleted_at = table.Column(type: "timestamp with time zone", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("pk_wallet_pockets", x => x.id);
                    table.ForeignKey(
                        name: "fk_wallet_pockets_wallets_wallet_id",
                        column: x => x.wallet_id,
                        principalTable: "wallets",
                        principalColumn: "id",
                        onDelete: ReferentialAction.Cascade);
                });
            migrationBuilder.CreateTable(
                name: "action_logs",
                columns: table => new
                {
                    id = table.Column(type: "uuid", nullable: false),
                    action = table.Column(type: "character varying(4096)", maxLength: 4096, nullable: false),
                    meta = table.Column>(type: "jsonb", nullable: false),
                    user_agent = table.Column(type: "character varying(512)", maxLength: 512, nullable: true),
                    ip_address = table.Column(type: "character varying(128)", maxLength: 128, nullable: true),
                    location = table.Column(type: "geometry", nullable: true),
                    account_id = table.Column(type: "uuid", nullable: false),
                    session_id = table.Column(type: "uuid", nullable: true),
                    created_at = table.Column(type: "timestamp with time zone", nullable: false),
                    updated_at = table.Column(type: "timestamp with time zone", nullable: false),
                    deleted_at = table.Column(type: "timestamp with time zone", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("pk_action_logs", x => x.id);
                    table.ForeignKey(
                        name: "fk_action_logs_accounts_account_id",
                        column: x => x.account_id,
                        principalTable: "accounts",
                        principalColumn: "id",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "fk_action_logs_auth_sessions_session_id",
                        column: x => x.session_id,
                        principalTable: "auth_sessions",
                        principalColumn: "id");
                });
            migrationBuilder.CreateTable(
                name: "account_profiles",
                columns: table => new
                {
                    id = table.Column(type: "uuid", nullable: false),
                    first_name = table.Column(type: "character varying(256)", maxLength: 256, nullable: true),
                    middle_name = table.Column(type: "character varying(256)", maxLength: 256, nullable: true),
                    last_name = table.Column(type: "character varying(256)", maxLength: 256, nullable: true),
                    bio = table.Column(type: "character varying(4096)", maxLength: 4096, nullable: true),
                    experience = table.Column(type: "integer", nullable: false),
                    picture_id = table.Column(type: "character varying(32)", maxLength: 32, nullable: true),
                    background_id = table.Column(type: "character varying(32)", maxLength: 32, nullable: true),
                    account_id = table.Column(type: "uuid", nullable: false),
                    created_at = table.Column(type: "timestamp with time zone", nullable: false),
                    updated_at = table.Column(type: "timestamp with time zone", nullable: false),
                    deleted_at = table.Column(type: "timestamp with time zone", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("pk_account_profiles", x => x.id);
                    table.ForeignKey(
                        name: "fk_account_profiles_accounts_id",
                        column: x => x.id,
                        principalTable: "accounts",
                        principalColumn: "id",
                        onDelete: ReferentialAction.Cascade);
                });
            migrationBuilder.CreateTable(
                name: "chat_members",
                columns: table => new
                {
                    id = table.Column(type: "uuid", nullable: false),
                    chat_room_id = table.Column(type: "uuid", nullable: false),
                    account_id = table.Column(type: "uuid", nullable: false),
                    nick = table.Column(type: "character varying(1024)", maxLength: 1024, nullable: true),
                    role = table.Column(type: "integer", nullable: false),
                    notify = table.Column(type: "integer", nullable: false),
                    joined_at = table.Column(type: "timestamp with time zone", nullable: true),
                    leave_at = table.Column(type: "timestamp with time zone", nullable: true),
                    is_bot = table.Column(type: "boolean", nullable: false),
                    created_at = table.Column(type: "timestamp with time zone", nullable: false),
                    updated_at = table.Column(type: "timestamp with time zone", nullable: false),
                    deleted_at = table.Column(type: "timestamp with time zone", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("pk_chat_members", x => x.id);
                    table.UniqueConstraint("ak_chat_members_chat_room_id_account_id", x => new { x.chat_room_id, x.account_id });
                    table.ForeignKey(
                        name: "fk_chat_members_accounts_account_id",
                        column: x => x.account_id,
                        principalTable: "accounts",
                        principalColumn: "id",
                        onDelete: ReferentialAction.Cascade);
                });
            migrationBuilder.CreateTable(
                name: "chat_messages",
                columns: table => new
                {
                    id = table.Column(type: "uuid", nullable: false),
                    type = table.Column(type: "text", nullable: false),
                    content = table.Column(type: "character varying(4096)", maxLength: 4096, nullable: true),
                    meta = table.Column>(type: "jsonb", nullable: true),
                    members_mentioned = table.Column>(type: "jsonb", nullable: true),
                    nonce = table.Column(type: "character varying(36)", maxLength: 36, nullable: false),
                    edited_at = table.Column(type: "timestamp with time zone", nullable: true),
                    replied_message_id = table.Column(type: "uuid", nullable: true),
                    forwarded_message_id = table.Column(type: "uuid", nullable: true),
                    sender_id = table.Column(type: "uuid", nullable: false),
                    chat_room_id = table.Column(type: "uuid", nullable: false),
                    created_at = table.Column(type: "timestamp with time zone", nullable: false),
                    updated_at = table.Column(type: "timestamp with time zone", nullable: false),
                    deleted_at = table.Column(type: "timestamp with time zone", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("pk_chat_messages", x => x.id);
                    table.ForeignKey(
                        name: "fk_chat_messages_chat_members_sender_id",
                        column: x => x.sender_id,
                        principalTable: "chat_members",
                        principalColumn: "id",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "fk_chat_messages_chat_messages_forwarded_message_id",
                        column: x => x.forwarded_message_id,
                        principalTable: "chat_messages",
                        principalColumn: "id",
                        onDelete: ReferentialAction.Restrict);
                    table.ForeignKey(
                        name: "fk_chat_messages_chat_messages_replied_message_id",
                        column: x => x.replied_message_id,
                        principalTable: "chat_messages",
                        principalColumn: "id",
                        onDelete: ReferentialAction.Restrict);
                });
            migrationBuilder.CreateTable(
                name: "chat_reactions",
                columns: table => new
                {
                    id = table.Column(type: "uuid", nullable: false),
                    message_id = table.Column(type: "uuid", nullable: false),
                    sender_id = table.Column(type: "uuid", nullable: false),
                    symbol = table.Column(type: "character varying(256)", maxLength: 256, nullable: false),
                    attitude = table.Column(type: "integer", nullable: false),
                    created_at = table.Column(type: "timestamp with time zone", nullable: false),
                    updated_at = table.Column(type: "timestamp with time zone", nullable: false),
                    deleted_at = table.Column(type: "timestamp with time zone", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("pk_chat_reactions", x => x.id);
                    table.ForeignKey(
                        name: "fk_chat_reactions_chat_members_sender_id",
                        column: x => x.sender_id,
                        principalTable: "chat_members",
                        principalColumn: "id",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "fk_chat_reactions_chat_messages_message_id",
                        column: x => x.message_id,
                        principalTable: "chat_messages",
                        principalColumn: "id",
                        onDelete: ReferentialAction.Cascade);
                });
            migrationBuilder.CreateTable(
                name: "chat_read_receipts",
                columns: table => new
                {
                    message_id = table.Column(type: "uuid", nullable: false),
                    sender_id = table.Column(type: "uuid", nullable: false),
                    created_at = table.Column(type: "timestamp with time zone", nullable: false),
                    updated_at = table.Column(type: "timestamp with time zone", nullable: false),
                    deleted_at = table.Column(type: "timestamp with time zone", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("pk_chat_read_receipts", x => new { x.message_id, x.sender_id });
                    table.ForeignKey(
                        name: "fk_chat_read_receipts_chat_members_sender_id",
                        column: x => x.sender_id,
                        principalTable: "chat_members",
                        principalColumn: "id",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "fk_chat_read_receipts_chat_messages_message_id",
                        column: x => x.message_id,
                        principalTable: "chat_messages",
                        principalColumn: "id",
                        onDelete: ReferentialAction.Cascade);
                });
            migrationBuilder.CreateTable(
                name: "chat_realtime_call",
                columns: table => new
                {
                    id = table.Column(type: "uuid", nullable: false),
                    title = table.Column(type: "text", nullable: true),
                    ended_at = table.Column(type: "timestamp with time zone", nullable: true),
                    sender_id = table.Column(type: "uuid", nullable: false),
                    room_id = table.Column(type: "uuid", nullable: false),
                    created_at = table.Column(type: "timestamp with time zone", nullable: false),
                    updated_at = table.Column