-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #437 from zilverline/aggregate-unique-keys
Enforce user defined unique keys for aggregates
- Loading branch information
Showing
17 changed files
with
713 additions
and
282 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# frozen_string_literal: true | ||
|
||
class AggregateUniqueKeys < ActiveRecord::Migration[7.2] | ||
def up | ||
Sequent::Support::Database.with_search_path(Sequent.configuration.event_store_schema_name) do | ||
say 'Creating aggregate_unique_keys table', true | ||
suppress_messages do | ||
execute <<~SQL | ||
CREATE TABLE IF NOT EXISTS aggregate_unique_keys ( | ||
aggregate_id uuid NOT NULL, | ||
scope text NOT NULL, | ||
key jsonb NOT NULL, | ||
PRIMARY KEY (aggregate_id, scope), | ||
UNIQUE (scope, key), | ||
FOREIGN KEY (aggregate_id) REFERENCES aggregates (aggregate_id) ON UPDATE CASCADE ON DELETE CASCADE | ||
) | ||
SQL | ||
end | ||
|
||
say 'Creating event store stored procedures and views', true | ||
suppress_messages do | ||
sequent_pgsql_filename = File.join(Sequent.configuration.database_schema_directory, 'sequent_pgsql.sql') | ||
execute File.read(sequent_pgsql_filename) | ||
end | ||
end | ||
end | ||
|
||
def down | ||
fail ActiveRecord::IrreversibleMigration | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.