Skip to content

Commit df5795b

Browse files
committed
Clarify annotations migration
1 parent 4a5b1af commit df5795b

1 file changed

Lines changed: 18 additions & 6 deletions

File tree

priv/repo/migrations/20260421101200_create_annotations.exs

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,27 @@ defmodule Plausible.Repo.Migrations.CreateAnnotations do
1212
"DROP TYPE annotation_granularity"
1313
)
1414

15+
# Example annotations
16+
#
17+
# id | note | granularity | datetime
18+
# ---+-----------------------------+-------------+--------------------
19+
# 1 | Christmas sale | date | 2025-12-14 00:00:00
20+
# 2 | Released feature X | minute | 2026-05-08 14:00:00
21+
#
22+
# Depending on granularity, the datetime must be interpreted in a different way:
23+
#
24+
# For granularity "date", only the date part of the `datetime` is meaningful.
25+
# The annotation is on that particular calendar date, no matter the timezone.
26+
# We store it as midnight, 00:00:00, but we could just as well store it as 13:37:00:
27+
# the time must be ignored by the server.
28+
#
29+
# For granularity "time", all of the datetime is meaningful.
30+
# The annotation is at that particular point in time. It's stored as UTC timestamp (naive)
31+
# and must be shifted to the site timezone.
32+
1533
create table(:annotations) do
1634
add :note, :string, null: false
1735
add :type, :annotation_type, null: false, default: "personal"
18-
# UTC datetime. The local date/time is derived by the frontend using the
19-
# site's configured timezone at display time.
20-
# granularity='date' — caller provides UTC midnight of the intended local date;
21-
# only the date component is shown.
22-
# granularity='minute' — caller provides the exact UTC moment;
23-
# both date and HH:MM are shown in site-local time.
2436
add :datetime, :utc_datetime, null: false
2537
add :granularity, :annotation_granularity, null: false
2638
add :site_id, references(:sites, on_delete: :delete_all), null: false

0 commit comments

Comments
 (0)