-- Script simples para adicionar colunas e criar estabelecimentos
-- Execute: sudo -u postgres psql -d maktubia_points -f fix-establishments-simple.sql

ALTER TABLE establishments ADD COLUMN IF NOT EXISTS created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP;
ALTER TABLE establishments ADD COLUMN IF NOT EXISTS updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP;

INSERT INTO establishments (est_id, name, type, qr_code, is_active)
VALUES 
    ('MAKTUBIA_SHOP_001', 'Maktubia Shop Principal', 'Loja', 'MAKTUBIA_SHOP_001', TRUE),
    ('MAKTUBIA_SHOP_002', 'Maktubia Shop Centro', 'Loja', 'MAKTUBIA_SHOP_002', TRUE),
    ('MAKTUBIA_REST_001', 'Maktubia Restaurant', 'Restaurante', 'MAKTUBIA_REST_001', TRUE),
    ('MAKTUBIA_CAFE_001', 'Maktubia Café', 'Café', 'MAKTUBIA_CAFE_001', TRUE),
    ('MAKTUBIA_SUPER_001', 'Maktubia Supermercado', 'Supermercado', 'MAKTUBIA_SUPER_001', TRUE)
ON CONFLICT (est_id) DO UPDATE SET
    name = EXCLUDED.name,
    type = EXCLUDED.type,
    is_active = EXCLUDED.is_active;

SELECT est_id, name, type, qr_code, is_active FROM establishments ORDER BY est_id;













