--- create-vk-channels

CREATE TABLE vk_channels (
  id                   BIGINT  NOT NULL REFERENCES channels (id),
  group_id             BIGINT      NOT NULL,
  access_token         VARCHAR     NOT NULL,
  confirmation_code    VARCHAR NOT NULL,
  secret               VARCHAR NOT NULL,
  last_sent_message_id BIGINT  NOT NULL  DEFAULT 0,
  deleted              BOOLEAN NOT NULL  DEFAULT FALSE,
  created_at           TIMESTAMPTZ NOT NULL DEFAULT now(),
  updated_at           TIMESTAMPTZ NOT NULL DEFAULT now(),
  PRIMARY KEY (id)
);

CREATE UNIQUE INDEX vk_channels_access_token_uniq
  ON vk_channels (access_token)
  WHERE deleted = FALSE;

CREATE UNIQUE INDEX vk_channels_group_id_uniq
  ON vk_channels (group_id)
  WHERE deleted = FALSE;
