| 54 | |
| 55 | #[test] |
| 56 | fn test_drift_missing_column_in_sqlite() -> rusqlite::Result<()> { |
| 57 | let mut conn = Connection::open_in_memory()?; |
| 58 | |
| 59 | // Initialize metadata table |
| 60 | TypeMetadata::init(&conn)?; |
| 61 | |
| 62 | // Create a table missing a column |
| 63 | conn.execute( |
| 64 | "CREATE TABLE users ( |
| 65 | id INTEGER PRIMARY KEY, |
| 66 | name TEXT NOT NULL |
| 67 | )", |
| 68 | [] |
| 69 | )?; |
| 70 | |
| 71 | // Store metadata with an extra column |
| 72 | let tx = conn.transaction()?; |
| 73 | tx.execute( |
| 74 | "INSERT INTO __pgsqlite_schema (table_name, column_name, pg_type, sqlite_type) |
| 75 | VALUES |
| 76 | ('users', 'id', 'int4', 'INTEGER'), |
| 77 | ('users', 'name', 'text', 'TEXT'), |
| 78 | ('users', 'email', 'text', 'TEXT')", |
| 79 | [] |
| 80 | )?; |
| 81 | tx.commit()?; |
| 82 | |
| 83 | // Should detect drift |
| 84 | let drift = SchemaDriftDetector::detect_drift(&conn).unwrap(); |
| 85 | assert!(!drift.is_empty()); |
| 86 | assert_eq!(drift.table_drifts.len(), 1); |
| 87 | |
| 88 | let table_drift = &drift.table_drifts[0]; |
| 89 | assert_eq!(table_drift.table_name, "users"); |
| 90 | assert_eq!(table_drift.missing_in_sqlite.len(), 1); |
| 91 | assert_eq!(table_drift.missing_in_sqlite[0].name, "email"); |
| 92 | |
| 93 | Ok(()) |
| 94 | } |
| 95 | |
| 96 | #[test] |
| 97 | fn test_drift_missing_column_in_metadata() -> rusqlite::Result<()> { |