nordabiz/database/migrations/add_gbp_hours_photos_columns.sql
Maciej Pienczyn 5f18a228b1 auto-claude: subtask-4-1 - Create SQL migration script for new columns
Add database migration script to add google_opening_hours (JSONB) and
google_photos_count (INTEGER) columns to company_website_analysis table.

These columns are needed for storing GBP data from Google Places API:
- google_opening_hours: stores weekday_text, open_now, and periods data
- google_photos_count: stores count of photos from Google Business profile

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-08 23:04:25 +01:00

53 lines
2.3 KiB
SQL

-- ============================================================
-- NordaBiz - Migration: Add GBP Hours and Photos Columns
-- ============================================================
-- Created: 2026-01-08
-- Description:
-- - Adds google_opening_hours (JSONB) for storing opening hours from Google Places API
-- - Adds google_photos_count (INTEGER) for storing photos count from Google Places API
-- - These columns enable the GBP audit service to properly check hours and photos completeness
--
-- Usage:
-- PostgreSQL: psql -h localhost -U nordabiz_app -d nordabiz -f add_gbp_hours_photos_columns.sql
-- SQLite: Not fully supported (JSONB columns)
-- ============================================================
-- ============================================================
-- 1. ADD GOOGLE OPENING HOURS COLUMN
-- ============================================================
ALTER TABLE company_website_analysis
ADD COLUMN IF NOT EXISTS google_opening_hours JSONB;
COMMENT ON COLUMN company_website_analysis.google_opening_hours IS 'Opening hours from Google Places API: weekday_text array, open_now, periods';
-- ============================================================
-- 2. ADD GOOGLE PHOTOS COUNT COLUMN
-- ============================================================
ALTER TABLE company_website_analysis
ADD COLUMN IF NOT EXISTS google_photos_count INTEGER;
COMMENT ON COLUMN company_website_analysis.google_photos_count IS 'Number of photos from Google Places API (max 10 from free tier)';
-- ============================================================
-- 3. GRANT PERMISSIONS TO APPLICATION USER
-- ============================================================
-- Ensure nordabiz_app has permissions on the table
GRANT ALL ON TABLE company_website_analysis TO nordabiz_app;
-- ============================================================
-- MIGRATION COMPLETE
-- ============================================================
-- Verify migration (PostgreSQL only)
DO $$
BEGIN
RAISE NOTICE 'GBP Hours/Photos columns migration completed successfully!';
RAISE NOTICE 'Added columns to company_website_analysis:';
RAISE NOTICE ' - google_opening_hours (JSONB) - Opening hours from Google Places API';
RAISE NOTICE ' - google_photos_count (INTEGER) - Photos count from Google Places API';
RAISE NOTICE 'Granted permissions to nordabiz_app';
END $$;