6 let mut test = Test::new("Remove column");
10 name = "create_user_table"
27 test.second_migration(
29 name = "remove_name_column"
32 type = "remove_column"
35 down = "'TEST_DOWN_VALUE'"
39 test.intermediate(|old_db, new_db| {
40 // Insert using old schema and ensure it can be retrieved through new schema
42 .simple_query("INSERT INTO users(id, name) VALUES (1, 'John Doe')")
45 .query("SELECT id FROM users WHERE id = 1", &[])
47 assert_eq!(1, results.len());
48 assert_eq!(1, results[0].get::<_, i32>("id"));
50 // Ensure the name column is not accesible through the new schema
51 assert!(new_db.query("SELECT id, name FROM users", &[]).is_err());
53 // Insert using new schema and ensure the down function is correctly applied
55 .simple_query("INSERT INTO users(id) VALUES (2)")
58 .query_opt("SELECT name FROM users WHERE id = 2", &[])
61 Some("TEST_DOWN_VALUE"),
62 result.as_ref().map(|row| row.get("name"))
70fn remove_column_with_index() {
71 let mut test = Test::new("Remove column");
75 name = "create_user_table"
100 test.second_migration(
102 name = "remove_name_column"
105 type = "remove_column"
108 down = "'TEST_DOWN_VALUE'"
112 test.after_completion(|db| {
113 // Ensure index has been removed after the migration is complete
118 FROM pg_catalog.pg_index
119 JOIN pg_catalog.pg_class ON pg_index.indexrelid = pg_class.oid
120 WHERE pg_class.relname = 'name_idx'
126 .map(|row| row.get(0))
129 assert_eq!(0, count, "expected index to not exist");
136fn remove_column_with_complex_down() {
137 let mut test = Test::new("Remove column complex");
139 test.first_migration(
141 name = "create_tables"
144 type = "create_table"
157 type = "create_table"
159 primary_key = ["user_id"]
171 test.second_migration(
173 name = "remove_users_email_column"
176 type = "remove_column"
182 value = "profiles.email"
183 where = "users.id = profiles.user_id"
187 test.after_first(|db| {
188 db.simple_query("INSERT INTO users (id, email) VALUES (1, 'test@example.com')")
190 db.simple_query("INSERT INTO profiles (user_id, email) VALUES (1, 'test@example.com')")
194 test.intermediate(|old_db, new_db| {
196 .simple_query("UPDATE profiles SET email = 'test2@example.com' WHERE user_id = 1")
199 // Ensure new email was propagated to users table in old schema
200 let email: String = old_db
211 .map(|row| row.get("email"))
213 assert_eq!("test2@example.com", email);
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list