Skip to content

Commit cc78aba

Browse files
Replace "type" index with multi-column index on "id" and "type"
1 parent ea80c2e commit cc78aba

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

CHANGELOG.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,27 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
66
and this project adheres to [Semantic Versioning](http://semver.org/).
77

88
## [Unreleased]
9+
10+
### Changed
11+
12+
- The `events` table `type` modified to include both `id` and `type` ([#69]).
13+
- This change should not affect existing applications. However, it is **recommended** to apply similar changes to the `events` table by adding a new index.
14+
- To create a new index, the following SQL could be executed manually on event store database:
15+
```sql
16+
CREATE INDEX events_id_type_index ON events ("id", "type");
17+
```
18+
Keep in mind that creating a new index will lock the table. To prevent that, you can use the following SQL:
19+
```sql
20+
CREATE INDEX CONCURRENTLY events_id_type_index ON events ("id", "type");
21+
```
22+
Read more about creating index on [PostgreSQL documentation](https://www.postgresql.org/docs/current/sql-createindex.html).
23+
- (optional) To drop the existing `type` index, the following SQL could be executed manually on event store database:
24+
```sql
25+
DROP INDEX events_type_index;
26+
```
27+
Note that you might need to keep this index if you have a custom script that uses the index.
28+
- _The above queries are suggestion so feel free to modify existing indexes as you wish._
29+
930
## [0.9.0] - 2021-11-18
1031

1132
### Added

lib/event_sourcery/postgres/schema.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def create_events(db: EventSourcery::Postgres.config.event_store_database,
3838
column :created_at, :'timestamp without time zone', null: false, default: Sequel.lit("(now() at time zone 'utc')")
3939
index [:aggregate_id, :version], unique: true
4040
index :uuid, unique: true
41-
index :type
41+
index [:id, :type]
4242
index :correlation_id
4343
index :causation_id
4444
index :created_at

0 commit comments

Comments
 (0)