|
1 | 1 | //! PostgreSQL contract for the event follow-up producers (push match |
2 | 2 | //! enqueue and channel TTL refresh), on the desired and migration schemas, |
3 | | -//! with historical overlap, push retired, and both follow-ups app-only. |
| 3 | +//! app-only as shipped and with the historical trigger overlap reconstructed. |
4 | 4 | use crate::replaceable::{ParameterizedReplacePrecondition, ParameterizedReplaceStatus}; |
5 | 5 | use crate::{event, migration, push, AdmittedTx, Db, DbConfig, DbError}; |
6 | 6 | use buzz_core::CommunityId; |
@@ -214,67 +214,66 @@ async fn activate_lease( |
214 | 214 | ); |
215 | 215 | } |
216 | 216 |
|
217 | | -/// Preserve the overlap and fully app-only compatibility contracts alongside |
218 | | -/// the shipped push-only retirement (the TTL trigger remains installed). |
| 217 | +/// Which producers are live. `AppOnly` is the shipped schema: 0063 and 0065 |
| 218 | +/// retired both follow-up triggers. `Dual` reconstructs the historical overlap |
| 219 | +/// (app follow-ups plus both triggers) in this disposable database only. |
219 | 220 | #[derive(Clone, Copy, Debug)] |
220 | 221 | enum Arm { |
221 | 222 | Dual, |
222 | 223 | AppOnly, |
223 | | - PushRetired, |
224 | 224 | } |
225 | 225 |
|
226 | 226 | async fn apply_arm(pool: &PgPool, arm: Arm) { |
227 | 227 | let triggers: i64 = sqlx::query_scalar( |
228 | 228 | "SELECT count(*) FROM pg_trigger \ |
229 | | - WHERE tgrelid = 'events'::regclass \ |
230 | | - AND tgname IN ('events_enqueue_push_match', 'events_refresh_channel_ttl')", |
| 229 | + WHERE tgname IN ('events_enqueue_push_match', 'events_refresh_channel_ttl')", |
231 | 230 | ) |
232 | 231 | .fetch_one(pool) |
233 | 232 | .await |
234 | | - .expect("count follow-up triggers"); |
| 233 | + .expect("count follow-up triggers, including partition clones"); |
235 | 234 | assert_eq!( |
236 | | - triggers, 1, |
237 | | - "only the TTL trigger remains in the shipped schema" |
| 235 | + triggers, 0, |
| 236 | + "no follow-up trigger remains on any partition of the shipped schema" |
238 | 237 | ); |
239 | | - let absent: bool = |
240 | | - sqlx::query_scalar("SELECT to_regprocedure('enqueue_push_match_job()') IS NULL") |
241 | | - .fetch_one(pool) |
242 | | - .await |
243 | | - .unwrap(); |
244 | | - assert!(absent); |
245 | | - match arm { |
246 | | - Arm::Dual => { |
247 | | - // Reconstruct the historical overlap explicitly in this test only. |
248 | | - sqlx::raw_sql(include_str!( |
249 | | - "../../../../migrations/0040_push_message_kinds.sql" |
250 | | - )) |
251 | | - .execute(pool) |
252 | | - .await |
253 | | - .unwrap(); |
254 | | - sqlx::raw_sql(include_str!( |
255 | | - "../../../../migrations/0059_push_rollback_gate.sql" |
256 | | - )) |
257 | | - .execute(pool) |
258 | | - .await |
259 | | - .unwrap(); |
260 | | - sqlx::query("CREATE TRIGGER events_enqueue_push_match AFTER INSERT ON events FOR EACH ROW EXECUTE FUNCTION enqueue_push_match_job()") |
261 | | - .execute(pool).await.unwrap(); |
262 | | - } |
263 | | - Arm::AppOnly => { |
264 | | - sqlx::query("DROP TRIGGER events_refresh_channel_ttl ON events") |
265 | | - .execute(pool) |
266 | | - .await |
267 | | - .unwrap(); |
268 | | - } |
269 | | - Arm::PushRetired => {} |
270 | | - } |
271 | | - if !matches!(arm, Arm::Dual) { |
| 238 | + let absent: bool = sqlx::query_scalar( |
| 239 | + "SELECT to_regprocedure('enqueue_push_match_job()') IS NULL \ |
| 240 | + AND to_regprocedure('refresh_channel_ttl_after_event_insert()') IS NULL", |
| 241 | + ) |
| 242 | + .fetch_one(pool) |
| 243 | + .await |
| 244 | + .unwrap(); |
| 245 | + assert!(absent, "no follow-up trigger function remains"); |
| 246 | + if let Arm::Dual = arm { |
272 | 247 | sqlx::raw_sql(include_str!( |
273 | | - "../../../../migrations/0059_push_rollback_gate.sql" |
| 248 | + "../../../../migrations/0040_push_message_kinds.sql" |
274 | 249 | )) |
275 | 250 | .execute(pool) |
276 | 251 | .await |
277 | 252 | .unwrap(); |
| 253 | + sqlx::raw_sql(include_str!( |
| 254 | + "../../../../migrations/0024_event_ttl_refresh_shared_lock.sql" |
| 255 | + )) |
| 256 | + .execute(pool) |
| 257 | + .await |
| 258 | + .unwrap(); |
| 259 | + } |
| 260 | + sqlx::raw_sql(include_str!( |
| 261 | + "../../../../migrations/0059_push_rollback_gate.sql" |
| 262 | + )) |
| 263 | + .execute(pool) |
| 264 | + .await |
| 265 | + .unwrap(); |
| 266 | + if let Arm::Dual = arm { |
| 267 | + for statement in [ |
| 268 | + "CREATE TRIGGER events_enqueue_push_match AFTER INSERT ON events \ |
| 269 | + FOR EACH ROW EXECUTE FUNCTION enqueue_push_match_job()", |
| 270 | + "CREATE CONSTRAINT TRIGGER events_refresh_channel_ttl AFTER INSERT ON events \ |
| 271 | + DEFERRABLE INITIALLY DEFERRED \ |
| 272 | + FOR EACH ROW EXECUTE FUNCTION refresh_channel_ttl_after_event_insert()", |
| 273 | + ] { |
| 274 | + sqlx::query(statement).execute(pool).await.unwrap(); |
| 275 | + } |
| 276 | + } else { |
278 | 277 | let absent: bool = |
279 | 278 | sqlx::query_scalar("SELECT to_regprocedure('enqueue_push_match_job()') IS NULL") |
280 | 279 | .fetch_one(pool) |
@@ -512,7 +511,7 @@ async fn assert_contract(migration_schema: bool, arm: Arm) { |
512 | 511 | assert!( |
513 | 512 | deadline(pool, community, channel).await |
514 | 513 | >= database_time_before_commit + chrono::Duration::seconds(60), |
515 | | - "the deferred trigger must refresh TTL at commit" |
| 514 | + "the TTL refresh must set the deadline at commit time" |
516 | 515 | ); |
517 | 516 | assert_eq!(match_count(&db, community, &committed).await, 1); |
518 | 517 |
|
@@ -824,18 +823,6 @@ async fn migration_schema_event_follow_up_contract_app_only() { |
824 | 823 | assert_contract(true, Arm::AppOnly).await; |
825 | 824 | } |
826 | 825 |
|
827 | | -#[tokio::test] |
828 | | -#[ignore = "requires Postgres"] |
829 | | -async fn desired_event_follow_up_contract_push_retired() { |
830 | | - assert_contract(false, Arm::PushRetired).await; |
831 | | -} |
832 | | - |
833 | | -#[tokio::test] |
834 | | -#[ignore = "requires Postgres"] |
835 | | -async fn migration_schema_event_follow_up_contract_push_retired() { |
836 | | - assert_contract(true, Arm::PushRetired).await; |
837 | | -} |
838 | | - |
839 | 826 | // Runs with both schema sources and with/without the overlap trigger. |
840 | 827 | async fn assert_rollback(db: &Db, community: CommunityId, channel: Uuid, keys: &Keys) { |
841 | 828 | let pool = db.pool(); |
|
0 commit comments