@@ -1,4 +1,4 @@
1−use super::{Action, MigrationContext};
1+use super::{common::Index, Action, MigrationContext};
22use crate::{
33 db::{Conn, Transaction},
44 schema::Schema,
@@ -9,16 +9,16 @@ use serde::{Deserialize, Serialize};
99#[derive(Serialize, Deserialize, Debug)]
1010pub struct AddIndex {
1111 pub table: String,
12− pub name: String,
13− pub columns: Vec<String>,
14− #[serde(default)]
15− pub unique: bool,
12+ pub index: Index,
1613}
1714
1815#[typetag::serde(name = "add_index")]
1916impl Action for AddIndex {
2017 fn describe(&self) -> String {
21− format!("Adding index \"{}\" to table \"{}\"", self.name, self.table)
18+ format!(
19+ "Adding index \"{}\" to table \"{}\"",
20+ self.index.name, self.table
21+ )
2222 }
2323
2424 fn run(
@@ -32,17 +32,17 @@ impl Action for AddIndex {
3232 let column_real_names: Vec<String> = table
3333 .columns
3434 .iter()
35− .filter(|column| self.columns.contains(&column.name))
35+ .filter(|column| self.index.columns.contains(&column.name))
3636 .map(|column| format!("\"{}\"", column.real_name))
3737 .collect();
3838
39− let unique = if self.unique { "UNIQUE" } else { "" };
39+ let unique = if self.index.unique { "UNIQUE" } else { "" };
4040
4141 db.run(&format!(
4242 r#"
4343 CREATE {unique} INDEX CONCURRENTLY "{name}" ON "{table}" ({columns})
4444 "#,
45− name = self.name,
45+ name = self.index.name,
4646 table = self.table,
4747 columns = column_real_names.join(", "),
4848 ))
@@ -65,7 +65,7 @@ impl Action for AddIndex {
6565 r#"
6666 DROP INDEX CONCURRENTLY IF EXISTS "{name}"
6767 "#,
68− name = self.name,
68+ name = self.index.name,
6969 ))
7070 .context("failed to drop index")?;
7171 Ok(())