Skip to content

Commit

Permalink
Upd
Browse files Browse the repository at this point in the history
  • Loading branch information
evgeniy-r committed Nov 6, 2021
1 parent b86440c commit dab5828
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
6 changes: 2 additions & 4 deletions datanymizer_dumper/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,8 @@ pub trait Table<T>: Sized + Send + Clone + Eq + Hash {
fn get_name(&self) -> String;
/// Returns table name with schema or other prefix, based on database type
fn get_full_name(&self) -> String;
/// Returns full and short table names
fn get_names(&self) -> Vec<String> {
vec![self.get_full_name(), self.get_name()]
}
/// Returns possible table names (e.g. full and short)
fn get_names(&self) -> Vec<String>;
/// Get table columns
fn get_columns(&self) -> Vec<Self::Column>;
/// Get columns names (needed in the future for SQL)
Expand Down
8 changes: 4 additions & 4 deletions datanymizer_dumper/src/postgres/dumper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ impl PgDumper {
Ok(())
}

fn set_table_order(tables: &mut Vec<(<Self as Dumper>::Table, i32)>, order: &[String]) {
fn sort_tables(tables: &mut Vec<(<Self as Dumper>::Table, i32)>, order: &[String]) {
tables.sort_by_cached_key(|(tbl, weight)| {
let position = order.iter().position(|i| tbl.get_names().contains(i));
(position, -weight)
Expand All @@ -206,7 +206,7 @@ impl Dumper for PgDumper {
self.debug("Fetch tables metadata...".into());

let mut tables = self.schema_inspector().ordered_tables(connection);
Self::set_table_order(
Self::sort_tables(
&mut tables,
settings.table_order.as_ref().unwrap_or(&vec![]),
);
Expand Down Expand Up @@ -304,7 +304,7 @@ mod tests {
}

#[test]
fn set_table_order() {
fn sort_tables() {
let order = vec!["table2".to_string(), "public.table1".to_string()];

let mut tables = vec![
Expand All @@ -316,7 +316,7 @@ mod tests {
(PgTable::new("table2".to_string(), "other".to_string()), 5),
];

PgDumper::set_table_order(&mut tables, &order);
PgDumper::sort_tables(&mut tables, &order);

let ordered_names: Vec<_> = tables
.iter()
Expand Down
4 changes: 4 additions & 0 deletions datanymizer_dumper/src/postgres/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ impl Table<Type> for PgTable {
format!("{}.{}", self.schemaname, self.tablename)
}

fn get_names(&self) -> Vec<String> {
vec![self.get_full_name(), self.get_name()]
}

fn get_columns(&self) -> Vec<Self::Column> {
self.columns.clone()
}
Expand Down

0 comments on commit dab5828

Please sign in to comment.