diff --git a/ansible-runner/context/app/project/roles/mirror_appliance/tasks/migrate.yaml b/ansible-runner/context/app/project/roles/mirror_appliance/tasks/migrate.yaml index 23ace4e..6961d77 100644 --- a/ansible-runner/context/app/project/roles/mirror_appliance/tasks/migrate.yaml +++ b/ansible-runner/context/app/project/roles/mirror_appliance/tasks/migrate.yaml @@ -145,9 +145,7 @@ mode: '0755' - name: Convert PostgreSQL data-only dump to SQLite-compatible SQL file - script: pg_to_sqlite.sh "{{ expanded_quay_root }}/quay-postgres-backup/pg_data_dump.sql" "{{ expanded_quay_root }}/quay-postgres-backup/transformed_pgdata.sql" - args: - executable: /bin/bash + command: /bin/bash "{{ expanded_quay_root }}/quay-postgres-backup/pg_to_sqlite.sh" "{{ expanded_quay_root }}/quay-postgres-backup/pg_data_dump.sql" "{{ expanded_quay_root }}/quay-postgres-backup/transformed_pgdata.sql" - name: Concatenate sqlite schema .sql and transformed postgres data into single merged_sqlite.sql shell: cat "{{ expanded_quay_root }}/quay-postgres-backup/sqlite_schema_dump.sql" "{{ expanded_quay_root }}/quay-postgres-backup/transformed_pgdata.sql" > "{{ expanded_quay_root }}/quay-postgres-backup/merged_sqlite.sql" diff --git a/ansible-runner/context/app/project/roles/mirror_appliance/templates/pg_to_sqlite.sh b/ansible-runner/context/app/project/roles/mirror_appliance/templates/pg_to_sqlite.sh index 9258218..d6f01cc 100755 --- a/ansible-runner/context/app/project/roles/mirror_appliance/templates/pg_to_sqlite.sh +++ b/ansible-runner/context/app/project/roles/mirror_appliance/templates/pg_to_sqlite.sh @@ -25,13 +25,16 @@ pg_to_sqlite() { sql=$(echo "$sql" | sed -E '/^pg_dump:.*$/d') # Remove original PostgreSQL sequence set statements - sql=$(echo "$sql" | sed -E "s/SELECT pg_catalog\.setval\('public\..*?\', [0-9]+, (true|false)\);//g") + sql=$(echo "$sql" | sed -E "s/SELECT pg_catalog\.setval\('public\..*?', [0-9]+, (true|false)\);//g") # Remove the `public.` schema prefix from table names sql=$(echo "$sql" | sed "s/INSERT INTO public\./INSERT INTO /g") - # Remove blank lines - sql=$(echo "$sql" | sed '/^$/d') + # Remove empty lines + sql=$(echo "$sql" | sed "/^\s*$/d") + + # Trim whitespace from the beginning and end + sql=$(echo "$sql" | sed 's/^[ \t]*//;s/[ \t]*$//') # Write the output to the specified file echo "$sql" > "$output_file"