Skip to content

Commit f935876

Browse files
committed
⏱️ Use µsec precision for postgres timestamp/timestampz
1 parent 2d85628 commit f935876

File tree

7 files changed

+19
-19
lines changed

7 files changed

+19
-19
lines changed

lib/sequin/postgres/value_caster.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,8 @@ defmodule Sequin.Postgres.ValueCaster do
9292
# Binary Data Types
9393
"bytea" => :binary,
9494
# Date/Time Types
95-
"timestamp" => :naive_datetime,
96-
"timestamptz" => :utc_datetime,
95+
"timestamp" => :naive_datetime_usec,
96+
"timestamptz" => :utc_datetime_usec,
9797
"date" => :date,
9898
"time" => :time,
9999
"timetz" => :time,

test/support/factory/factory.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ defmodule Sequin.Factory do
3535
def iso_timestamp, do: DateTime.to_iso8601(timestamp())
3636
def last_name, do: Faker.Person.last_name()
3737
def milliseconds, do: Faker.random_between(1, 300_000)
38-
def naive_timestamp, do: NaiveDateTime.truncate(Faker.NaiveDateTime.backward(365), :second)
38+
def naive_timestamp, do: Faker.NaiveDateTime.backward(365)
3939
def one_of(module) when is_atom(module), do: one_of(module.__valid_values__())
4040
def one_of(opts), do: Enum.random(opts)
4141
def password, do: Faker.String.base64(12)

test/support/models/character.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ defmodule Sequin.TestSupport.Models.Character do
1414
field :tags, {:array, :string}
1515
field :metadata, :map
1616

17-
timestamps()
17+
timestamps(type: :naive_datetime_usec)
1818
end
1919

2020
def quoted_table_name do

test/support/models/character_detailed.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ defmodule Sequin.TestSupport.Models.CharacterDetailed do
2828
field :power_level, :integer
2929
field :embedding, {:array, :float}
3030

31-
timestamps()
31+
timestamps(type: :utc_datetime_usec)
3232
end
3333

3434
def table_oid do

test/support/models/character_ident_full.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ defmodule Sequin.TestSupport.Models.CharacterIdentFull do
1313
field :is_active, :boolean
1414
field :tags, {:array, :string}
1515

16-
timestamps()
16+
timestamps(type: :naive_datetime_usec)
1717
end
1818

1919
def table_oid do

test/support/models/character_multi_pk.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ defmodule Sequin.TestSupport.Models.CharacterMultiPK do
1414
field :name, :string
1515
field :house, :string
1616

17-
timestamps()
17+
timestamps(type: :naive_datetime_usec)
1818
end
1919

2020
def table_oid do

test/support/unboxed_repo/migrations/20240816005458_create_test_tables.exs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ defmodule Sequin.Test.UnboxedRepo.Migrations.CreateTestTables do
1111
add :tags, {:array, :text}
1212
add :metadata, :map
1313

14-
timestamps()
14+
timestamps(type: :naive_datetime_usec)
1515
end
1616

1717
create table(:characters_ident_full) do
@@ -21,7 +21,7 @@ defmodule Sequin.Test.UnboxedRepo.Migrations.CreateTestTables do
2121
add :is_active, :boolean
2222
add :tags, {:array, :text}
2323

24-
timestamps()
24+
timestamps(type: :naive_datetime_usec)
2525
end
2626

2727
execute "alter table characters_ident_full replica identity full"
@@ -34,7 +34,7 @@ defmodule Sequin.Test.UnboxedRepo.Migrations.CreateTestTables do
3434
add :name, :text
3535
add :house, :text
3636

37-
timestamps()
37+
timestamps(type: :naive_datetime_usec)
3838
end
3939

4040
execute "CREATE EXTENSION IF NOT EXISTS pg_trgm"
@@ -69,7 +69,7 @@ defmodule Sequin.Test.UnboxedRepo.Migrations.CreateTestTables do
6969
add :active_period, :daterange
7070
add :embedding, :vector, size: 3
7171

72-
timestamps()
72+
timestamps(type: :naive_datetime_usec)
7373
end
7474

7575
# Older version without transaction_annotations
@@ -84,8 +84,8 @@ defmodule Sequin.Test.UnboxedRepo.Migrations.CreateTestTables do
8484
add :record, :map, null: false
8585
add :changes, :map
8686
add :action, :string, null: false
87-
add :committed_at, :utc_datetime, null: false
88-
add :inserted_at, :utc_datetime, null: false, default: fragment("NOW()")
87+
add :committed_at, :naive_datetime_usec, null: false
88+
add :inserted_at, :naive_datetime_usec, null: false, default: fragment("NOW()")
8989
end
9090

9191
create unique_index(:test_event_logs_v0, [:source_database_id, :committed_at, :seq, :record_pk])
@@ -106,8 +106,8 @@ defmodule Sequin.Test.UnboxedRepo.Migrations.CreateTestTables do
106106
add :changes, :map
107107
add :action, :string, null: false
108108
add :transaction_annotations, :map
109-
add :committed_at, :utc_datetime, null: false
110-
add :inserted_at, :utc_datetime, null: false, default: fragment("NOW()")
109+
add :committed_at, :naive_datetime_usec, null: false
110+
add :inserted_at, :naive_datetime_usec, null: false, default: fragment("NOW()")
111111
end
112112

113113
create unique_index(:test_event_logs, [:source_database_id, :committed_at, :seq, :record_pk])
@@ -127,8 +127,8 @@ defmodule Sequin.Test.UnboxedRepo.Migrations.CreateTestTables do
127127
add :record, :map, null: false
128128
add :changes, :map
129129
add :action, :string, null: false
130-
add :committed_at, :utc_datetime, null: false, primary_key: true
131-
add :inserted_at, :utc_datetime, null: false, default: fragment("NOW()")
130+
add :committed_at, :naive_datetime_usec, null: false, primary_key: true
131+
add :inserted_at, :naive_datetime_usec, null: false, default: fragment("NOW()")
132132
end
133133

134134
execute "CREATE TABLE test_event_logs_partitioned_default PARTITION OF test_event_logs_partitioned DEFAULT"
@@ -153,8 +153,8 @@ defmodule Sequin.Test.UnboxedRepo.Migrations.CreateTestTables do
153153
add :record, :map, null: false
154154
add :changes, :map
155155
add :action, :text, null: false
156-
add :committed_at, :utc_datetime, null: false
157-
add :inserted_at, :utc_datetime, null: false, default: fragment("NOW()")
156+
add :committed_at, :naive_datetime_usec, null: false
157+
add :inserted_at, :naive_datetime_usec, null: false, default: fragment("NOW()")
158158
end
159159

160160
create unique_index(:sequin_events, [:source_database_id, :committed_at, :seq, :record_pk])

0 commit comments

Comments
 (0)