-- Initialize PostGIS
CREATE EXTENSION IF NOT EXISTS postgis;

-- Create cities table for conurbation data
CREATE TABLE IF NOT EXISTS cities (
    id SERIAL PRIMARY KEY,
    name VARCHAR(255) NOT NULL,
    population INTEGER,
    country VARCHAR(100),
    geom GEOGRAPHY(POINT, 4326) NOT NULL
);

-- Create spatial index
CREATE INDEX IF NOT EXISTS idx_cities_geom ON cities USING GIST(geom);

-- Insert some seed data for testing
INSERT INTO cities (name, population, country, geom) VALUES
('London', 9000000, 'United Kingdom', ST_GeomFromText('POINT(-0.1278 51.5074)', 4326)),
('Paris', 2161000, 'France', ST_GeomFromText('POINT(2.3522 48.8566)', 4326)),
('Berlin', 3644000, 'Germany', ST_GeomFromText('POINT(13.4050 52.5200)', 4326)),
('Moscow', 12506000, 'Russia', ST_GeomFromText('POINT(37.6173 55.7558)', 4326)),
('Tokyo', 37400000, 'Japan', ST_GeomFromText('POINT(139.6503 35.6762)', 4326)),
('New York', 8336000, 'USA', ST_GeomFromText('POINT(-74.0060 40.7128)', 4326)),
('Beijing', 21540000, 'China', ST_GeomFromText('POINT(116.4074 39.9042)', 4326)),
('Mumbai', 20411000, 'India', ST_GeomFromText('POINT(72.8777 19.0760)', 4326)),
('São Paulo', 12325000, 'Brazil', ST_GeomFromText('POINT(-46.6333 -23.5505)', 4326)),
('Cairo', 9500000, 'Egypt', ST_GeomFromText('POINT(31.2357 30.0444)', 4326));
