Skip to content

Commit 6037c58

Browse files
committed
Use timestamp with time zone for timestamp fields in projection_versions.
Fixes #20.
1 parent 7a543e2 commit 6037c58

5 files changed

Lines changed: 61 additions & 53 deletions

File tree

CHANGELOG.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,15 @@
55
- Add `.formatter.exs` to Hex package ([#19](https://github.com/commanded/commanded-ecto-projections/pull/19)).
66
- Add microseconds to timestamp fields in `projection_versions` ([#22](https://github.com/commanded/commanded-ecto-projections/pull/22)).
77

8+
### Upgrading
9+
10+
- Upgrade your existing `projection_versions` table by running:
11+
12+
```sql
13+
ALTER TABLE projection_versions ALTER COLUMN inserted_at TYPE timestamp with time zone USING inserted_at AT TIME ZONE 'UTC';
14+
ALTER TABLE projection_versions ALTER COLUMN updated_at TYPE timestamp with time zone USING updated_at AT TIME ZONE 'UTC';
15+
```
16+
817
## v0.8.0
918

1019
### Enhancements
@@ -55,7 +64,6 @@
5564

5665
- Allow an Ecto schema prefix to be defined in config or per handler ([#4](https://github.com/commanded/commanded-ecto-projections/pull/4)).
5766

58-
5967
## v0.4.0
6068

6169
### Enhancements

README.md

Lines changed: 49 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -30,61 +30,61 @@ You should already have [Ecto](https://github.com/elixir-ecto/ecto) installed an
3030

3131
1. Add `commanded_ecto_projections` to your list of dependencies in `mix.exs`:
3232

33-
```elixir
34-
def deps do
35-
[
36-
{:commanded_ecto_projections, "~> 0.8"},
37-
]
38-
end
39-
```
33+
```elixir
34+
def deps do
35+
[
36+
{:commanded_ecto_projections, "~> 0.8"},
37+
]
38+
end
39+
```
4040

4141
2. Configure `commanded_ecto_projections` with the Ecto repo used by your application:
4242

43-
```elixir
44-
config :commanded_ecto_projections,
45-
repo: MyApp.Projections.Repo
46-
```
43+
```elixir
44+
config :commanded_ecto_projections,
45+
repo: MyApp.Projections.Repo
46+
```
4747

48-
Or alternatively in case of umbrella application define it later per projection:
48+
Or alternatively in case of umbrella application define it later per projection:
4949

50-
```elixir
51-
defmodule MyApp.ExampleProjector do
52-
use Commanded.Projections.Ecto,
53-
name: "example_projection",
54-
repo: MyApp.Projections.Repo
50+
```elixir
51+
defmodule MyApp.ExampleProjector do
52+
use Commanded.Projections.Ecto,
53+
name: "example_projection",
54+
repo: MyApp.Projections.Repo
5555

56-
...
57-
end
58-
```
56+
...
57+
end
58+
```
5959

6060
3. Generate an Ecto migration in your app:
6161

62-
```console
63-
$ mix ecto.gen.migration create_projection_versions
64-
```
62+
```console
63+
$ mix ecto.gen.migration create_projection_versions
64+
```
6565

6666
4. Modify the generated migration, in `priv/repo/migrations`, to create the `projection_versions` table:
6767

68-
```elixir
69-
defmodule CreateProjectionVersions do
70-
use Ecto.Migration
68+
```elixir
69+
defmodule CreateProjectionVersions do
70+
use Ecto.Migration
7171

72-
def change do
73-
create table(:projection_versions, primary_key: false) do
74-
add :projection_name, :text, primary_key: true
75-
add :last_seen_event_number, :bigint
72+
def change do
73+
create table(:projection_versions, primary_key: false) do
74+
add :projection_name, :text, primary_key: true
75+
add :last_seen_event_number, :bigint
7676

77-
timestamps()
78-
end
79-
end
80-
end
81-
```
77+
timestamps(type: :timestamptz)
78+
end
79+
end
80+
end
81+
```
8282

83-
4. Run the Ecto migration:
83+
5. Run the Ecto migration:
8484

85-
```console
86-
$ mix ecto.migrate
87-
```
85+
```console
86+
$ mix ecto.migrate
87+
```
8888

8989
### Schema Prefix
9090

@@ -250,19 +250,19 @@ To rebuild a projection you will need to:
250250

251251
1. Delete the row containing the last seen event for the projection name:
252252

253-
```SQL
254-
delete from projection_versions
255-
where projection_name = 'example_projection';
256-
```
253+
```SQL
254+
delete from projection_versions
255+
where projection_name = 'example_projection';
256+
```
257257

258258
2. Truncate the tables that are being populated by the projection, and restart their identity:
259259

260-
```SQL
261-
truncate table
262-
example_projections,
263-
other_projections
264-
restart identity;
265-
```
260+
```SQL
261+
truncate table
262+
example_projections,
263+
other_projections
264+
restart identity;
265+
```
266266

267267
You will also need to reset the event store subscription for the commanded event handler. This is specific to whichever event store you are using.
268268

lib/projections/ecto.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ defmodule Commanded.Projections.Ecto do
130130
schema "projection_versions" do
131131
field(:last_seen_event_number, :integer)
132132

133-
timestamps(type: :naive_datetime_usec)
133+
timestamps(type: :utc_datetime_usec)
134134
end
135135

136136
@required_fields ~w(last_seen_event_number)a

priv/repo/migrations/20170609113553_create_projection_versions.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ defmodule Commanded.Projections.Repo.Migrations.CreateProjectionVersions do
66
add :projection_name, :text, primary_key: true
77
add :last_seen_event_number, :bigint
88

9-
timestamps()
9+
timestamps(type: :timestamptz)
1010
end
1111
end
1212
end

priv/repo/migrations/20170929080308_create_projection_version_with_prefix.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ defmodule Commanded.Projections.Repo.Migrations.CreateProjectionVersionWithPrefi
88
add :projection_name, :text, primary_key: true
99
add :last_seen_event_number, :bigint
1010

11-
timestamps()
11+
timestamps(type: :timestamptz)
1212
end
1313
end
1414

0 commit comments

Comments
 (0)