CREATE TABLE "external_auth" (
  "id"           bigserial NOT NULL,
  "name"         text NOT NULL,
  "type"         text NOT NULL,
  "config"       jsonb NOT NULL,
  PRIMARY KEY ("id")
);
CREATE INDEX ON "external_auth" ("type");

CREATE TABLE "external_user" (
  "external_auth_id" bigint NOT NULL,
  "foreign_id"       text NOT NULL,
  "user_id"          bigint NOT NULL,
  FOREIGN KEY ("user_id") REFERENCES "user" ("id") ON DELETE CASCADE,
  FOREIGN KEY ("external_auth_id") REFERENCES "external_auth" ("id") ON DELETE CASCADE,
  PRIMARY KEY ("external_auth_id", "foreign_id")
);