@@ -158,8 +158,38 @@ pub(crate) struct EventRow {
158158
159159#[ cfg( test) ]
160160pub ( crate ) async fn open_test_pool ( ) -> DbPool {
161- let pool = pool:: create_write_pool ( "sqlite::memory:" ) . await . unwrap ( ) ;
161+ #[ cfg( all( feature = "sqlite" , not( feature = "postgres" ) ) ) ]
162+ let url = "sqlite::memory:" ;
163+
164+ #[ cfg( all( feature = "postgres" , not( feature = "sqlite" ) ) ) ]
165+ let url_owned = std:: env:: var ( "DATABASE_URL" )
166+ . unwrap_or_else ( |_| "postgres://stackpit:stackpit@localhost:5432/stackpit_test" . into ( ) ) ;
167+ #[ cfg( all( feature = "postgres" , not( feature = "sqlite" ) ) ) ]
168+ let url = url_owned. as_str ( ) ;
169+
170+ let pool = pool:: create_write_pool ( url) . await . unwrap ( ) ;
162171 pool:: run_migrations ( & pool) . await . unwrap ( ) ;
172+
173+ // Postgres tests share a real database -- clean all data between tests.
174+ // TRUNCATE CASCADE handles foreign key ordering for us.
175+ #[ cfg( all( feature = "postgres" , not( feature = "sqlite" ) ) ) ]
176+ {
177+ sqlx:: query (
178+ "TRUNCATE events, issues, logs, spans, metrics, attachments, \
179+ issue_tag_values, integrations, project_integrations, \
180+ alert_rules, alert_state, digest_schedules, \
181+ project_keys, projects, releases, sourcemaps, upload_chunks, \
182+ discard_stats, discarded_fingerprints, inbound_filters, \
183+ message_filters, rate_limits, environment_filters, \
184+ release_filters, user_agent_filters, filter_rules, \
185+ ip_blocklist, project_repos, sync_state \
186+ CASCADE",
187+ )
188+ . execute ( & pool)
189+ . await
190+ . unwrap ( ) ;
191+ }
192+
163193 pool
164194}
165195
0 commit comments