@@ -157,8 +157,8 @@ impl Action for AlterColumn {
158 // Duplicate any indices to the temporary column
158 // Duplicate any indices to the temporary column
159 let indices = common::get_indices_for_column(db, &table.real_name, &column.real_name)?;
159 let indices = common::get_indices_for_column(db, &table.real_name, &column.real_name)?;
160− for (index_name, index_oid) in indices {
160+ for index in indices {
161− let index_columns: Vec<String> = common::get_index_columns(db, &index_name)?
161+ let index_columns: Vec<String> = common::get_index_columns(db, &index.name)?
162 .into_iter()
162 .into_iter()
163 .map(|idx_column| {
163 .map(|idx_column| {
164 // Replace column with temporary column for new index
164 // Replace column with temporary column for new index
@@ -169,15 +169,18 @@ impl Action for AlterColumn {
171 .collect();
171 .collect();
172− let temp_index_name = self.temp_index_name(ctx, index_oid);
172+ let temp_index_name = self.temp_index_name(ctx, index.oid);
174+ let unique_def = if index.unique { "UNIQUE" } else { "" };
174 db.query(&format!(
176 db.query(&format!(
176− CREATE INDEX CONCURRENTLY IF NOT EXISTS "{new_index_name}" ON "{table}" ({columns})
178+ CREATE {unique_def} INDEX CONCURRENTLY IF NOT EXISTS "{new_index_name}" ON "{table}" USING {index_type} ({columns})
178 new_index_name = temp_index_name,
180 new_index_name = temp_index_name,
179 table = table.real_name,
181 table = table.real_name,
180 columns = index_columns.join(", "),
182 columns = index_columns.join(", "),
183+ index_type = index.index_type,
182 .context("failed to create temporary index")?;
185 .context("failed to create temporary index")?;
@@ -280,7 +283,7 @@ impl Action for AlterColumn {
281 // Replace old indices with the new temporary ones created for the temporary column
284 // Replace old indices with the new temporary ones created for the temporary column
282 let indices = common::get_indices_for_column(db, &self.table, &self.column)?;
285 let indices = common::get_indices_for_column(db, &self.table, &self.column)?;
283− for (current_index_name, index_oid) in indices {
286+ for current_index in indices {
284 // To keep the index handling idempotent, we need to do the following:
287 // To keep the index handling idempotent, we need to do the following:
285 // 1. Add a prefix to the existing index
288 // 1. Add a prefix to the existing index
286 // 2. Rename temporary index to its final name
289 // 2. Rename temporary index to its final name
@@ -288,7 +291,7 @@ impl Action for AlterColumn {
289 // Add prefix (if not already added) to existing index
292 // Add prefix (if not already added) to existing index
290 let prefix = "__reshape_old";
293 let prefix = "__reshape_old";
291− let target_index_name = current_index_name.trim_start_matches(prefix);
294+ let target_index_name = current_index.name.trim_start_matches(prefix);
292 let old_index_name = format!("{}_{}", prefix, target_index_name);
295 let old_index_name = format!("{}_{}", prefix, target_index_name);
293 db.query(&format!(
296 db.query(&format!(
@@ -300,7 +303,7 @@ impl Action for AlterColumn {
300 .context("failed to rename old index")?;
303 .context("failed to rename old index")?;
302 // Rename temporary index to real name
305 // Rename temporary index to real name
303− let temp_index_name = self.temp_index_name(ctx, index_oid);
306+ let temp_index_name = self.temp_index_name(ctx, current_index.oid);
304 db.query(&format!(
307 db.query(&format!(
306 ALTER INDEX IF EXISTS "{temp_index_name}" RENAME TO "{target_index_name}"
309 ALTER INDEX IF EXISTS "{temp_index_name}" RENAME TO "{target_index_name}"
@@ -388,8 +391,8 @@ impl Action for AlterColumn {
388 // Safely remove any indices created for the temporary column
391 // Safely remove any indices created for the temporary column
389 let temp_column_name = self.temporary_column_name(ctx);
392 let temp_column_name = self.temporary_column_name(ctx);
390 let indices = common::get_indices_for_column(db, &self.table, &temp_column_name)?;
393 let indices = common::get_indices_for_column(db, &self.table, &temp_column_name)?;
391− for (_, index_oid) in indices {
394+ for index in indices {
392− let temp_index_name = self.temp_index_name(ctx, index_oid);
395+ let temp_index_name = self.temp_index_name(ctx, index.oid);
393 db.query(&format!(
396 db.query(&format!(
395 DROP INDEX CONCURRENTLY IF EXISTS "{index_name}"
398 DROP INDEX CONCURRENTLY IF EXISTS "{index_name}"