-- Restore the original (unused) weekly-bucket schema and total_visited column.
DROP INDEX IF EXISTS idx_location_page_visits_day_count;
DROP INDEX IF EXISTS idx_location_page_visits_location_day;
DROP TABLE IF EXISTS location_page_visits;

CREATE TABLE location_page_visits (
  id SERIAL PRIMARY KEY,
  location_id INT NOT NULL REFERENCES locations(id),
  week_key VARCHAR(10) NOT NULL,
  visit_count BIGINT DEFAULT(0) NOT NULL,
  is_deleted BOOLEAN,
  updated_at TIMESTAMP DEFAULT NOW(),

  UNIQUE(location_id, week_key)
);

CREATE INDEX idx_location_page_visits_week_key_visit_count
  ON location_page_visits(week_key, visit_count DESC);

ALTER TABLE locations ADD COLUMN IF NOT EXISTS total_visited integer;
