--- create-vk-channels

CREATE TABLE vk_channels (
  id                   BIGINT         NOT NULL REFERENCES channels (id),
  group_id             BIGINT         NOT NULL,
  access_token         VARCHAR(255)   NOT NULL,
  confirmation_code    VARCHAR(255),
  secret               VARCHAR(255)   NOT NULL,
  last_sent_message_id BIGINT         NOT NULL  DEFAULT 0,
  deleted              BIT                      DEFAULT 0,
  created_at           DATETIMEOFFSET NOT NULL  DEFAULT SYSDATETIMEOFFSET(),
  updated_at           DATETIMEOFFSET NOT NULL  DEFAULT SYSDATETIMEOFFSET()
    PRIMARY KEY (id)
);

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

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