@@ -31,6 +31,7 @@ fn add_index() {
3131 name: "name_idx".to_string(),
3232 columns: vec!["name".to_string()],
3333 unique: true,
34+ index_type: None,
3435 },
3536 });
3637
@@ -101,6 +102,7 @@ fn add_index_unique() {
101102 name: "name_idx".to_string(),
102103 columns: vec!["name".to_string()],
103104 unique: true,
105+ index_type: None,
104106 },
105107 });
106108
@@ -148,3 +150,82 @@ fn add_index_unique() {
148150 reshape.complete().unwrap();
149151 common::assert_cleaned_up(&mut new_db);
150152}
153+
154+#[test]
155+fn add_index_with_type() {
156+ let (mut reshape, mut old_db, mut new_db) = common::setup();
157+
158+ let create_table_migration = Migration::new("create_user_table", None).with_action(
159+ CreateTableBuilder::default()
160+ .name("users")
161+ .primary_key(vec!["id".to_string()])
162+ .columns(vec![
163+ ColumnBuilder::default()
164+ .name("id")
165+ .data_type("INTEGER")
166+ .build()
167+ .unwrap(),
168+ ColumnBuilder::default()
169+ .name("data")
170+ .data_type("JSONB")
171+ .build()
172+ .unwrap(),
173+ ])
174+ .build()
175+ .unwrap(),
176+ );
177+ let add_index_migration = Migration::new("add_name_index", None).with_action(AddIndex {
178+ table: "users".to_string(),
179+ index: Index {
180+ name: "name_idx".to_string(),
181+ columns: vec!["data".to_string()],
182+ unique: false,
183+ index_type: Some("gin".to_string()),
184+ },
185+ });
186+
187+ let first_migrations = vec![create_table_migration.clone()];
188+ let second_migrations = vec![create_table_migration.clone(), add_index_migration.clone()];
189+
190+ // Run migrations
191+ reshape.migrate(first_migrations.clone()).unwrap();
192+ reshape.migrate(second_migrations.clone()).unwrap();
193+
194+ // Update schemas of Postgres connections
195+ let old_schema_query =
196+ reshape::schema_query_for_migration(&first_migrations.last().unwrap().name);
197+ let new_schema_query =
198+ reshape::schema_query_for_migration(&second_migrations.last().unwrap().name);
199+ old_db.simple_query(&old_schema_query).unwrap();
200+ new_db.simple_query(&new_schema_query).unwrap();
201+
202+ // Ensure index is valid, ready and unique
203+ let (is_ready, is_valid, index_type): (bool, bool, String) = new_db
204+ .query(
205+ "
206+ SELECT pg_index.indisready, pg_index.indisvalid, pg_am.amname
207+ FROM pg_catalog.pg_index
208+ JOIN pg_catalog.pg_class ON pg_index.indexrelid = pg_class.oid
209+ JOIN pg_catalog.pg_am ON pg_class.relam = pg_am.oid
210+ WHERE pg_class.relname = 'name_idx'
211+ ",
212+ &[],
213+ )
214+ .unwrap()
215+ .first()
216+ .map(|row| {
217+ (
218+ row.get("indisready"),
219+ row.get("indisvalid"),
220+ row.get("amname"),
221+ )
222+ })
223+ .unwrap();
224+
225+ assert!(is_ready, "expected index to be ready");
226+ assert!(is_valid, "expected index to be valid");
227+ assert_eq!("gin", index_type, "expected index type to be GIN");
228+
229+ reshape.complete().unwrap();
230+ common::assert_cleaned_up(&mut new_db);
231+}