using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace Blahblah.FlowerStory.Server.Migrations
{
    /// <inheritdoc />
    public partial class InitialDb : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.CreateTable(
                name: "tokens",
                columns: table => new
                {
                    tid = table.Column<string>(type: "TEXT", nullable: false),
                    uid = table.Column<int>(type: "INTEGER", nullable: false),
                    logondate = table.Column<long>(type: "INTEGER", nullable: false),
                    activedate = table.Column<long>(type: "INTEGER", nullable: false),
                    expiredate = table.Column<long>(type: "INTEGER", nullable: false),
                    expiresecs = table.Column<int>(type: "INTEGER", nullable: false),
                    verifycode = table.Column<string>(type: "TEXT", nullable: true),
                    clientapp = table.Column<string>(type: "TEXT", nullable: true),
                    deviceid = table.Column<string>(type: "TEXT", nullable: true),
                    clientagent = table.Column<string>(type: "TEXT", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_tokens", x => x.tid);
                });

            migrationBuilder.CreateTable(
                name: "users",
                columns: table => new
                {
                    uid = table.Column<int>(type: "INTEGER", nullable: false)
                        .Annotation("Sqlite:Autoincrement", true),
                    id = table.Column<string>(type: "TEXT", nullable: false),
                    password = table.Column<string>(type: "TEXT", nullable: false),
                    level = table.Column<int>(type: "INTEGER", nullable: false),
                    regdate = table.Column<long>(type: "INTEGER", nullable: false),
                    activedate = table.Column<long>(type: "INTEGER", nullable: true),
                    name = table.Column<string>(type: "TEXT", nullable: false),
                    email = table.Column<string>(type: "TEXT", nullable: true),
                    mobile = table.Column<string>(type: "TEXT", nullable: true),
                    avatar = table.Column<byte[]>(type: "BLOB", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_users", x => x.uid);
                });

            migrationBuilder.CreateTable(
                name: "flowers",
                columns: table => new
                {
                    fid = table.Column<int>(type: "INTEGER", nullable: false)
                        .Annotation("Sqlite:Autoincrement", true),
                    uid = table.Column<int>(type: "INTEGER", nullable: false),
                    categoryid = table.Column<int>(type: "INTEGER", nullable: false),
                    name = table.Column<string>(type: "TEXT", nullable: false),
                    datebuy = table.Column<long>(type: "INTEGER", nullable: false),
                    cost = table.Column<decimal>(type: "real", nullable: true),
                    purchase = table.Column<string>(type: "TEXT", nullable: true),
                    memo = table.Column<string>(type: "TEXT", nullable: true),
                    latitude = table.Column<double>(type: "REAL", nullable: true),
                    longitude = table.Column<double>(type: "REAL", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_flowers", x => x.fid);
                    table.ForeignKey(
                        name: "FK_flowers_users_uid",
                        column: x => x.uid,
                        principalTable: "users",
                        principalColumn: "uid",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "records",
                columns: table => new
                {
                    rid = table.Column<int>(type: "INTEGER", nullable: false)
                        .Annotation("Sqlite:Autoincrement", true),
                    uid = table.Column<int>(type: "INTEGER", nullable: false),
                    fid = table.Column<int>(type: "INTEGER", nullable: false),
                    eid = table.Column<int>(type: "INTEGER", nullable: false),
                    date = table.Column<long>(type: "INTEGER", nullable: false),
                    byuid = table.Column<int>(type: "INTEGER", nullable: true),
                    byname = table.Column<string>(type: "TEXT", nullable: true),
                    memo = table.Column<string>(type: "TEXT", nullable: true),
                    latitude = table.Column<double>(type: "REAL", nullable: true),
                    longitude = table.Column<double>(type: "REAL", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_records", x => x.rid);
                    table.ForeignKey(
                        name: "FK_records_flowers_fid",
                        column: x => x.fid,
                        principalTable: "flowers",
                        principalColumn: "fid",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "FK_records_users_uid",
                        column: x => x.uid,
                        principalTable: "users",
                        principalColumn: "uid",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "photos",
                columns: table => new
                {
                    pid = table.Column<int>(type: "INTEGER", nullable: false)
                        .Annotation("Sqlite:Autoincrement", true),
                    fid = table.Column<int>(type: "INTEGER", nullable: true),
                    rid = table.Column<int>(type: "INTEGER", nullable: true),
                    filetype = table.Column<string>(type: "TEXT", nullable: false),
                    filename = table.Column<string>(type: "TEXT", nullable: false),
                    path = table.Column<string>(type: "TEXT", nullable: false),
                    dateupload = table.Column<long>(type: "INTEGER", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_photos", x => x.pid);
                    table.ForeignKey(
                        name: "FK_photos_flowers_fid",
                        column: x => x.fid,
                        principalTable: "flowers",
                        principalColumn: "fid");
                    table.ForeignKey(
                        name: "FK_photos_records_rid",
                        column: x => x.rid,
                        principalTable: "records",
                        principalColumn: "rid");
                });

            migrationBuilder.CreateIndex(
                name: "IX_flowers_uid",
                table: "flowers",
                column: "uid");

            migrationBuilder.CreateIndex(
                name: "IX_photos_fid",
                table: "photos",
                column: "fid");

            migrationBuilder.CreateIndex(
                name: "IX_photos_rid",
                table: "photos",
                column: "rid");

            migrationBuilder.CreateIndex(
                name: "IX_records_fid",
                table: "records",
                column: "fid");

            migrationBuilder.CreateIndex(
                name: "IX_records_uid",
                table: "records",
                column: "uid");
        }

        /// <inheritdoc />
        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                name: "photos");

            migrationBuilder.DropTable(
                name: "tokens");

            migrationBuilder.DropTable(
                name: "records");

            migrationBuilder.DropTable(
                name: "flowers");

            migrationBuilder.DropTable(
                name: "users");
        }
    }
}