Skip to content

Commit f4af5f5

Browse files
committed
dump_db: Convert column_defaults from BTreeMap to Vec
1 parent 8666e8b commit f4af5f5

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

src/tasks/dump_db/dump-import.sql.hbs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ BEGIN;
77
-- Set defaults for non-nullable columns not included in the dump.
88
{{#each tables as |table|}}
99
{{#each column_defaults}}
10-
ALTER TABLE "{{table.name}}" ALTER COLUMN "{{@key}}" SET DEFAULT {{this}};
10+
ALTER TABLE "{{table.name}}" ALTER COLUMN "{{column}}" SET DEFAULT {{value}};
1111
{{/each}}
1212
{{/each}}
1313

@@ -27,7 +27,7 @@ BEGIN;
2727
-- Drop the defaults again.
2828
{{#each tables as |table|}}
2929
{{#each column_defaults}}
30-
ALTER TABLE "{{table.name}}" ALTER COLUMN "{{@key}}" DROP DEFAULT;
30+
ALTER TABLE "{{table.name}}" ALTER COLUMN "{{column}}" DROP DEFAULT;
3131
{{/each}}
3232
{{/each}}
3333

src/tasks/dump_db/gen_scripts.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::{collections::BTreeMap, fs::File, path::Path};
1+
use std::{fs::File, path::Path};
22

33
use crate::tasks::dump_db::configuration::{ColumnVisibility, TableConfig, VisibilityConfig};
44
use swirl::PerformError;
@@ -16,7 +16,13 @@ struct HandlebarsTableContext<'a> {
1616
name: &'a str,
1717
filter: Option<String>,
1818
columns: String,
19-
column_defaults: BTreeMap<&'a str, &'a str>,
19+
column_defaults: Vec<ColumnDefault<'a>>,
20+
}
21+
22+
#[derive(Debug, Serialize)]
23+
struct ColumnDefault<'a> {
24+
column: &'a str,
25+
value: &'a str,
2026
}
2127

2228
impl TableConfig {
@@ -35,7 +41,10 @@ impl TableConfig {
3541
let column_defaults = self
3642
.column_defaults
3743
.iter()
38-
.map(|(k, v)| (k.as_str(), v.as_str()))
44+
.map(|(k, v)| ColumnDefault {
45+
column: k.as_str(),
46+
value: v.as_str(),
47+
})
3948
.collect();
4049
Some(HandlebarsTableContext {
4150
name,

0 commit comments

Comments
 (0)