#!/bin/bash
# Один раз выполните: sudo bash scripts/setup-postgres-ubuntu.sh
# Логин: mkd_user, пароль: MkdUbuntu24Secure
set -e
sudo -u postgres psql -c "DO \$\$ BEGIN CREATE USER mkd_user WITH PASSWORD 'MkdUbuntu24Secure'; EXCEPTION WHEN duplicate_object THEN ALTER USER mkd_user WITH PASSWORD 'MkdUbuntu24Secure'; END \$\$;"
sudo -u postgres psql -c "SELECT 1 FROM pg_database WHERE datname='mkd_control_center'" | grep -q 1 || sudo -u postgres psql -c "CREATE DATABASE mkd_control_center OWNER mkd_user;"
sudo -u postgres psql -d mkd_control_center -c "GRANT ALL ON SCHEMA public TO mkd_user; GRANT CREATE ON SCHEMA public TO mkd_user;"
echo "Готово. Логин: mkd_user, пароль: MkdUbuntu24Secure"
