-- Add local username/password authentication support.
ALTER TABLE "User" ADD COLUMN "username" TEXT;

CREATE UNIQUE INDEX "User_username_key" ON "User"("username");

CREATE TABLE "LocalCredential" (
  "id" TEXT NOT NULL,
  "userUid" TEXT NOT NULL,
  "passwordHash" TEXT NOT NULL,
  "createdOn" TIMESTAMPTZ(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
  "updatedOn" TIMESTAMPTZ(3) NOT NULL,

  CONSTRAINT "LocalCredential_pkey" PRIMARY KEY ("id")
);

CREATE UNIQUE INDEX "LocalCredential_userUid_key" ON "LocalCredential"("userUid");

ALTER TABLE "LocalCredential"
ADD CONSTRAINT "LocalCredential_userUid_fkey"
FOREIGN KEY ("userUid") REFERENCES "User"("uid")
ON DELETE CASCADE ON UPDATE CASCADE;
