105 lines
4.1 KiB
Lua
105 lines
4.1 KiB
Lua
return {
|
|
postgres = {
|
|
up = [[
|
|
CREATE TABLE IF NOT EXISTS "oauth2_credentials" (
|
|
"id" UUID PRIMARY KEY,
|
|
"created_at" TIMESTAMP WITH TIME ZONE DEFAULT (CURRENT_TIMESTAMP(0) AT TIME ZONE 'UTC'),
|
|
"name" TEXT,
|
|
"consumer_id" UUID REFERENCES "consumers" ("id") ON DELETE CASCADE,
|
|
"client_id" TEXT UNIQUE,
|
|
"client_secret" TEXT,
|
|
"redirect_uris" TEXT[]
|
|
);
|
|
|
|
DO $$
|
|
BEGIN
|
|
CREATE INDEX IF NOT EXISTS "oauth2_credentials_consumer_id_idx" ON "oauth2_credentials" ("consumer_id");
|
|
EXCEPTION WHEN UNDEFINED_COLUMN THEN
|
|
-- Do nothing, accept existing state
|
|
END$$;
|
|
|
|
DO $$
|
|
BEGIN
|
|
CREATE INDEX IF NOT EXISTS "oauth2_credentials_secret_idx" ON "oauth2_credentials" ("client_secret");
|
|
EXCEPTION WHEN UNDEFINED_COLUMN THEN
|
|
-- Do nothing, accept existing state
|
|
END$$;
|
|
|
|
|
|
|
|
CREATE TABLE IF NOT EXISTS "oauth2_authorization_codes" (
|
|
"id" UUID PRIMARY KEY,
|
|
"created_at" TIMESTAMP WITH TIME ZONE DEFAULT (CURRENT_TIMESTAMP(0) AT TIME ZONE 'UTC'),
|
|
"credential_id" UUID REFERENCES "oauth2_credentials" ("id") ON DELETE CASCADE,
|
|
"service_id" UUID REFERENCES "services" ("id") ON DELETE CASCADE,
|
|
"code" TEXT UNIQUE,
|
|
"authenticated_userid" TEXT,
|
|
"scope" TEXT,
|
|
"ttl" TIMESTAMP WITH TIME ZONE
|
|
);
|
|
|
|
DO $$
|
|
BEGIN
|
|
CREATE INDEX IF NOT EXISTS "oauth2_authorization_codes_authenticated_userid_idx" ON "oauth2_authorization_codes" ("authenticated_userid");
|
|
EXCEPTION WHEN UNDEFINED_COLUMN THEN
|
|
-- Do nothing, accept existing state
|
|
END$$;
|
|
|
|
DO $$
|
|
BEGIN
|
|
CREATE INDEX IF NOT EXISTS "oauth2_authorization_credential_id_idx"
|
|
ON "oauth2_authorization_codes" ("credential_id");
|
|
EXCEPTION WHEN UNDEFINED_COLUMN THEN
|
|
-- Do nothing, accept existing state
|
|
END$$;
|
|
|
|
DO $$
|
|
BEGIN
|
|
CREATE INDEX IF NOT EXISTS "oauth2_authorization_service_id_idx"
|
|
ON "oauth2_authorization_codes" ("service_id");
|
|
EXCEPTION WHEN UNDEFINED_COLUMN THEN
|
|
-- Do nothing, accept existing state
|
|
END$$;
|
|
|
|
|
|
|
|
CREATE TABLE IF NOT EXISTS "oauth2_tokens" (
|
|
"id" UUID PRIMARY KEY,
|
|
"created_at" TIMESTAMP WITH TIME ZONE DEFAULT (CURRENT_TIMESTAMP(0) AT TIME ZONE 'UTC'),
|
|
"credential_id" UUID REFERENCES "oauth2_credentials" ("id") ON DELETE CASCADE,
|
|
"service_id" UUID REFERENCES "services" ("id") ON DELETE CASCADE,
|
|
"access_token" TEXT UNIQUE,
|
|
"refresh_token" TEXT UNIQUE,
|
|
"token_type" TEXT,
|
|
"expires_in" INTEGER,
|
|
"authenticated_userid" TEXT,
|
|
"scope" TEXT,
|
|
"ttl" TIMESTAMP WITH TIME ZONE
|
|
);
|
|
|
|
DO $$
|
|
BEGIN
|
|
CREATE INDEX IF NOT EXISTS "oauth2_tokens_authenticated_userid_idx" ON "oauth2_tokens" ("authenticated_userid");
|
|
EXCEPTION WHEN UNDEFINED_COLUMN THEN
|
|
-- Do nothing, accept existing state
|
|
END$$;
|
|
|
|
DO $$
|
|
BEGIN
|
|
CREATE INDEX IF NOT EXISTS "oauth2_tokens_credential_id_idx"
|
|
ON "oauth2_tokens" ("credential_id");
|
|
EXCEPTION WHEN UNDEFINED_COLUMN THEN
|
|
-- Do nothing, accept existing state
|
|
END$$;
|
|
|
|
DO $$
|
|
BEGIN
|
|
CREATE INDEX IF NOT EXISTS "oauth2_tokens_service_id_idx"
|
|
ON "oauth2_tokens" ("service_id");
|
|
EXCEPTION WHEN UNDEFINED_COLUMN THEN
|
|
-- Do nothing, accept existing state
|
|
END$$;
|
|
]],
|
|
},
|
|
}
|