@@ -1,4 +1,4 @@
1−use super::{Action, MigrationContext};
1+use super::{common::Index, Action, MigrationContext};
2use crate::{
2use crate::{
3 db::{Conn, Transaction},
3 db::{Conn, Transaction},
4 schema::Schema,
4 schema::Schema,
@@ -9,16 +9,16 @@ use serde::{Deserialize, Serialize};
9#[derive(Serialize, Deserialize, Debug)]
9#[derive(Serialize, Deserialize, Debug)]
10pub struct AddIndex {
10pub struct AddIndex {
11 pub table: String,
11 pub table: String,
12− pub name: String,
12+ pub index: Index,
13− pub columns: Vec<String>,
18#[typetag::serde(name = "add_index")]
15#[typetag::serde(name = "add_index")]
19impl Action for AddIndex {
16impl Action for AddIndex {
20 fn describe(&self) -> String {
17 fn describe(&self) -> String {
21− format!("Adding index \"{}\" to table \"{}\"", self.name, self.table)
19+ "Adding index \"{}\" to table \"{}\"",
20+ self.index.name, self.table
@@ -32,17 +32,17 @@ impl Action for AddIndex {
32 let column_real_names: Vec<String> = table
32 let column_real_names: Vec<String> = table
35− .filter(|column| self.columns.contains(&column.name))
35+ .filter(|column| self.index.columns.contains(&column.name))
36 .map(|column| format!("\"{}\"", column.real_name))
36 .map(|column| format!("\"{}\"", column.real_name))
37 .collect();
37 .collect();
39− let unique = if self.unique { "UNIQUE" } else { "" };
39+ let unique = if self.index.unique { "UNIQUE" } else { "" };
41 db.run(&format!(
41 db.run(&format!(
43 CREATE {unique} INDEX CONCURRENTLY "{name}" ON "{table}" ({columns})
43 CREATE {unique} INDEX CONCURRENTLY "{name}" ON "{table}" ({columns})
45− name = self.name,
45+ name = self.index.name,
46 table = self.table,
46 table = self.table,
47 columns = column_real_names.join(", "),
47 columns = column_real_names.join(", "),
@@ -65,7 +65,7 @@ impl Action for AddIndex {
66 DROP INDEX CONCURRENTLY IF EXISTS "{name}"
66 DROP INDEX CONCURRENTLY IF EXISTS "{name}"
68− name = self.name,
68+ name = self.index.name,
70 .context("failed to drop index")?;
70 .context("failed to drop index")?;