diff --git a/src/tasks/dump_db/dump-export.sql.hbs b/src/tasks/dump_db/dump-export.sql.hbs index 99952df693..2b7c4765fa 100644 --- a/src/tasks/dump_db/dump-export.sql.hbs +++ b/src/tasks/dump_db/dump-export.sql.hbs @@ -1,9 +1,9 @@ BEGIN ISOLATION LEVEL REPEATABLE READ, READ ONLY; -{{~#each tables}} -{{~#if this.filter}} +{{#each tables}} +{{#if this.filter}} \copy (SELECT {{this.columns}} FROM "{{this.name}}" WHERE {{this.filter}}) TO 'data/{{this.name}}.csv' WITH CSV HEADER -{{~else}} +{{else}} \copy "{{this.name}}" ({{this.columns}}) TO 'data/{{this.name}}.csv' WITH CSV HEADER -{{~/if}} -{{~/each}} +{{/if}} +{{/each}} COMMIT; diff --git a/src/tasks/dump_db/dump-import.sql.hbs b/src/tasks/dump_db/dump-import.sql.hbs index f9c5ac5dd4..4f9147772a 100644 --- a/src/tasks/dump_db/dump-import.sql.hbs +++ b/src/tasks/dump_db/dump-import.sql.hbs @@ -1,38 +1,38 @@ BEGIN; -- Disable triggers on each table. -{{~#each tables}} +{{#each tables}} ALTER TABLE "{{this.name}}" DISABLE TRIGGER ALL; -{{~/each}} +{{/each}} -- Set defaults for non-nullable columns not included in the dump. -{{~#each tables as |table|}} -{{~#each column_defaults}} +{{#each tables as |table|}} +{{#each column_defaults}} ALTER TABLE "{{table.name}}" ALTER COLUMN "{{@key}}" SET DEFAULT {{this}}; -{{~/each}} -{{~/each}} +{{/each}} +{{/each}} -- Truncate all tables. -{{~#each tables}} +{{#each tables}} TRUNCATE "{{this.name}}" RESTART IDENTITY CASCADE; -{{~/each}} +{{/each}} -- Enable this trigger so that `crates.textsearchable_index_col` can be excluded from the export ALTER TABLE "crates" ENABLE TRIGGER "trigger_crates_tsvector_update"; -- Import the CSV data. -{{~#each tables}} +{{#each tables}} \copy "{{this.name}}" ({{this.columns}}) FROM 'data/{{this.name}}.csv' WITH CSV HEADER -{{~/each}} +{{/each}} -- Drop the defaults again. -{{~#each tables as |table|}} -{{~#each column_defaults}} +{{#each tables as |table|}} +{{#each column_defaults}} ALTER TABLE "{{table.name}}" ALTER COLUMN "{{@key}}" DROP DEFAULT; -{{~/each}} -{{~/each}} +{{/each}} +{{/each}} -- Reenable triggers on each table. -{{~#each tables}} +{{#each tables}} ALTER TABLE "{{this.name}}" ENABLE TRIGGER ALL; -{{~/each}} +{{/each}} COMMIT;