-- pgvector for rag database
\c rag;
CREATE EXTENSION IF NOT EXISTS vector;

-- Create databases for other services (idempotent)
\c postgres;
DO $$
BEGIN
  IF NOT EXISTS (SELECT FROM pg_database WHERE datname = 'im_system') THEN
    PERFORM dblink_exec('dbname=postgres', 'CREATE DATABASE im_system');
  END IF;
  IF NOT EXISTS (SELECT FROM pg_database WHERE datname = 'workflow') THEN
    PERFORM dblink_exec('dbname=postgres', 'CREATE DATABASE workflow');
  END IF;
  IF NOT EXISTS (SELECT FROM pg_database WHERE datname = 'file_system') THEN
    PERFORM dblink_exec('dbname=postgres', 'CREATE DATABASE file_system');
  END IF;
  IF NOT EXISTS (SELECT FROM pg_database WHERE datname = 'order_service') THEN
    PERFORM dblink_exec('dbname=postgres', 'CREATE DATABASE order_service');
  END IF;
END
$$;
