@@ -31,6 +31,7 @@ fn add_index() {
31 name: "name_idx".to_string(),
31 name: "name_idx".to_string(),
32 columns: vec!["name".to_string()],
32 columns: vec!["name".to_string()],
33 unique: true,
33 unique: true,
@@ -101,6 +102,7 @@ fn add_index_unique() {
101 name: "name_idx".to_string(),
102 name: "name_idx".to_string(),
102 columns: vec!["name".to_string()],
103 columns: vec!["name".to_string()],
103 unique: true,
104 unique: true,
@@ -148,3 +150,82 @@ fn add_index_unique() {
148 reshape.complete().unwrap();
150 reshape.complete().unwrap();
149 common::assert_cleaned_up(&mut new_db);
151 common::assert_cleaned_up(&mut new_db);
155+fn add_index_with_type() {
156+ let (mut reshape, mut old_db, mut new_db) = common::setup();
158+ let create_table_migration = Migration::new("create_user_table", None).with_action(
159+ CreateTableBuilder::default()
161+ .primary_key(vec!["id".to_string()])
163+ ColumnBuilder::default()
165+ .data_type("INTEGER")
168+ ColumnBuilder::default()
177+ let add_index_migration = Migration::new("add_name_index", None).with_action(AddIndex {
178+ table: "users".to_string(),
180+ name: "name_idx".to_string(),
181+ columns: vec!["data".to_string()],
183+ index_type: Some("gin".to_string()),
187+ let first_migrations = vec![create_table_migration.clone()];
188+ let second_migrations = vec![create_table_migration.clone(), add_index_migration.clone()];
191+ reshape.migrate(first_migrations.clone()).unwrap();
192+ reshape.migrate(second_migrations.clone()).unwrap();
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();
202+ // Ensure index is valid, ready and unique
203+ let (is_ready, is_valid, index_type): (bool, bool, String) = new_db
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'
218+ row.get("indisready"),
219+ row.get("indisvalid"),
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");
229+ reshape.complete().unwrap();
230+ common::assert_cleaned_up(&mut new_db);