-- PR Привлечение: действия, которыми привлекали людей (рассылка, мероприятие, пост и т.д.)
CREATE TABLE IF NOT EXISTS pr_attraction_actions (
  id                        BIGSERIAL PRIMARY KEY,
  title                     TEXT NOT NULL,
  description               TEXT,
  channel_id                BIGINT REFERENCES pr_smm_channels(id) ON DELETE SET NULL,
  action_type               VARCHAR(20) NOT NULL CHECK (action_type IN ('mailing', 'event', 'post', 'other')),
  action_date               DATE NOT NULL DEFAULT CURRENT_DATE,
  new_subscribers_attributed INT,
  event_id                   BIGINT REFERENCES pr_events(id) ON DELETE SET NULL,
  created_at                TIMESTAMPTZ NOT NULL DEFAULT NOW(),
  created_by                 TEXT
);

CREATE INDEX IF NOT EXISTS idx_pr_attraction_actions_channel ON pr_attraction_actions(channel_id);
CREATE INDEX IF NOT EXISTS idx_pr_attraction_actions_type ON pr_attraction_actions(action_type);
CREATE INDEX IF NOT EXISTS idx_pr_attraction_actions_date ON pr_attraction_actions(action_date DESC);

COMMENT ON TABLE pr_attraction_actions IS 'Действия привлечения: рассылка, мероприятие, пост и т.д., с приростом подписчиков';
