-- Run as PostgreSQL superuser (e.g. postgres) after installing PostgreSQL + PostGIS for your major version.
-- Creates role and database matching backend/.env.example DATABASE_URL.
--
-- psql -U postgres -v ON_ERROR_STOP=1 -f scripts/init-database.sql
-- Or paste into pgAdmin Query Tool (run sections if needed).

DO $$
BEGIN
  IF NOT EXISTS (SELECT 1 FROM pg_roles WHERE rolname = 'wmims_user') THEN
    CREATE ROLE wmims_user WITH LOGIN PASSWORD 'password';
  END IF;
END
$$;

SELECT 'CREATE DATABASE wmims OWNER wmims_user'
WHERE NOT EXISTS (SELECT 1 FROM pg_database WHERE datname = 'wmims')\gexec

\c wmims

CREATE EXTENSION IF NOT EXISTS postgis;
