Skip to content

Commit

Permalink
fix to include special characters in db name (#2664)
Browse files Browse the repository at this point in the history
  • Loading branch information
ajoaugustine authored Nov 7, 2024
1 parent 4feaf55 commit 75b4a52
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions kube/services/jobs/psql-db-copy-aurora-job.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -168,11 +168,11 @@ spec:
gen3_log_info "Source DB: $source_db_database, Username: $db_username, Current DB: $db_database, Target DB: $target_db"
# DB commands
gen3 psql aurora -c "GRANT $db_username TO $aurora_master_username"
gen3 psql aurora -c "GRANT \"$db_username\" TO \"$aurora_master_username\""
gen3 psql aurora -c "SELECT pg_terminate_backend(pg_stat_activity.pid) FROM pg_stat_activity WHERE pg_stat_activity.datname = '$source_db_database' AND pid <> pg_backend_pid()"
gen3 psql aurora -c "CREATE DATABASE $target_db WITH TEMPLATE $source_db_database OWNER $db_username"
pg_command="DO \$\$ DECLARE tbl record; BEGIN FOR tbl IN (SELECT table_schema || '.' || table_name AS full_table_name FROM information_schema.tables WHERE table_schema = 'public') LOOP EXECUTE 'ALTER TABLE ' || tbl.full_table_name || ' OWNER TO $db_username;'; END LOOP; END \$\$;"
PGPASSWORD=${aurora_master_password} psql -h $aurora_host_name -U $aurora_master_username -d "$target_db" -c "$pg_command"
gen3 psql aurora -c "CREATE DATABASE \"$target_db\" WITH TEMPLATE \"$source_db_database\" OWNER \"$db_username\""
pg_command="DO \$\$ DECLARE tbl record; BEGIN FOR tbl IN (SELECT table_schema || '.' || table_name AS full_table_name FROM information_schema.tables WHERE table_schema = 'public') LOOP EXECUTE 'ALTER TABLE ' || tbl.full_table_name || ' OWNER TO \"$db_username\";'; END LOOP; END \$\$;"
PGPASSWORD=${aurora_master_password} psql -h $aurora_host_name -U "$aurora_master_username" -d "$target_db" -c "$pg_command"
if [ $? -eq 0 ]; then
gen3_log_info "Successfully processed $database"
new_databases+=("$target_db")
Expand Down

0 comments on commit 75b4a52

Please sign in to comment.