ruby_event_store-active_record 2.11.1 → 2.12.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (20) hide show
  1. checksums.yaml +4 -4
  2. data/lib/ruby_event_store/active_record/event_repository_reader.rb +8 -0
  3. data/lib/ruby_event_store/active_record/generators/database_adapter.rb +100 -0
  4. data/lib/ruby_event_store/active_record/generators/foreign_key_on_event_id_migration_generator.rb +61 -0
  5. data/lib/ruby_event_store/active_record/generators/migration_generator.rb +5 -14
  6. data/lib/ruby_event_store/active_record/generators/rails_foreign_key_on_event_id_migration_generator.rb +56 -0
  7. data/lib/ruby_event_store/active_record/generators/rails_migration_generator.rb +10 -16
  8. data/lib/ruby_event_store/active_record/generators/templates/add_foreign_key_on_event_id_to_event_store_events_in_streams_template.erb +7 -0
  9. data/lib/ruby_event_store/active_record/generators/templates/create_event_store_events_template.erb +2 -0
  10. data/lib/ruby_event_store/active_record/generators/templates/mysql/add_foreign_key_on_event_id_to_event_store_events_in_streams_template.erb +7 -0
  11. data/lib/ruby_event_store/active_record/generators/templates/mysql/create_event_store_events_template.erb +2 -0
  12. data/lib/ruby_event_store/active_record/generators/templates/postgres/add_foreign_key_on_event_id_to_event_store_events_in_streams_template.erb +7 -0
  13. data/lib/ruby_event_store/active_record/generators/templates/postgres/create_event_store_events_template.erb +2 -0
  14. data/lib/ruby_event_store/active_record/generators/templates/postgres/validate_add_foreign_key_on_event_id_to_event_store_events_in_streams_template.erb +7 -0
  15. data/lib/ruby_event_store/active_record/tasks/migration_tasks.rake +13 -6
  16. data/lib/ruby_event_store/active_record/version.rb +1 -1
  17. data/lib/ruby_event_store/active_record.rb +3 -2
  18. metadata +11 -6
  19. data/lib/ruby_event_store/active_record/generators/templates/template_directory.rb +0 -16
  20. data/lib/ruby_event_store/active_record/generators/verify_data_type_for_adapter.rb +0 -45
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8cd51c2d204db4312e3e4a90b15bb2200f3b9cc8e53aaf0c2ea5e1acfdca2ee4
4
- data.tar.gz: 7af5b1d11ee794462a5713fd2818e9095a82ee2f4befaba66fa77df2072219f3
3
+ metadata.gz: 9987cdb6acdbe0954d31ef08815daeea9cf3bab6b0069bf5e03e2a60463bf13e
4
+ data.tar.gz: bd8b1464de23ef8cc10e256ff90eee0c1851010cd23634f7484e1a1e9dc9544d
5
5
  SHA512:
6
- metadata.gz: 4f82c7e63124e4a34b72bdc41b5a3dbd479b86a8f982b96586b3a270efaf2ca02b587899065e91d1c0173825f992a1cc8c0c4bcfcbc1a51ea2335c5ccbb5f3f5
7
- data.tar.gz: a58e7400b9332a4ced9ad85585637248df7ea7eaa7ea86323dae32bc9557f0224a8d41f031d527f9cf326e19a6f8b7a5a48a851b30c639d95dfc6e6e765088eb
6
+ metadata.gz: 61ceca1ee73adec8f023606dda0afb08f3b00f0bfe09be545ef909b093a71467a097ee2f2cf28224552e4b1c724d9eb23c8dd7b121c2925afc67861b5fccadb6
7
+ data.tar.gz: 657b3186c572ed9f0e457640f1e5721b01e089aa330edc6886dac2fddd86c8f92b23a62d7a7f0dbf857c0daba9b987843c3997ea413a766fff9984d04ebfecb0
@@ -139,6 +139,8 @@ module RubyEventStore
139
139
  @stream_klass.find_by!(event_id: specification.start, stream: specification.stream.name),
140
140
  @stream_klass.table_name
141
141
  )
142
+ rescue ::ActiveRecord::RecordNotFound
143
+ raise EventNotFound.new(specification.start)
142
144
  end
143
145
 
144
146
  def stop_condition(specification)
@@ -147,6 +149,8 @@ module RubyEventStore
147
149
  @stream_klass.find_by!(event_id: specification.stop, stream: specification.stream.name),
148
150
  @stream_klass.table_name
149
151
  )
152
+ rescue ::ActiveRecord::RecordNotFound
153
+ raise EventNotFound.new(specification.stop)
150
154
  end
151
155
 
152
156
  def start_condition_in_global_stream(specification)
@@ -155,6 +159,8 @@ module RubyEventStore
155
159
  @event_klass.find_by!(event_id: specification.start),
156
160
  @event_klass.table_name
157
161
  )
162
+ rescue ::ActiveRecord::RecordNotFound
163
+ raise EventNotFound.new(specification.start)
158
164
  end
159
165
 
160
166
  def stop_condition_in_global_stream(specification)
@@ -163,6 +169,8 @@ module RubyEventStore
163
169
  @event_klass.find_by!(event_id: specification.stop),
164
170
  @event_klass.table_name
165
171
  )
172
+ rescue ::ActiveRecord::RecordNotFound
173
+ raise EventNotFound.new(specification.stop)
166
174
  end
167
175
 
168
176
  def coalesce(*exprs)
@@ -0,0 +1,100 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RubyEventStore
4
+ module ActiveRecord
5
+ UnsupportedAdapter = Class.new(StandardError)
6
+ InvalidDataTypeForAdapter = Class.new(StandardError)
7
+
8
+ class DatabaseAdapter
9
+ NOT_SET = Object.new.freeze
10
+
11
+ class PostgreSQL < self
12
+ SUPPORTED_DATA_TYPES = %w[binary json jsonb].freeze
13
+
14
+ def initialize(data_type = NOT_SET)
15
+ super("postgresql", data_type)
16
+ end
17
+
18
+ def template_directory
19
+ "postgres/"
20
+ end
21
+ end
22
+
23
+ class MySQL < self
24
+ SUPPORTED_DATA_TYPES = %w[binary json].freeze
25
+
26
+ def initialize(data_type = NOT_SET)
27
+ super("mysql2", data_type)
28
+ end
29
+
30
+ def template_directory
31
+ "mysql/"
32
+ end
33
+ end
34
+
35
+ class SQLite < self
36
+ SUPPORTED_DATA_TYPES = %w[binary].freeze
37
+
38
+ def initialize(data_type = NOT_SET)
39
+ super("sqlite", data_type)
40
+ end
41
+ end
42
+
43
+ def initialize(adapter_name, data_type)
44
+ raise UnsupportedAdapter if instance_of?(DatabaseAdapter)
45
+
46
+ validate_data_type!(data_type)
47
+
48
+ @adapter_name = adapter_name
49
+ @data_type = data_type
50
+ end
51
+
52
+ attr_reader :adapter_name, :data_type
53
+
54
+ def supported_data_types
55
+ self.class::SUPPORTED_DATA_TYPES
56
+ end
57
+
58
+ def eql?(other)
59
+ other.is_a?(DatabaseAdapter) && adapter_name.eql?(other.adapter_name)
60
+ end
61
+
62
+ alias == eql?
63
+
64
+ def hash
65
+ DatabaseAdapter.hash ^ adapter_name.hash
66
+ end
67
+
68
+ def template_directory
69
+ end
70
+
71
+ def self.from_string(adapter_name, data_type = NOT_SET)
72
+ raise NoMethodError unless eql?(DatabaseAdapter)
73
+
74
+ case adapter_name.to_s.downcase
75
+ when "postgresql", "postgis"
76
+ PostgreSQL.new(data_type)
77
+ when "mysql2", "trilogy"
78
+ MySQL.new(data_type)
79
+ when "sqlite"
80
+ SQLite.new(data_type)
81
+ else
82
+ raise UnsupportedAdapter, "Unsupported adapter: #{adapter_name.inspect}"
83
+ end
84
+ end
85
+
86
+ private
87
+
88
+ def validate_data_type!(data_type)
89
+ if !data_type.eql?(NOT_SET) && !supported_data_types.include?(data_type)
90
+ raise InvalidDataTypeForAdapter,
91
+ "#{class_name} doesn't support #{data_type.inspect}. Supported types are: #{supported_data_types.join(", ")}."
92
+ end
93
+ end
94
+
95
+ def class_name
96
+ self.class.name.split("::").last
97
+ end
98
+ end
99
+ end
100
+ end
@@ -0,0 +1,61 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RubyEventStore
4
+ module ActiveRecord
5
+ class ForeignKeyOnEventIdMigrationGenerator
6
+ def call(database_adapter_name, migration_path)
7
+ database_adapter = DatabaseAdapter.from_string(database_adapter_name)
8
+ each_migration(database_adapter) do |migration_name|
9
+ path = build_path(migration_path, migration_name)
10
+ write_to_file(path, migration_code(database_adapter, migration_name))
11
+ end
12
+ end
13
+
14
+ private
15
+
16
+ def each_migration(database_adapter, &block)
17
+ case database_adapter
18
+ when DatabaseAdapter::PostgreSQL
19
+ [
20
+ 'add_foreign_key_on_event_id_to_event_store_events_in_streams',
21
+ 'validate_add_foreign_key_on_event_id_to_event_store_events_in_streams'
22
+ ]
23
+ else
24
+ ['add_foreign_key_on_event_id_to_event_store_events_in_streams']
25
+ end.each(&block)
26
+ end
27
+
28
+ def absolute_path(path)
29
+ File.expand_path(path, __dir__)
30
+ end
31
+
32
+ def migration_code(database_adapter, migration_name)
33
+ migration_template(template_root(database_adapter), migration_name).result_with_hash(migration_version: migration_version)
34
+ end
35
+
36
+ def migration_template(template_root, name)
37
+ ERB.new(File.read(File.join(template_root, "#{name}_template.erb")))
38
+ end
39
+
40
+ def template_root(database_adapter)
41
+ absolute_path("./templates/#{database_adapter.template_directory}")
42
+ end
43
+
44
+ def migration_version
45
+ ::ActiveRecord::Migration.current_version
46
+ end
47
+
48
+ def timestamp
49
+ Time.now.strftime("%Y%m%d%H%M%S")
50
+ end
51
+
52
+ def write_to_file(path, migration_code)
53
+ File.write(path, migration_code)
54
+ end
55
+
56
+ def build_path(migration_path, migration_name)
57
+ File.join("#{migration_path}", "#{timestamp}_#{migration_name}.rb")
58
+ end
59
+ end
60
+ end
61
+ end
@@ -4,13 +4,8 @@ require "erb"
4
4
  module RubyEventStore
5
5
  module ActiveRecord
6
6
  class MigrationGenerator
7
- DATA_TYPES = %w[binary json jsonb].freeze
8
-
9
- def call(data_type, database_adapter, migration_path)
10
- raise ArgumentError, "Invalid value for data type. Supported for options are: #{DATA_TYPES.join(", ")}." unless DATA_TYPES.include?(data_type)
11
- VerifyDataTypeForAdapter.new.call(database_adapter, data_type)
12
-
13
- migration_code = migration_code(data_type, database_adapter)
7
+ def call(database_adapter, migration_path)
8
+ migration_code = migration_code(database_adapter)
14
9
  path = build_path(migration_path)
15
10
  write_to_file(migration_code, path)
16
11
  path
@@ -22,16 +17,12 @@ module RubyEventStore
22
17
  File.expand_path(path, __dir__)
23
18
  end
24
19
 
25
- def migration_code(data_type, database_adapter)
26
- migration_template(template_root(database_adapter), "create_event_store_events").result_with_hash(migration_version: migration_version, data_type: data_type)
20
+ def migration_code(database_adapter)
21
+ migration_template(template_root(database_adapter), "create_event_store_events").result_with_hash(migration_version: migration_version, data_type: database_adapter.data_type)
27
22
  end
28
23
 
29
24
  def template_root(database_adapter)
30
- absolute_path("./templates/#{template_directory(database_adapter)}")
31
- end
32
-
33
- def template_directory(database_adapter)
34
- TemplateDirectory.for_adapter(database_adapter)
25
+ absolute_path("./templates/#{database_adapter.template_directory}")
35
26
  end
36
27
 
37
28
  def migration_template(template_root, name)
@@ -0,0 +1,56 @@
1
+ # frozen_string_literal: true
2
+
3
+ begin
4
+ require "rails/generators"
5
+ rescue LoadError
6
+ end
7
+
8
+ if defined?(Rails::Generators::Base)
9
+ module RubyEventStore
10
+ module ActiveRecord
11
+ class RailsForeignKeyOnEventIdMigrationGenerator < Rails::Generators::Base
12
+ class Error < Thor::Error
13
+ end
14
+
15
+ namespace "rails_event_store_active_record:migration_for_foreign_key_on_event_id"
16
+
17
+ source_root File.expand_path(File.join(File.dirname(__FILE__), "../generators/templates"))
18
+
19
+ def initialize(*args)
20
+ super
21
+
22
+ @database_adapter = DatabaseAdapter.from_string(adapter_name)
23
+ rescue UnsupportedAdapter => e
24
+ raise Error, e.message
25
+ end
26
+
27
+ def create_migration
28
+ case @database_adapter
29
+ when DatabaseAdapter::PostgreSQL
30
+ template "#{@database_adapter.template_directory}add_foreign_key_on_event_id_to_event_store_events_in_streams_template.erb",
31
+ "db/migrate/#{timestamp}_add_foreign_key_on_event_id_to_event_store_events_in_streams.rb"
32
+ template "#{@database_adapter.template_directory}validate_add_foreign_key_on_event_id_to_event_store_events_in_streams_template.erb",
33
+ "db/migrate/#{timestamp}_validate_add_foreign_key_on_event_id_to_event_store_events_in_streams.rb"
34
+ else
35
+ template "#{@database_adapter.template_directory}add_foreign_key_on_event_id_to_event_store_events_in_streams_template.erb",
36
+ "db/migrate/#{timestamp}_add_foreign_key_on_event_id_to_event_store_events_in_streams.rb"
37
+ end
38
+ end
39
+
40
+ private
41
+
42
+ def adapter_name
43
+ ::ActiveRecord::Base.connection.adapter_name
44
+ end
45
+
46
+ def migration_version
47
+ ::ActiveRecord::Migration.current_version
48
+ end
49
+
50
+ def timestamp
51
+ Time.now.strftime("%Y%m%d%H%M%S")
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
@@ -11,8 +11,6 @@ module RubyEventStore
11
11
  class Error < Thor::Error
12
12
  end
13
13
 
14
- DATA_TYPES = %w[binary json jsonb].freeze
15
-
16
14
  namespace "rails_event_store_active_record:migration"
17
15
 
18
16
  source_root File.expand_path(File.join(File.dirname(__FILE__), "../generators/templates"))
@@ -21,37 +19,33 @@ module RubyEventStore
21
19
  type: :string,
22
20
  default: "binary",
23
21
  desc:
24
- "Configure the data type for `data` and `meta data` fields in Postgres migration (options: #{DATA_TYPES.join("/")})"
22
+ "Configure the data type for `data` and `meta data` fields in migration (options: #{DatabaseAdapter::PostgreSQL.new.supported_data_types.join(", ")})"
25
23
  )
26
24
 
27
25
  def initialize(*args)
28
26
  super
29
27
 
30
- if DATA_TYPES.exclude?(data_type)
31
- raise Error, "Invalid value for --data-type option. Supported for options are: #{DATA_TYPES.join(", ")}."
32
- end
33
-
34
- VerifyDataTypeForAdapter.new.call(adapter, data_type)
35
- rescue InvalidDataTypeForAdapter, UnsupportedAdapter => e
28
+ @database_adapter = DatabaseAdapter.from_string(adapter_name, data_type)
29
+ rescue UnsupportedAdapter => e
36
30
  raise Error, e.message
31
+ rescue InvalidDataTypeForAdapter
32
+ raise Error,
33
+ "Invalid value for --data-type option. Supported for options are: #{DatabaseAdapter.from_string(adapter_name).supported_data_types.join(", ")}."
37
34
  end
38
35
 
39
36
  def create_migration
40
- template "#{template_directory}create_event_store_events_template.erb", "db/migrate/#{timestamp}_create_event_store_events.rb"
37
+ template "#{@database_adapter.template_directory}create_event_store_events_template.erb",
38
+ "db/migrate/#{timestamp}_create_event_store_events.rb"
41
39
  end
42
40
 
43
41
  private
44
42
 
45
- def template_directory
46
- TemplateDirectory.for_adapter(adapter)
47
- end
48
-
49
43
  def data_type
50
44
  options.fetch("data_type")
51
45
  end
52
46
 
53
- def adapter
54
- ::ActiveRecord::Base.connection.adapter_name.downcase
47
+ def adapter_name
48
+ ::ActiveRecord::Base.connection.adapter_name
55
49
  end
56
50
 
57
51
  def migration_version
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ class AddForeginKeyOnEventIdToEventStoreEventsInStreams < ActiveRecord::Migration[<%= migration_version %>]
4
+ def change
5
+ add_foreign_key :event_store_events_in_streams, :event_store_events, column: :event_id, primary_key: :event_id, if_not_exists: true
6
+ end
7
+ end
@@ -20,5 +20,7 @@ class CreateEventStoreEvents < ActiveRecord::Migration[<%= migration_version %>]
20
20
  t.datetime :created_at, null: false, precision: 6, index: true
21
21
  t.datetime :valid_at, null: true, precision: 6, index: true
22
22
  end
23
+
24
+ add_foreign_key "event_store_events_in_streams", "event_store_events", column: "event_id", primary_key: "event_id"
23
25
  end
24
26
  end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ class AddForeginKeyOnEventIdToEventStoreEventsInStreams < ActiveRecord::Migration[<%= migration_version %>]
4
+ def change
5
+ add_foreign_key :event_store_events_in_streams, :event_store_events, column: :event_id, primary_key: :event_id, if_not_exists: true
6
+ end
7
+ end
@@ -20,5 +20,7 @@ class CreateEventStoreEvents < ActiveRecord::Migration[<%= migration_version %>]
20
20
  t.datetime :created_at, null: false, precision: 6, index: true
21
21
  t.datetime :valid_at, null: true, precision: 6, index: true
22
22
  end
23
+
24
+ add_foreign_key "event_store_events_in_streams", "event_store_events", column: "event_id", primary_key: "event_id"
23
25
  end
24
26
  end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ class AddForeginKeyOnEventIdToEventStoreEventsInStreams < ActiveRecord::Migration[<%= migration_version %>]
4
+ def change
5
+ add_foreign_key :event_store_events_in_streams, :event_store_events, column: :event_id, primary_key: :event_id, if_not_exists: true, validate: false
6
+ end
7
+ end
@@ -20,5 +20,7 @@ class CreateEventStoreEvents < ActiveRecord::Migration[<%= migration_version %>]
20
20
  t.datetime :created_at, null: false, type: :timestamp, precision: 6, index: true
21
21
  t.datetime :valid_at, null: true, type: :timestamp, precision: 6, index: true
22
22
  end
23
+
24
+ add_foreign_key "event_store_events_in_streams", "event_store_events", column: "event_id", primary_key: "event_id"
23
25
  end
24
26
  end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ class ValidateAddForeginKeyOnEventIdToEventStoreEventsInStreams < ActiveRecord::Migration[<%= migration_version %>]
4
+ def change
5
+ validate_foreign_key :event_store_events_in_streams, :event_store_events, column: :event_id, primary_key: :event_id
6
+ end
7
+ end
@@ -5,14 +5,11 @@ task "db:migrations:copy" do
5
5
  data_type =
6
6
  ENV["DATA_TYPE"] || raise("Specify data type (binary, json, jsonb): rake db:migrations:copy DATA_TYPE=json")
7
7
  ::ActiveRecord::Base.establish_connection(ENV["DATABASE_URL"])
8
- database_adapter = ::ActiveRecord::Base.connection.adapter_name
8
+ database_adapter =
9
+ RubyEventStore::ActiveRecord::DatabaseAdapter.from_string(::ActiveRecord::Base.connection.adapter_name, data_type)
9
10
 
10
11
  path =
11
- RubyEventStore::ActiveRecord::MigrationGenerator.new.call(
12
- data_type,
13
- database_adapter,
14
- ENV["MIGRATION_PATH"] || "db/migrate"
15
- )
12
+ RubyEventStore::ActiveRecord::MigrationGenerator.new.call(database_adapter, ENV["MIGRATION_PATH"] || "db/migrate")
16
13
 
17
14
  puts "Migration file created #{path}"
18
15
  end
@@ -25,3 +22,13 @@ task "db:migrations:fix_missing_event_id_index" do
25
22
 
26
23
  puts "Migration file created #{path}"
27
24
  end
25
+
26
+ desc "Generate migration for adding foreign key on event_store_events_in_streams.event_id"
27
+ task "db:migrations:add_foreign_key_on_event_id" do
28
+ ::ActiveRecord::Base.establish_connection(ENV["DATABASE_URL"])
29
+
30
+ path =
31
+ RubyEventStore::ActiveRecord::ForeignKeyOnEventIdMigrationGenerator.new.call(ENV["MIGRATION_PATH"] || "db/migrate")
32
+
33
+ puts "Migration file created #{path}"
34
+ end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module RubyEventStore
4
4
  module ActiveRecord
5
- VERSION = "2.11.1"
5
+ VERSION = "2.12.0"
6
6
  end
7
7
  end
@@ -1,11 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative "active_record/generators/database_adapter"
3
4
  require_relative "active_record/generators/migration_generator"
4
5
  require_relative "active_record/generators/rails_migration_generator"
5
- require_relative "active_record/generators/templates/template_directory"
6
- require_relative "active_record/generators/verify_data_type_for_adapter"
7
6
  require_relative "active_record/generators/event_id_index_migration_generator"
8
7
  require_relative "active_record/generators/rails_event_id_index_migration_generator"
8
+ require_relative "active_record/generators/foreign_key_on_event_id_migration_generator"
9
+ require_relative "active_record/generators/rails_foreign_key_on_event_id_migration_generator"
9
10
  require_relative "active_record/event"
10
11
  require_relative "active_record/with_default_models"
11
12
  require_relative "active_record/with_abstract_base_class"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby_event_store-active_record
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.11.1
4
+ version: 2.12.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Arkency
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-07-24 00:00:00.000000000 Z
11
+ date: 2023-09-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ruby_event_store
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - '='
18
18
  - !ruby/object:Gem::Version
19
- version: 2.11.1
19
+ version: 2.12.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - '='
25
25
  - !ruby/object:Gem::Version
26
- version: 2.11.1
26
+ version: 2.12.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: activerecord
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -57,16 +57,21 @@ files:
57
57
  - lib/ruby_event_store/active_record/event.rb
58
58
  - lib/ruby_event_store/active_record/event_repository.rb
59
59
  - lib/ruby_event_store/active_record/event_repository_reader.rb
60
+ - lib/ruby_event_store/active_record/generators/database_adapter.rb
60
61
  - lib/ruby_event_store/active_record/generators/event_id_index_migration_generator.rb
62
+ - lib/ruby_event_store/active_record/generators/foreign_key_on_event_id_migration_generator.rb
61
63
  - lib/ruby_event_store/active_record/generators/migration_generator.rb
62
64
  - lib/ruby_event_store/active_record/generators/rails_event_id_index_migration_generator.rb
65
+ - lib/ruby_event_store/active_record/generators/rails_foreign_key_on_event_id_migration_generator.rb
63
66
  - lib/ruby_event_store/active_record/generators/rails_migration_generator.rb
64
67
  - lib/ruby_event_store/active_record/generators/templates/add_event_id_index_to_event_store_events_in_streams_template.erb
68
+ - lib/ruby_event_store/active_record/generators/templates/add_foreign_key_on_event_id_to_event_store_events_in_streams_template.erb
65
69
  - lib/ruby_event_store/active_record/generators/templates/create_event_store_events_template.erb
70
+ - lib/ruby_event_store/active_record/generators/templates/mysql/add_foreign_key_on_event_id_to_event_store_events_in_streams_template.erb
66
71
  - lib/ruby_event_store/active_record/generators/templates/mysql/create_event_store_events_template.erb
72
+ - lib/ruby_event_store/active_record/generators/templates/postgres/add_foreign_key_on_event_id_to_event_store_events_in_streams_template.erb
67
73
  - lib/ruby_event_store/active_record/generators/templates/postgres/create_event_store_events_template.erb
68
- - lib/ruby_event_store/active_record/generators/templates/template_directory.rb
69
- - lib/ruby_event_store/active_record/generators/verify_data_type_for_adapter.rb
74
+ - lib/ruby_event_store/active_record/generators/templates/postgres/validate_add_foreign_key_on_event_id_to_event_store_events_in_streams_template.erb
70
75
  - lib/ruby_event_store/active_record/index_violation_detector.rb
71
76
  - lib/ruby_event_store/active_record/pg_linearized_event_repository.rb
72
77
  - lib/ruby_event_store/active_record/railtie.rb
@@ -1,16 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module RubyEventStore
4
- module ActiveRecord
5
- class TemplateDirectory
6
- def self.for_adapter(database_adapter)
7
- case database_adapter.downcase
8
- when "postgresql"
9
- "postgres/"
10
- when "mysql2"
11
- "mysql/"
12
- end
13
- end
14
- end
15
- end
16
- end
@@ -1,45 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module RubyEventStore
4
- module ActiveRecord
5
- InvalidDataTypeForAdapter = Class.new(StandardError)
6
- UnsupportedAdapter = Class.new(StandardError)
7
-
8
- class VerifyDataTypeForAdapter
9
- SUPPORTED_POSTGRES_DATA_TYPES = %w[binary json jsonb].freeze
10
- SUPPORTED_MYSQL_DATA_TYPES = %w[binary json].freeze
11
- SUPPORTED_SQLITE_DATA_TYPES = %w[binary].freeze
12
-
13
- def call(adapter, data_type)
14
- raise UnsupportedAdapter, "Unsupported adapter" unless supported?(adapter)
15
- raise InvalidDataTypeForAdapter, "MySQL2 doesn't support #{data_type}" if is_mysql2?(adapter) && !SUPPORTED_MYSQL_DATA_TYPES.include?(data_type)
16
- raise InvalidDataTypeForAdapter, "sqlite doesn't support #{data_type}" if is_sqlite?(adapter) && supported_by_sqlite?(data_type)
17
- raise InvalidDataTypeForAdapter, "PostgreSQL doesn't support #{data_type}" unless supported_by_postgres?(data_type)
18
- end
19
-
20
- private
21
-
22
- private_constant :SUPPORTED_POSTGRES_DATA_TYPES, :SUPPORTED_MYSQL_DATA_TYPES, :SUPPORTED_SQLITE_DATA_TYPES
23
-
24
- def supported?(adapter)
25
- %w[mysql2 postgresql sqlite].include?(adapter.downcase)
26
- end
27
-
28
- def is_sqlite?(adapter)
29
- adapter.downcase.eql?("sqlite")
30
- end
31
-
32
- def is_mysql2?(adapter)
33
- adapter.downcase.eql?("mysql2")
34
- end
35
-
36
- def supported_by_sqlite?(data_type)
37
- !SUPPORTED_SQLITE_DATA_TYPES.include?(data_type)
38
- end
39
-
40
- def supported_by_postgres?(data_type)
41
- SUPPORTED_POSTGRES_DATA_TYPES.include?(data_type)
42
- end
43
- end
44
- end
45
- end