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 +4 -4
- data/lib/ruby_event_store/active_record/generators/foreign_key_on_event_id_migration_generator.rb +11 -7
- data/lib/ruby_event_store/active_record/generators/rails_foreign_key_on_event_id_migration_generator.rb +6 -5
- data/lib/ruby_event_store/active_record/generators/templates/add_foreign_key_on_event_id_to_event_store_events_in_streams_template.erb +1 -1
- data/lib/ruby_event_store/active_record/generators/templates/mysql/add_foreign_key_on_event_id_to_event_store_events_in_streams_template.erb +1 -1
- data/lib/ruby_event_store/active_record/generators/templates/postgres/add_foreign_key_on_event_id_to_event_store_events_in_streams_template.erb +1 -1
- 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 +1 -1
- data/lib/ruby_event_store/active_record/tasks/migration_tasks.rake +37 -10
- data/lib/ruby_event_store/active_record/version.rb +1 -1
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c9c93dedba2d77d5d9a3b8d72346baae945137d0a454435533114cbc7a12dfe8
|
4
|
+
data.tar.gz: 6a2c214fd8433e874b25f29e5a34ebd7ddc58fe2b0368573bba94bdd919b2f9f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 723e4cf7240697d8615a65fd2af425650df2b61274857e49665c82a4cf7d8916a904bb7ce3d9f0126955c7da96e43d2f3518e0ed2025170df14cccdde18487c2
|
7
|
+
data.tar.gz: 6ed6cafb966c3a2d60df79fdf4a192f39d32f2425375b5b23c6a51166482663dcf554d16f5e9cf24d227d784242495fba68679419fdb3597d7a859f9c5207fec
|
data/lib/ruby_event_store/active_record/generators/foreign_key_on_event_id_migration_generator.rb
CHANGED
@@ -3,10 +3,10 @@
|
|
3
3
|
module RubyEventStore
|
4
4
|
module ActiveRecord
|
5
5
|
class ForeignKeyOnEventIdMigrationGenerator
|
6
|
-
def call(
|
7
|
-
|
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}", "#{
|
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/#{
|
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/#{
|
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/#{
|
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
|
51
|
-
|
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
|
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
|
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
|
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
|
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
|
-
|
6
|
-
|
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(
|
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
|
-
|
16
|
+
task = MigrationTask.new("db:migrations:fix_missing_event_id_index")
|
17
|
+
task.establish_connection
|
20
18
|
|
21
|
-
path = RubyEventStore::ActiveRecord::EventIdIndexMigrationGenerator.new.call(
|
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
|
-
|
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(
|
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
|
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.
|
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-
|
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.
|
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.
|
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.
|
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
|