ruby_event_store-active_record 2.12.0 → 2.12.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9987cdb6acdbe0954d31ef08815daeea9cf3bab6b0069bf5e03e2a60463bf13e
4
- data.tar.gz: bd8b1464de23ef8cc10e256ff90eee0c1851010cd23634f7484e1a1e9dc9544d
3
+ metadata.gz: c9c93dedba2d77d5d9a3b8d72346baae945137d0a454435533114cbc7a12dfe8
4
+ data.tar.gz: 6a2c214fd8433e874b25f29e5a34ebd7ddc58fe2b0368573bba94bdd919b2f9f
5
5
  SHA512:
6
- metadata.gz: 61ceca1ee73adec8f023606dda0afb08f3b00f0bfe09be545ef909b093a71467a097ee2f2cf28224552e4b1c724d9eb23c8dd7b121c2925afc67861b5fccadb6
7
- data.tar.gz: 657b3186c572ed9f0e457640f1e5721b01e089aa330edc6886dac2fddd86c8f92b23a62d7a7f0dbf857c0daba9b987843c3997ea413a766fff9984d04ebfecb0
6
+ metadata.gz: 723e4cf7240697d8615a65fd2af425650df2b61274857e49665c82a4cf7d8916a904bb7ce3d9f0126955c7da96e43d2f3518e0ed2025170df14cccdde18487c2
7
+ data.tar.gz: 6ed6cafb966c3a2d60df79fdf4a192f39d32f2425375b5b23c6a51166482663dcf554d16f5e9cf24d227d784242495fba68679419fdb3597d7a859f9c5207fec
@@ -3,10 +3,10 @@
3
3
  module RubyEventStore
4
4
  module ActiveRecord
5
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)
6
+ def call(database_adapter, migration_path)
7
+ time = Time.now
8
+ each_migration(database_adapter) do |migration_name, i|
9
+ path = build_path(migration_path, migration_name, time + i)
10
10
  write_to_file(path, migration_code(database_adapter, migration_name))
11
11
  end
12
12
  end
@@ -22,7 +22,7 @@ module RubyEventStore
22
22
  ]
23
23
  else
24
24
  ['add_foreign_key_on_event_id_to_event_store_events_in_streams']
25
- end.each(&block)
25
+ end.each.with_index(&block)
26
26
  end
27
27
 
28
28
  def absolute_path(path)
@@ -53,8 +53,12 @@ module RubyEventStore
53
53
  File.write(path, migration_code)
54
54
  end
55
55
 
56
- def build_path(migration_path, migration_name)
57
- File.join("#{migration_path}", "#{timestamp}_#{migration_name}.rb")
56
+ def build_path(migration_path, migration_name, time)
57
+ File.join("#{migration_path}", "#{migration_verion_number(time)}_#{migration_name}.rb")
58
+ end
59
+
60
+ def migration_verion_number(time)
61
+ time.strftime("%Y%m%d%H%M%S")
58
62
  end
59
63
  end
60
64
  end
@@ -27,13 +27,14 @@ if defined?(Rails::Generators::Base)
27
27
  def create_migration
28
28
  case @database_adapter
29
29
  when DatabaseAdapter::PostgreSQL
30
+ time = Time.now
30
31
  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
+ "db/migrate/#{migration_verion_number(time)}_add_foreign_key_on_event_id_to_event_store_events_in_streams.rb"
32
33
  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
+ "db/migrate/#{migration_verion_number(time + 1)}_validate_add_foreign_key_on_event_id_to_event_store_events_in_streams.rb"
34
35
  else
35
36
  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
+ "db/migrate/#{migration_verion_number(Time.now)}_add_foreign_key_on_event_id_to_event_store_events_in_streams.rb"
37
38
  end
38
39
  end
39
40
 
@@ -47,8 +48,8 @@ if defined?(Rails::Generators::Base)
47
48
  ::ActiveRecord::Migration.current_version
48
49
  end
49
50
 
50
- def timestamp
51
- Time.now.strftime("%Y%m%d%H%M%S")
51
+ def migration_verion_number(time)
52
+ time.strftime("%Y%m%d%H%M%S")
52
53
  end
53
54
  end
54
55
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- class AddForeginKeyOnEventIdToEventStoreEventsInStreams < ActiveRecord::Migration[<%= migration_version %>]
3
+ class AddForeignKeyOnEventIdToEventStoreEventsInStreams < ActiveRecord::Migration[<%= migration_version %>]
4
4
  def change
5
5
  add_foreign_key :event_store_events_in_streams, :event_store_events, column: :event_id, primary_key: :event_id, if_not_exists: true
6
6
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- class AddForeginKeyOnEventIdToEventStoreEventsInStreams < ActiveRecord::Migration[<%= migration_version %>]
3
+ class AddForeignKeyOnEventIdToEventStoreEventsInStreams < ActiveRecord::Migration[<%= migration_version %>]
4
4
  def change
5
5
  add_foreign_key :event_store_events_in_streams, :event_store_events, column: :event_id, primary_key: :event_id, if_not_exists: true
6
6
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- class AddForeginKeyOnEventIdToEventStoreEventsInStreams < ActiveRecord::Migration[<%= migration_version %>]
3
+ class AddForeignKeyOnEventIdToEventStoreEventsInStreams < ActiveRecord::Migration[<%= migration_version %>]
4
4
  def change
5
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
6
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- class ValidateAddForeginKeyOnEventIdToEventStoreEventsInStreams < ActiveRecord::Migration[<%= migration_version %>]
3
+ class ValidateAddForeignKeyOnEventIdToEventStoreEventsInStreams < ActiveRecord::Migration[<%= migration_version %>]
4
4
  def change
5
5
  validate_foreign_key :event_store_events_in_streams, :event_store_events, column: :event_id, primary_key: :event_id
6
6
  end
@@ -2,33 +2,60 @@ require_relative "../generators/migration_generator"
2
2
 
3
3
  desc "Generate migration"
4
4
  task "db:migrations:copy" do
5
- data_type =
6
- ENV["DATA_TYPE"] || raise("Specify data type (binary, json, jsonb): rake db:migrations:copy DATA_TYPE=json")
7
- ::ActiveRecord::Base.establish_connection(ENV["DATABASE_URL"])
8
- database_adapter =
9
- RubyEventStore::ActiveRecord::DatabaseAdapter.from_string(::ActiveRecord::Base.connection.adapter_name, data_type)
5
+ task = MigrationTask.new("db:migrations:copy")
6
+ task.establish_connection
10
7
 
11
8
  path =
12
- RubyEventStore::ActiveRecord::MigrationGenerator.new.call(database_adapter, ENV["MIGRATION_PATH"] || "db/migrate")
9
+ RubyEventStore::ActiveRecord::MigrationGenerator.new.call(task.adapter, task.migration_path)
13
10
 
14
11
  puts "Migration file created #{path}"
15
12
  end
16
13
 
17
14
  desc "Generate migration for missing event_id index"
18
15
  task "db:migrations:fix_missing_event_id_index" do
19
- ::ActiveRecord::Base.establish_connection(ENV["DATABASE_URL"])
16
+ task = MigrationTask.new("db:migrations:fix_missing_event_id_index")
17
+ task.establish_connection
20
18
 
21
- path = RubyEventStore::ActiveRecord::EventIdIndexMigrationGenerator.new.call(ENV["MIGRATION_PATH"] || "db/migrate")
19
+ path = RubyEventStore::ActiveRecord::EventIdIndexMigrationGenerator.new.call(task.migration_path)
22
20
 
23
21
  puts "Migration file created #{path}"
24
22
  end
25
23
 
26
24
  desc "Generate migration for adding foreign key on event_store_events_in_streams.event_id"
27
25
  task "db:migrations:add_foreign_key_on_event_id" do
28
- ::ActiveRecord::Base.establish_connection(ENV["DATABASE_URL"])
26
+ task = MigrationTask.new("db:migrations:add_foreign_key_on_event_id")
27
+ task.establish_connection
29
28
 
30
29
  path =
31
- RubyEventStore::ActiveRecord::ForeignKeyOnEventIdMigrationGenerator.new.call(ENV["MIGRATION_PATH"] || "db/migrate")
30
+ RubyEventStore::ActiveRecord::ForeignKeyOnEventIdMigrationGenerator.new.call(task.adapter, task.migration_path)
32
31
 
33
32
  puts "Migration file created #{path}"
34
33
  end
34
+
35
+ class MigrationTask
36
+ def initialize(
37
+ task,
38
+ database_url: ENV["DATABASE_URL"],
39
+ data_type: ENV["DATA_TYPE"],
40
+ migration_path: ENV["MIGRATION_PATH"]
41
+ )
42
+ @task = task
43
+ @data_type = data_type
44
+ @migration_path = migration_path
45
+ @database_url = database_url
46
+ end
47
+
48
+ def establish_connection
49
+ ::ActiveRecord::Base.establish_connection(@database_url)
50
+ end
51
+
52
+ def adapter
53
+ data_type = @data_type || raise("Specify data type (binary, json, jsonb): rake #{@task} DATA_TYPE=json")
54
+
55
+ RubyEventStore::ActiveRecord::DatabaseAdapter.from_string(::ActiveRecord::Base.connection.adapter_name, data_type)
56
+ end
57
+
58
+ def migration_path
59
+ @migration_path || "db/migrate"
60
+ end
61
+ end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module RubyEventStore
4
4
  module ActiveRecord
5
- VERSION = "2.12.0"
5
+ VERSION = "2.12.1"
6
6
  end
7
7
  end
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.12.0
4
+ version: 2.12.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Arkency
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-09-04 00:00:00.000000000 Z
11
+ date: 2023-09-05 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.12.0
19
+ version: 2.12.1
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.12.0
26
+ version: 2.12.1
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: activerecord
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -104,7 +104,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
104
104
  - !ruby/object:Gem::Version
105
105
  version: '0'
106
106
  requirements: []
107
- rubygems_version: 3.4.17
107
+ rubygems_version: 3.3.7
108
108
  signing_key:
109
109
  specification_version: 4
110
110
  summary: Persistent event repository implementation for RubyEventStore based on ActiveRecord