-- CreateTable
CREATE TABLE "users" (
    "npub" TEXT NOT NULL PRIMARY KEY,
    "registeredAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "lastPayment" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "subscriptionDuration" INTEGER
);

-- CreateTable
CREATE TABLE "aliases" (
    "npub" TEXT NOT NULL,
    "alias" TEXT NOT NULL,

    PRIMARY KEY ("npub", "alias"),
    CONSTRAINT "aliases_npub_fkey" FOREIGN KEY ("npub") REFERENCES "users" ("npub") ON DELETE RESTRICT ON UPDATE CASCADE
);

-- CreateTable
CREATE TABLE "mail_queue" (
    "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
    "alias" TEXT NOT NULL,
    "sender" TEXT NOT NULL,
    "data" TEXT NOT NULL,
    "createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
    CONSTRAINT "mail_queue_alias_fkey" FOREIGN KEY ("alias") REFERENCES "aliases" ("alias") ON DELETE RESTRICT ON UPDATE CASCADE
);

-- CreateIndex
CREATE UNIQUE INDEX "aliases_alias_key" ON "aliases"("alias");
