@@ -172,3 +172,79 @@ def test_schemas_with_migrations(self) -> None:
172172 # Test exists_in_other_schemas for sm2
173173 other_schemas = sm2 .exists_in_other_schemas (conn )
174174 self .assertEqual (other_schemas , ["public" ])
175+
176+ def test_schemas_with_migration_details_empty (self ) -> None :
177+ """Test schemas_with_migration_details when no migrations exist."""
178+ with psycopg .connect (f"service={ self .pg_service } " ) as conn :
179+ details = SchemaMigrations .schemas_with_migration_details (conn )
180+ self .assertEqual (details , [])
181+
182+ def test_schemas_with_migration_details_single_schema (self ) -> None :
183+ """Test schemas_with_migration_details with a single installed module."""
184+ test_dir = Path ("test" ) / "data" / "single_changelog"
185+ cfg = PumConfig (test_dir , pum = {"module" : "test_module" })
186+ sm = SchemaMigrations (cfg )
187+
188+ with psycopg .connect (f"service={ self .pg_service } " ) as conn :
189+ sm .create (connection = conn )
190+ sm .set_baseline (connection = conn , version = "1.2.3" )
191+
192+ details = SchemaMigrations .schemas_with_migration_details (conn )
193+ self .assertEqual (len (details ), 1 )
194+ detail = details [0 ]
195+ self .assertEqual (detail ["schema" ], "public" )
196+ self .assertEqual (detail ["module" ], "test_module" )
197+ self .assertEqual (detail ["version" ], "1.2.3" )
198+ self .assertIsNotNone (detail ["installed_date" ])
199+ self .assertIsNone (detail ["upgrade_date" ]) # No upgrade yet
200+ self .assertFalse (detail ["beta_testing" ])
201+
202+ def test_schemas_with_migration_details_after_upgrade (self ) -> None :
203+ """Test schemas_with_migration_details shows upgrade_date after a second baseline."""
204+ test_dir = Path ("test" ) / "data" / "single_changelog"
205+ cfg = PumConfig (test_dir , pum = {"module" : "test_module" })
206+ sm = SchemaMigrations (cfg )
207+
208+ with psycopg .connect (f"service={ self .pg_service } " ) as conn :
209+ sm .create (connection = conn )
210+ sm .set_baseline (connection = conn , version = "1.2.3" , commit = True )
211+
212+ # Use a separate connection/transaction so now() differs
213+ with psycopg .connect (f"service={ self .pg_service } " ) as conn :
214+ sm .set_baseline (connection = conn , version = "1.2.4" , commit = True )
215+
216+ details = SchemaMigrations .schemas_with_migration_details (conn )
217+ self .assertEqual (len (details ), 1 )
218+ detail = details [0 ]
219+ self .assertEqual (detail ["version" ], "1.2.4" )
220+ self .assertIsNotNone (detail ["installed_date" ])
221+ self .assertIsNotNone (detail ["upgrade_date" ]) # Upgrade happened
222+
223+ def test_schemas_with_migration_details_multiple_schemas (self ) -> None :
224+ """Test schemas_with_migration_details with modules in different schemas."""
225+ test_dir = Path ("test" ) / "data" / "single_changelog"
226+ cfg1 = PumConfig (test_dir , pum = {"module" : "module_a" , "migration_table_schema" : "public" })
227+ cfg2 = PumConfig (
228+ test_dir ,
229+ pum = {"module" : "module_b" , "migration_table_schema" : "pum_custom_migrations_schema" },
230+ )
231+ sm1 = SchemaMigrations (cfg1 )
232+ sm2 = SchemaMigrations (cfg2 )
233+
234+ with psycopg .connect (f"service={ self .pg_service } " ) as conn :
235+ sm1 .create (connection = conn , allow_multiple_modules = True )
236+ sm1 .set_baseline (connection = conn , version = "1.0.0" )
237+
238+ sm2 .create (connection = conn , allow_multiple_modules = True )
239+ sm2 .set_baseline (connection = conn , version = "2.0.0" )
240+
241+ details = SchemaMigrations .schemas_with_migration_details (conn )
242+ self .assertEqual (len (details ), 2 )
243+
244+ by_schema = {d ["schema" ]: d for d in details }
245+ self .assertIn ("public" , by_schema )
246+ self .assertIn ("pum_custom_migrations_schema" , by_schema )
247+ self .assertEqual (by_schema ["public" ]["module" ], "module_a" )
248+ self .assertEqual (by_schema ["public" ]["version" ], "1.0.0" )
249+ self .assertEqual (by_schema ["pum_custom_migrations_schema" ]["module" ], "module_b" )
250+ self .assertEqual (by_schema ["pum_custom_migrations_schema" ]["version" ], "2.0.0" )
0 commit comments