Skip to content

Commit

Permalink
dump_db: Remove handlebars whitespace control characters
Browse files Browse the repository at this point in the history
  • Loading branch information
Turbo87 committed Sep 12, 2021
1 parent b91057b commit 030a8fb
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 21 deletions.
10 changes: 5 additions & 5 deletions 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;
32 changes: 16 additions & 16 deletions 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;

0 comments on commit 030a8fb

Please sign in to comment.