-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ts/detours): add
activated_at
when detour is activated
- Loading branch information
Showing
2 changed files
with
56 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
priv/repo/async_migrations/20241218135700_backfill_detour_activated_at.exs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
defmodule Skate.Repo.Migrations.BackfillDetourActivatedAt do | ||
# https://fly.io/phoenix-files/backfilling-data/ | ||
|
||
|
||
import Ecto.Query | ||
use Ecto.Migration | ||
|
||
@disable_ddl_transaction true | ||
@disable_migration_lock true | ||
|
||
def up do | ||
# The 'backfilling-data' blog post suggests using a "throttle" function | ||
# so that we don't update too many at once, but we currently have less than | ||
# 1000 detours, so I think this will be negligable and not worth the | ||
# complexity cost at _this_ time. | ||
repo().update_all( | ||
from( | ||
r in Skate.Repo.Migrations.BackfillDetourActivatedAt.MigratingSchema, | ||
select: r.id, | ||
where: not is_nil(r.state["value"]["Detour Drawing"]["Active"]) and is_nil(r.activated_at), | ||
update: [set: [activated_at: r.updated_at]] | ||
), | ||
[], | ||
log: :info | ||
) | ||
end | ||
|
||
def down, do: :ok | ||
end | ||
|
||
defmodule Skate.Repo.Migrations.BackfillDetourActivatedAt.MigratingSchema do | ||
@moduledoc """ | ||
Detours database table schema frozen at this point in time. | ||
""" | ||
|
||
use Skate.Schema | ||
|
||
alias Skate.Settings.Db.User | ||
|
||
typed_schema "detours" do | ||
field :state, :map | ||
belongs_to :author, User | ||
|
||
# When this detour was activated | ||
field :activated_at, :utc_datetime_usec | ||
|
||
timestamps() | ||
end | ||
end |