This commit is contained in:
2021-01-02 11:56:24 +01:00
parent 39e5c84cf6
commit 96ab03a5fb
12 changed files with 301 additions and 120 deletions

View File

@@ -1,21 +1,23 @@
-- migrate:up
CREATE TABLE "users" (
CREATE TABLE "accounts" (
"id" uuid PRIMARY KEY,
"created" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
"username" text NOT NULL,
"password" text NOT NULL
"accountName" text NOT NULL,
"apiKey" text,
"password" text
);
CREATE UNIQUE INDEX idx_accountname ON accounts ("accountName");
CREATE TABLE "usersFields" (
CREATE TABLE "accountsFields" (
"id" uuid PRIMARY KEY,
"created" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
"userId" uuid NOT NULL,
"accountId" uuid NOT NULL,
"name" text NOT NULL,
"value" text[] NOT NULL
);
ALTER TABLE "usersFields"
ADD FOREIGN KEY ("userId") REFERENCES "users" ("id") ON DELETE RESTRICT ON UPDATE RESTRICT;
CREATE UNIQUE INDEX idx_usersfields ON "usersFields" ("userId", "name");
ALTER TABLE "accountsFields"
ADD FOREIGN KEY ("accountId") REFERENCES "accounts" ("id") ON DELETE RESTRICT ON UPDATE RESTRICT;
CREATE UNIQUE INDEX idx_accountsfields ON "accountsFields" ("accountId", "name");
-- migrate:down