From cc78abac5485548af2b7fde2d821c6a5e0c3707f Mon Sep 17 00:00:00 2001 From: Daniel Niknam Date: Thu, 28 Oct 2021 00:02:22 +1100 Subject: [PATCH] Replace "type" index with multi-column index on "id" and "type" --- CHANGELOG.md | 21 +++++++++++++++++++++ lib/event_sourcery/postgres/schema.rb | 2 +- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a8005b4..1631f1d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,27 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). ## [Unreleased] + +### Changed + +- The `events` table `type` modified to include both `id` and `type` ([#69]). + - This change should not affect existing applications. However, it is **recommended** to apply similar changes to the `events` table by adding a new index. + - To create a new index, the following SQL could be executed manually on event store database: + ```sql + CREATE INDEX events_id_type_index ON events ("id", "type"); + ``` + Keep in mind that creating a new index will lock the table. To prevent that, you can use the following SQL: + ```sql + CREATE INDEX CONCURRENTLY events_id_type_index ON events ("id", "type"); + ``` + Read more about creating index on [PostgreSQL documentation](https://www.postgresql.org/docs/current/sql-createindex.html). + - (optional) To drop the existing `type` index, the following SQL could be executed manually on event store database: + ```sql + DROP INDEX events_type_index; + ``` + Note that you might need to keep this index if you have a custom script that uses the index. + - _The above queries are suggestion so feel free to modify existing indexes as you wish._ + ## [0.9.0] - 2021-11-18 ### Added diff --git a/lib/event_sourcery/postgres/schema.rb b/lib/event_sourcery/postgres/schema.rb index b1fe58c..7cf0929 100644 --- a/lib/event_sourcery/postgres/schema.rb +++ b/lib/event_sourcery/postgres/schema.rb @@ -38,7 +38,7 @@ def create_events(db: EventSourcery::Postgres.config.event_store_database, column :created_at, :'timestamp without time zone', null: false, default: Sequel.lit("(now() at time zone 'utc')") index [:aggregate_id, :version], unique: true index :uuid, unique: true - index :type + index [:id, :type] index :correlation_id index :causation_id index :created_at