-- Initialize OSM database with PostGIS and hstore extensions
-- This script runs automatically when PostgreSQL container starts for the first time

-- Connect to the osm database
\c osm;

-- Enable PostGIS extension
CREATE EXTENSION IF NOT EXISTS postgis;
CREATE EXTENSION IF NOT EXISTS postgis_topology;

-- Enable hstore extension for key-value storage
CREATE EXTENSION IF NOT EXISTS hstore;

-- Grant necessary permissions
GRANT ALL PRIVILEGES ON DATABASE osm TO postgres;
GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA public TO postgres;
GRANT ALL PRIVILEGES ON ALL SEQUENCES IN SCHEMA public TO postgres;

-- Set up proper ownership
ALTER DATABASE osm OWNER TO postgres;

-- Display confirmation
SELECT 'OSM database initialized successfully with PostGIS and hstore extensions' AS status;