Skip to content

Commit

Permalink
Use timestamp with time zone for timestamp fields in `projection_ve…
Browse files Browse the repository at this point in the history
…rsions`.

Fixes commanded#20.
  • Loading branch information
datafoo committed Feb 5, 2019
1 parent 7a543e2 commit 6037c58
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 53 deletions.
10 changes: 9 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@
- Add `.formatter.exs` to Hex package ([#19](https://github.com/commanded/commanded-ecto-projections/pull/19)).
- Add microseconds to timestamp fields in `projection_versions` ([#22](https://github.com/commanded/commanded-ecto-projections/pull/22)).

### Upgrading

- Upgrade your existing `projection_versions` table by running:

```sql
ALTER TABLE projection_versions ALTER COLUMN inserted_at TYPE timestamp with time zone USING inserted_at AT TIME ZONE 'UTC';
ALTER TABLE projection_versions ALTER COLUMN updated_at TYPE timestamp with time zone USING updated_at AT TIME ZONE 'UTC';
```

## v0.8.0

### Enhancements
Expand Down Expand Up @@ -55,7 +64,6 @@

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


## v0.4.0

### Enhancements
Expand Down
98 changes: 49 additions & 49 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,61 +30,61 @@ You should already have [Ecto](https://github.com/elixir-ecto/ecto) installed an

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

```elixir
def deps do
[
{:commanded_ecto_projections, "~> 0.8"},
]
end
```
```elixir
def deps do
[
{:commanded_ecto_projections, "~> 0.8"},
]
end
```

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

```elixir
config :commanded_ecto_projections,
repo: MyApp.Projections.Repo
```
```elixir
config :commanded_ecto_projections,
repo: MyApp.Projections.Repo
```

Or alternatively in case of umbrella application define it later per projection:
Or alternatively in case of umbrella application define it later per projection:

```elixir
defmodule MyApp.ExampleProjector do
use Commanded.Projections.Ecto,
name: "example_projection",
repo: MyApp.Projections.Repo
```elixir
defmodule MyApp.ExampleProjector do
use Commanded.Projections.Ecto,
name: "example_projection",
repo: MyApp.Projections.Repo

...
end
```
...
end
```

3. Generate an Ecto migration in your app:

```console
$ mix ecto.gen.migration create_projection_versions
```
```console
$ mix ecto.gen.migration create_projection_versions
```

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

```elixir
defmodule CreateProjectionVersions do
use Ecto.Migration
```elixir
defmodule CreateProjectionVersions do
use Ecto.Migration

def change do
create table(:projection_versions, primary_key: false) do
add :projection_name, :text, primary_key: true
add :last_seen_event_number, :bigint
def change do
create table(:projection_versions, primary_key: false) do
add :projection_name, :text, primary_key: true
add :last_seen_event_number, :bigint

timestamps()
end
end
end
```
timestamps(type: :timestamptz)
end
end
end
```

4. Run the Ecto migration:
5. Run the Ecto migration:

```console
$ mix ecto.migrate
```
```console
$ mix ecto.migrate
```

### Schema Prefix

Expand Down Expand Up @@ -250,19 +250,19 @@ To rebuild a projection you will need to:

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

```SQL
delete from projection_versions
where projection_name = 'example_projection';
```
```SQL
delete from projection_versions
where projection_name = 'example_projection';
```

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

```SQL
truncate table
example_projections,
other_projections
restart identity;
```
```SQL
truncate table
example_projections,
other_projections
restart identity;
```

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.

Expand Down
2 changes: 1 addition & 1 deletion lib/projections/ecto.ex
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ defmodule Commanded.Projections.Ecto do
schema "projection_versions" do
field(:last_seen_event_number, :integer)

timestamps(type: :naive_datetime_usec)
timestamps(type: :utc_datetime_usec)
end

@required_fields ~w(last_seen_event_number)a
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ defmodule Commanded.Projections.Repo.Migrations.CreateProjectionVersions do
add :projection_name, :text, primary_key: true
add :last_seen_event_number, :bigint

timestamps()
timestamps(type: :timestamptz)
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ defmodule Commanded.Projections.Repo.Migrations.CreateProjectionVersionWithPrefi
add :projection_name, :text, primary_key: true
add :last_seen_event_number, :bigint

timestamps()
timestamps(type: :timestamptz)
end
end

Expand Down

0 comments on commit 6037c58

Please sign in to comment.