Test the dev baseline case in diagnoseMigrationHistory
@@ -750,3 +750,44 @@ async fn with_an_invalid_unapplied_migration_should_report_it(api: &TestApi) ->
Ok(())
}
+
+#[test_each_connector(tags("postgres"))]
+async fn drift_can_be_detected_without_migrations_table(api: &TestApi) -> TestResult {
+ let directory = api.create_migrations_directory()?;
+
+ api.apply_script("CREATE TABLE \"Cat\" (\nid SERIAL PRIMARY KEY\n);")
+ .await?;
+
+ let dm1 = r#"
+ model Cat {
+ id Int @id @default(autoincrement())
+ }
+ "#;
+
+ api.create_migration("initial", dm1, &directory).send().await?;
+
+ let DiagnoseMigrationHistoryOutput {
+ drift,
+ history,
+ edited_migration_names,
+ failed_migration_names,
+ has_migrations_table,
+ error_in_unapplied_migration,
+ } = api
+ .diagnose_migration_history(&directory)
+ .opt_in_to_shadow_database(true)
+ .send()
+ .await?
+ .into_output();
+
+ assert!(matches!(drift, Some(DriftDiagnostic::DriftDetected { rollback: _ })));
+ assert!(
+ matches!(history, Some(HistoryDiagnostic::DatabaseIsBehind { unapplied_migration_names: migs }) if migs.len() == 1)
+ );
+ assert!(failed_migration_names.is_empty());
+ assert!(edited_migration_names.is_empty());
+ assert!(!has_migrations_table);
+ assert!(error_in_unapplied_migration.is_none());
+
+ Ok(())
+}
