         "member_authorization"  BOOLEAN         NOT NULL,
         "public_access_level"   "api_access_level",
         "access_level"          "api_access_level" NOT NULL,
-        "parallel_access"       BOOLEAN         NOT NULL,
         "validity_period"       INTERVAL        NOT NULL,
         "last_usage"            TIMESTAMPTZ     NOT NULL,
+        CONSTRAINT "system_clients_require_name"
+          CHECK ("name" NOTNULL OR "member_id" ISNULL),
         CONSTRAINT "public_access_level_set_if_and_only_if_system_client"
           CHECK ("member_id" ISNULL = "public_access_level" NOTNULL) );
 CREATE UNIQUE INDEX "api_client_non_member_client_identifier_idx"


CREATE TABLE "api_client" (
        "id"                    SERIAL8         PRIMARY KEY,
        "name"                  TEXT            NOT NULL,
        UNIQUE ("member_id", "client_identifier"),
        "member_id"             INT4            REFERENCES "member" ("id")
                                                ON DELETE CASCADE ON UPDATE CASCADE,

        CONSTRAINT "one_of_authorization_code_and_refresh_token_set"
          CHECK ("authorization_code" NOTNULL OR "refresh_token" NOTNULL),
        CONSTRAINT "refresh_token_if_and_only_if_refreshed"
          CHECK ("refreshed" NOTNULL = "refresh_token" NOTNULL),
        CONSTRAINT "old_refresh_token_requires_current_refresh_token"
          CHECK ("refresh_token" NOTNULL OR "old_refresh_token" ISNULL) );

COMMENT ON TABLE "api_access" IS 'Issued OAuth2 authorization codes and refresh tokens';

COMMENT ON COLUMN "api_client"."validity_period"      IS 'Period after which an entry in the "api_access" table expires';
COMMENT ON COLUMN "api_access"."created"              IS 'Date/time when authorization code (or first refresh token when there is no authorization code) has been created';
COMMENT ON COLUMN "api_access"."authorization_code"   IS 'OAuth2 authorization code (only valid for a very short time after it has been created)';
COMMENT ON COLUMN "api_access"."refreshed"            IS 'Date/time of last refresh';
COMMENT ON COLUMN "api_access"."refresh_token"        IS 'OAuth2 refresh token';

