Skip to content

Commit

Permalink
Fix regex
Browse files Browse the repository at this point in the history
  • Loading branch information
harishsurf authored and bcaton85 committed Aug 13, 2024
1 parent 4475ff4 commit 0e75ed0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 0e75ed0

Please sign in to comment.