From 9cb545d1bdcbc799368d62cbd6a2270f2c47808e Mon Sep 17 00:00:00 2001 From: Andrew Kostka Date: Tue, 14 Jul 2026 07:39:04 +0000 Subject: [PATCH 1/2] Add migration to backfill terms of use --- ...kfill_policy_acceptance_existing_users.php | 63 +++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 database/migrations/2026_07_13_075347_backfill_policy_acceptance_existing_users.php diff --git a/database/migrations/2026_07_13_075347_backfill_policy_acceptance_existing_users.php b/database/migrations/2026_07_13_075347_backfill_policy_acceptance_existing_users.php new file mode 100644 index 00000000..fbe37635 --- /dev/null +++ b/database/migrations/2026_07_13_075347_backfill_policy_acceptance_existing_users.php @@ -0,0 +1,63 @@ +getPolicyId(); + $timestamp = now(); + + DB::table('users') + ->leftJoin('policy_acceptances', fn ($join) => + $join->on('users.id', '=', 'user_id') + ->where('policy_id', '=', $policyId) + ) + ->whereNull('policy_id') + ->where('users.created_at', '<', self::USER_CREATED_AT_CUTOFF) + ->orderBy('users.id') + ->select('users.id', 'users.created_at') + ->chunkById(100, fn ($users) => + DB::table('policy_acceptances')->insert( + $users->map(fn ($user) => [ + 'user_id' => $user->id, + 'policy_id' => $policyId, + 'accepted_at' => $user->created_at, + 'created_at' => $timestamp, + 'updated_at' => $timestamp, + ])->all() + ), + 'users.id', 'id'); + } + + /** + * Reverse the migrations. + */ + public function down(): void { + DB::table('policy_acceptances') + ->where('policy_id', $this->getPolicyId()) + ->where('accepted_at', '<', self::USER_CREATED_AT_CUTOFF) + ->whereColumn('created_at', '>', 'accepted_at') + ->delete(); + } + + /** + * @return int The policy ID of our existing terms of use. + */ + private function getPolicyId(): int { + return DB::table('policies') + ->where('policy_type', 'terms-of-use') + ->where('active_from', '2022-01-01') + ->soleValue('id'); + } +}; From 272d4ebab9ff8b38103042c9a13cc55d6dbd4219 Mon Sep 17 00:00:00 2001 From: Andrew Kostka Date: Tue, 14 Jul 2026 07:52:35 +0000 Subject: [PATCH 2/2] Fix linting --- ...kfill_policy_acceptance_existing_users.php | 26 +++++++++---------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/database/migrations/2026_07_13_075347_backfill_policy_acceptance_existing_users.php b/database/migrations/2026_07_13_075347_backfill_policy_acceptance_existing_users.php index fbe37635..c48bbc27 100644 --- a/database/migrations/2026_07_13_075347_backfill_policy_acceptance_existing_users.php +++ b/database/migrations/2026_07_13_075347_backfill_policy_acceptance_existing_users.php @@ -19,25 +19,23 @@ public function up(): void { $timestamp = now(); DB::table('users') - ->leftJoin('policy_acceptances', fn ($join) => - $join->on('users.id', '=', 'user_id') - ->where('policy_id', '=', $policyId) + ->leftJoin('policy_acceptances', fn ($join) => $join->on('users.id', '=', 'user_id') + ->where('policy_id', '=', $policyId) ) ->whereNull('policy_id') ->where('users.created_at', '<', self::USER_CREATED_AT_CUTOFF) ->orderBy('users.id') ->select('users.id', 'users.created_at') - ->chunkById(100, fn ($users) => - DB::table('policy_acceptances')->insert( - $users->map(fn ($user) => [ - 'user_id' => $user->id, - 'policy_id' => $policyId, - 'accepted_at' => $user->created_at, - 'created_at' => $timestamp, - 'updated_at' => $timestamp, - ])->all() - ), - 'users.id', 'id'); + ->chunkById(100, fn ($users) => DB::table('policy_acceptances')->insert( + $users->map(fn ($user) => [ + 'user_id' => $user->id, + 'policy_id' => $policyId, + 'accepted_at' => $user->created_at, + 'created_at' => $timestamp, + 'updated_at' => $timestamp, + ])->all() + ), + 'users.id', 'id'); } /**