Skip to content

Commit

Permalink
feat: support --role options in pg_dump
Browse files Browse the repository at this point in the history
  • Loading branch information
AlisaAkiron committed Mar 8, 2024
1 parent e958d8b commit 348bc3c
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 7 deletions.
26 changes: 19 additions & 7 deletions example/database/postgresql.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ postgresql:
- "Data"
- "PostData"

# Set role before dumping
# Can be omitted
# Can be overridden by database specific settings
# --role={} option in pg_dump
## role: "my_role"

# Whether to create the database before restoring
# Can be omitted
# Can be overridden by database specific settings
Expand Down Expand Up @@ -76,7 +82,7 @@ postgresql:

# Format of the backup (Plain, Custom, Tar)
# Can be omitted
# Will override the pg_dump.format option
# Will override the client.format option
# Note that the directory type is not supported
# --format={} option in pg_dump
## format: "Plain"
Expand All @@ -103,28 +109,34 @@ postgresql:

# Section to include in the backup (PreData, Data, PostData)
# Can be omitted
# Will override the pg_dump.sections option
# Will override the client.sections option
# --section={} option in pg_dump
## sections:
## - "PreData"
## - "Data"
## - "PostData"

# Set role before dumping
# Can be omitted
# Will override the client.role option
# --role={} option in pg_dump
## role: "my_role"

# Whether to create the database before restoring
# Can be omitted
# Will override the pg_dump.create option
# Will override the client.create option
# --create option in pg_dump
## create: false

# Whether to drop the database before restoring
# Can be omitted
# Will override the pg_dump.clean option
# Will override the client.clean option
# --clean option in pg_dump
## clean: false

# Do not save the corresponding data
# Can be omitted
# Will override the pg_dump.do_not_save option
# Will override the client.do_not_save option
# Available values:
# LargeObjects, Owner, Privileges, Comments,
# Publications, SecurityLabels, Subscriptions,
Expand All @@ -135,13 +147,13 @@ postgresql:

# Disable something
# Can be omitted
# Will override the pg_dump.disable option
# Will override the client.disable option
# Available values:
# DollarQuoting, Triggers
# --disable={} option in pg_dump
## disable: []

# Extra arguments for pg_dump
# Can be omitted
# Will override the pg_dump.extra_args option
# Will override the client.extra_args option
## extra_args: []
1 change: 1 addition & 0 deletions src/configs/client/pg_dump.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ pub struct PgDump {
pub binary_path: String,
pub format: PgFormat,
pub sections: Vec<PgSection>,
pub role: Option<String>,
pub clean: Option<bool>,
pub create: Option<bool>,
pub do_not_save: Option<Vec<PgDoNotSave>>,
Expand Down
2 changes: 2 additions & 0 deletions src/configs/database/postgresql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ pub struct PostgreSQLDatabase {
pub exclude_schemata: Option<Vec<String>>,
pub include_tables: Option<Vec<String>>,
pub exclude_tables: Option<Vec<String>>,
pub role: Option<String>,
pub clean: Option<bool>,
pub create: Option<bool>,
pub sections: Option<Vec<PgSection>>,
Expand All @@ -38,6 +39,7 @@ impl From<&String> for PostgreSQLDatabase {
exclude_schemata: None,
include_tables: None,
exclude_tables: None,
role: None,
clean: None,
create: None,
sections: None,
Expand Down
13 changes: 13 additions & 0 deletions src/provider/pg_dump.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,19 @@ impl Dump<PgDump, PostgreSQLConnection> for PostgreSQLDatabase {
apply_selective_args_some(cmd, "schema", &self.include_schemata);
apply_selective_args_some(cmd, "exclude-schema", &self.exclude_schemata);

// role
match &self.role {
Some(val) => {
cmd.arg(format!("--role={role}", role = val));
}
None => match &pg_dump.role {
Some(val) => {
cmd.arg(format!("--role={role}", role = val));
}
None => (),
},
}

// extra_args
match &self.extra_args {
Some(val) => {
Expand Down

0 comments on commit 348bc3c

Please sign in to comment.