@@ -157,8 +157,8 @@ impl Action for AlterColumn {
157157
158158 // Duplicate any indices to the temporary column
159159 let indices = common::get_indices_for_column(db, &table.real_name, &column.real_name)?;
160− for (index_name, index_oid) in indices {
161− let index_columns: Vec<String> = common::get_index_columns(db, &index_name)?
160+ for index in indices {
161+ let index_columns: Vec<String> = common::get_index_columns(db, &index.name)?
162162 .into_iter()
163163 .map(|idx_column| {
164164 // Replace column with temporary column for new index
@@ -169,15 +169,18 @@ impl Action for AlterColumn {
169169 }
170170 })
171171 .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);
173+
174+ let unique_def = if index.unique { "UNIQUE" } else { "" };
173175
174176 db.query(&format!(
175177 r#"
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})
177179 "#,
178180 new_index_name = temp_index_name,
179181 table = table.real_name,
180182 columns = index_columns.join(", "),
183+ index_type = index.index_type,
181184 ))
182185 .context("failed to create temporary index")?;
183186 }
@@ -280,7 +283,7 @@ impl Action for AlterColumn {
280283
281284 // Replace old indices with the new temporary ones created for the temporary column
282285 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 {
284287 // To keep the index handling idempotent, we need to do the following:
285288 // 1. Add a prefix to the existing index
286289 // 2. Rename temporary index to its final name
@@ -288,7 +291,7 @@ impl Action for AlterColumn {
288291
289292 // Add prefix (if not already added) to existing index
290293 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);
292295 let old_index_name = format!("{}_{}", prefix, target_index_name);
293296 db.query(&format!(
294297 r#"
@@ -300,7 +303,7 @@ impl Action for AlterColumn {
300303 .context("failed to rename old index")?;
301304
302305 // 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);
304307 db.query(&format!(
305308 r#"
306309 ALTER INDEX IF EXISTS "{temp_index_name}" RENAME TO "{target_index_name}"
@@ -388,8 +391,8 @@ impl Action for AlterColumn {
388391 // Safely remove any indices created for the temporary column
389392 let temp_column_name = self.temporary_column_name(ctx);
390393 let indices = common::get_indices_for_column(db, &self.table, &temp_column_name)?;
391− for (_, index_oid) in indices {
392− let temp_index_name = self.temp_index_name(ctx, index_oid);
394+ for index in indices {
395+ let temp_index_name = self.temp_index_name(ctx, index.oid);
393396 db.query(&format!(
394397 r#"
395398 DROP INDEX CONCURRENTLY IF EXISTS "{index_name}"