51 lines
1.8 KiB
Bash
51 lines
1.8 KiB
Bash
#!/bin/bash
|
|
set -euo pipefail
|
|
|
|
echo "--- RUNNING ONE-TIME SETUP (AGENT-POWERED) ---"
|
|
|
|
# The entrypoint.sh has already fetched all credentials
|
|
# and exported them as environment variables.
|
|
# We just need to run the Django commands.
|
|
|
|
# 1) Run migrations
|
|
# (Assumes settings.py's 'admin' db reads from env vars)
|
|
echo "=> Applying admin DB credentials and running migrations..."
|
|
poetry run python manage.py migrate --database=admin
|
|
|
|
# 2) Fix table ownership for Vault
|
|
# (Assumes settings.py's 'admin' db reads from env vars)
|
|
echo "=> Fixing table ownership for Vault..."
|
|
poetry run python manage.py shell -c "
|
|
from django.db import connections
|
|
import sys
|
|
|
|
print('Connecting to admin DB to fix table ownership...')
|
|
try:
|
|
admin_connection = connections['admin']
|
|
with admin_connection.cursor() as cursor:
|
|
# Get all tables and change ownership
|
|
cursor.execute(\"\"\"
|
|
SELECT tablename FROM pg_tables WHERE schemaname = 'public'
|
|
\"\"\")
|
|
tables = cursor.fetchall()
|
|
for (table,) in tables:
|
|
print(f'Setting owner of table {table} to nexus5_owner...')
|
|
cursor.execute(f'ALTER TABLE public.{table} OWNER TO nexus5_owner;')
|
|
|
|
# Get all sequences and change ownership
|
|
cursor.execute(\"\"\"
|
|
SELECT sequencename FROM pg_sequences WHERE schemaname = 'public'
|
|
\"\"\")
|
|
sequences = cursor.fetchall()
|
|
for (sequence,) in sequences:
|
|
print(f'Setting owner of sequence {sequence} to nexus5_owner...')
|
|
cursor.execute(f'ALTER SEQUENCE public.{sequence} OWNER TO nexus5_owner;')
|
|
|
|
print('Table ownership fixed.')
|
|
except Exception as e:
|
|
print(f'Error fixing table ownership: {e}')
|
|
sys.exit(1)
|
|
"
|
|
|
|
# Steps 1 and 4 from your old script are GONE.
|
|
echo '=> Setup complete.' |