auth-api/db/migrations/20201207191913_first.sql

34 lines
1.1 KiB
MySQL
Raw Normal View History

2020-12-29 13:46:58 +01:00
-- migrate:up
2021-01-02 11:56:24 +01:00
CREATE TABLE "accounts" (
2020-12-29 13:46:58 +01:00
"id" uuid PRIMARY KEY,
"created" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
"name" text NOT NULL,
2021-01-02 11:56:24 +01:00
"apiKey" text,
"password" text
2020-12-29 13:46:58 +01:00
);
CREATE UNIQUE INDEX idx_accountname ON accounts ("name");
2020-12-29 13:46:58 +01:00
2021-01-02 11:56:24 +01:00
CREATE TABLE "accountsFields" (
2020-12-29 13:46:58 +01:00
"id" uuid PRIMARY KEY,
"created" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
2021-01-02 11:56:24 +01:00
"accountId" uuid NOT NULL,
2020-12-29 13:46:58 +01:00
"name" text NOT NULL,
"value" text[] NOT NULL
);
2021-01-02 11:56:24 +01:00
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");
2020-12-29 13:46:58 +01:00
CREATE TABLE "renewalTokens" (
"accountId" uuid NOT NULL,
"exp" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP + '24 hours',
"token" char(60) NOT NULL
);
ALTER TABLE "renewalTokens"
ADD FOREIGN KEY ("accountId") REFERENCES "accounts" ("id") ON DELETE RESTRICT ON UPDATE RESTRICT;
CREATE INDEX idx_renewaltokensaccountid ON "renewalTokens" ("accountId");
CREATE INDEX idx_renewaltokensexp ON "renewalTokens" ("exp");
CREATE INDEX idx_renewaltokenstoken ON "renewalTokens" ("token");
2020-12-29 13:46:58 +01:00
-- migrate:down