hiling_go/db/migrations/000016_rebuld_location_page_visits.down.sql
2026-06-14 05:52:04 +03:00

21 lines
712 B
SQL

-- 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;