Skip to content

Commit 6c6242a

Browse files
committed
rename private functions
1 parent dc83f72 commit 6c6242a

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

butane_core/src/db/pg.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -548,10 +548,10 @@ where
548548
fn sql_for_op(current: &mut ADB, op: &Operation) -> Result<String> {
549549
match op {
550550
Operation::AddTable(table) => Ok(create_table(table, false)?),
551-
Operation::AddTableConstraints(table) => Ok(create_table_constraints(table)),
551+
Operation::AddTableConstraints(table) => Ok(create_table_fkey_constraints(table)),
552552
Operation::AddTableIfNotExists(table) => Ok(create_table(table, true)?),
553553
Operation::RemoveTable(name) => Ok(drop_table(name)),
554-
Operation::RemoveTableConstraints(table) => remove_table_constraints(table),
554+
Operation::RemoveTableConstraints(table) => remove_table_fkey_constraints(table),
555555
Operation::AddColumn(tbl, col) => add_column(tbl, col),
556556
Operation::RemoveColumn(tbl, name) => Ok(remove_column(tbl, name)),
557557
Operation::ChangeColumn(tbl, old, new) => {
@@ -586,22 +586,22 @@ fn create_table(table: &ATable, allow_exists: bool) -> Result<String> {
586586
))
587587
}
588588

589-
fn create_table_constraints(table: &ATable) -> String {
589+
fn create_table_fkey_constraints(table: &ATable) -> String {
590590
table
591591
.columns
592592
.iter()
593593
.filter(|column| column.reference().is_some())
594-
.map(|column| define_constraint(&table.name, column))
594+
.map(|column| define_fkey_constraint(&table.name, column))
595595
.collect::<Vec<String>>()
596596
.join("\n")
597597
}
598598

599-
fn remove_table_constraints(table: &ATable) -> Result<String> {
599+
fn remove_table_fkey_constraints(table: &ATable) -> Result<String> {
600600
Ok(table
601601
.columns
602602
.iter()
603603
.filter(|column| column.reference().is_some())
604-
.map(|column| drop_fk_constraints(table, column))
604+
.map(|column| drop_fkey_constraints(table, column))
605605
.collect::<Result<Vec<String>>>()?
606606
.join("\n"))
607607
}
@@ -632,7 +632,7 @@ fn define_column(col: &AColumn) -> Result<String> {
632632
))
633633
}
634634

635-
fn define_constraint(table_name: &str, column: &AColumn) -> String {
635+
fn define_fkey_constraint(table_name: &str, column: &AColumn) -> String {
636636
let reference = column
637637
.reference()
638638
.as_ref()
@@ -651,7 +651,7 @@ fn define_constraint(table_name: &str, column: &AColumn) -> String {
651651
}
652652
}
653653

654-
fn drop_fk_constraints(table: &ATable, column: &AColumn) -> Result<String> {
654+
fn drop_fkey_constraints(table: &ATable, column: &AColumn) -> Result<String> {
655655
let mut modified_column = column.clone();
656656
modified_column.remove_reference();
657657
change_column(table, column, &modified_column)

butane_core/src/migrations/adb.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,7 @@ impl AColumn {
486486
}
487487
/// Remove the column that this column refers to.
488488
pub fn remove_reference(&mut self) {
489-
self.reference = None
489+
self.reference = None;
490490
}
491491
/// Get the type identifier.
492492
pub fn typeid(&self) -> Result<TypeIdentifier> {
@@ -578,13 +578,12 @@ pub fn create_many_table(
578578
}
579579

580580
/// Individual operation use to apply a migration.
581+
/// The order of operations in a diff roughly follows this enum order.
581582
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
582583
pub enum Operation {
583584
//future improvement: support column renames
584585
/// Add a table.
585586
AddTable(ATable),
586-
/// Add table constraints referring to other tables, if the backend supports it.
587-
AddTableConstraints(ATable),
588587
/// Add a table, if it doesnt already exist.
589588
AddTableIfNotExists(ATable),
590589
/// Remove table constraints referring to other tables, if the backend supports it.
@@ -597,6 +596,8 @@ pub enum Operation {
597596
RemoveColumn(String, String),
598597
/// Change a table columns type.
599598
ChangeColumn(String, AColumn, AColumn),
599+
/// Add table constraints referring to other tables, if the backend supports it.
600+
AddTableConstraints(ATable),
600601
}
601602

602603
/// Determine the operations necessary to move the database schema from `old` to `new`.

0 commit comments

Comments
 (0)