phobos_db_checkpoint 2.2.0 → 2.3.0

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
  SHA1:
3
- metadata.gz: 13a63376197697c40c39c9bdf591800eb664e94a
4
- data.tar.gz: 6eb6a3c254683519a39a0170ae17f640109c97fd
3
+ metadata.gz: bded9e44c71ab913e667bd410909c32349a80d95
4
+ data.tar.gz: bbe38ca65038fd8fe9c768d6b5a2342b6498cf8d
5
5
  SHA512:
6
- metadata.gz: e19cdd1f43137d43ca368bbcdeb5fe3681d9ab77fc0a17e679e0472e7c042ed1e29fbdccf2c9f5694d70922987c04ecaddad77135caa37ae421e06040b5ebebe
7
- data.tar.gz: e0db0427dec26307dde803eb362c13a47088e706947b9ec4ac20e95d867939482cd17ad2e0ac87951a2e4082887ec2153dc5bde694bc99df27337efc61844852
6
+ metadata.gz: dc3d96c808dfaabd944eeb5851dd57b5e62bf386f78897d885df524d908e3d94cf9bb72999e93899571043d804338737b95d5acbb9503d3e318c438c1f441e2d
7
+ data.tar.gz: 5a2d60b0c1e9ef12eb57072f0013b0af5e74eac4a32a64fb75018abd302ecfda0b62a95d56b1dded8456f7263694186e72d38de66316b37a900141af0d986028
@@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
4
4
  The format is based on [Keep a Changelog](http://keepachangelog.com/)
5
5
  and this project adheres to [Semantic Versioning](http://semver.org/).
6
6
 
7
+ ## 2.3.0 (2017-03-08)
8
+
9
+ - [enhancement] Add created_at to events table
10
+
7
11
  ## 2.2.0 (2017-03-08)
8
12
 
9
13
  - [enhancement] Add delete failure end point
data/README.md CHANGED
@@ -299,6 +299,10 @@ The following payload is included for all notifications:
299
299
 
300
300
  ## <a name="upgrading"></a> Upgrading
301
301
 
302
+ #### From 2.2.0 >= _version_ >= 2.0.0 to 2.3.0
303
+
304
+ The database table for Event has had created_at added to it, run `phobos_db_checkpoint copy-migrations` in your project to receive the migration.
305
+
302
306
  #### From <2.0 to 2.x
303
307
 
304
308
  ##### Rename database tables
@@ -34,23 +34,35 @@ module PhobosDBCheckpoint
34
34
  aliases: ['-d'],
35
35
  default: 'db/migrate',
36
36
  banner: 'Destination folder relative to your project'
37
+ option :config,
38
+ aliases: ['-c'],
39
+ default: 'config/database.yml',
40
+ banner: 'Database configuration relative to your project'
37
41
  def copy_migrations
42
+ if options[:config]
43
+ ENV['DB_CONFIG'] = options[:config]
44
+ end
45
+
46
+ unless active_connection?
47
+ PhobosDBCheckpoint.configure(pool_size: 1)
48
+ end
49
+
38
50
  destination_fullpath = File.join(destination_root, options[:destination])
39
51
  generated_migrations = list_migrations(destination_fullpath)
40
52
  FileUtils.mkdir_p(destination_fullpath)
41
-
53
+ file_path = nil
42
54
  template_migrations_metadata.each do |metadata|
43
-
44
55
  if migration_exists?(generated_migrations, metadata[:name])
45
56
  say_status('exists', metadata[:name])
46
-
47
57
  else
48
58
  file_path = File.join(options[:destination], "#{metadata[:number]}_#{metadata[:name]}")
49
59
  template_path = File.join('templates/migrate', metadata[:path])
50
60
  template(template_path, file_path)
51
61
  end
52
-
53
62
  end
63
+ rescue
64
+ FileUtils.rm_f(file_path.to_s)
65
+ raise
54
66
  end
55
67
 
56
68
  desc 'migration NAME', 'Generates a new migration with the given name. Use underlines (_) as a separator, ex: add_new_column'
@@ -117,6 +129,14 @@ module PhobosDBCheckpoint
117
129
  def new_migration_template
118
130
  File.join(self.class.source_root, 'templates/new_migration.rb.erb')
119
131
  end
132
+
133
+ def active_connection?
134
+ ActiveRecord::Base
135
+ .connection_pool
136
+ .with_connection { |con| con.active? }
137
+ rescue
138
+ false
139
+ end
120
140
  end
121
141
  end
122
142
  end
@@ -3,6 +3,10 @@ module PhobosDBCheckpoint
3
3
  include PhobosDBCheckpoint::EventHelper
4
4
  after_initialize :assign_checksum
5
5
 
6
+ scope :order_by_event_time_and_created_at, -> {
7
+ order('event_time desc nulls last', 'created_at desc nulls last')
8
+ }
9
+
6
10
  def exists?
7
11
  Event.where(topic: topic, group_id: group_id, checksum: checksum).exists?
8
12
  end
@@ -75,7 +75,7 @@ module PhobosDBCheckpoint
75
75
  query = query.where(event_type: params['event_type']) if params['event_type']
76
76
 
77
77
  query
78
- .order(event_time: :desc)
78
+ .order_by_event_time_and_created_at
79
79
  .limit(limit)
80
80
  .offset(offset)
81
81
  .to_json
@@ -94,7 +94,7 @@ module PhobosDBCheckpoint
94
94
  query = query.where(event_type: params['event_type']) if params['event_type']
95
95
 
96
96
  query
97
- .order(event_time: :desc)
97
+ .order_by_event_time_and_created_at
98
98
  .limit(limit)
99
99
  .offset(offset)
100
100
  .to_json
@@ -2,6 +2,10 @@ module PhobosDBCheckpoint
2
2
  class Failure < ActiveRecord::Base
3
3
  include PhobosDBCheckpoint::EventHelper
4
4
 
5
+ scope :order_by_event_time_and_created_at, -> {
6
+ order('event_time desc nulls last', 'created_at desc nulls last')
7
+ }
8
+
5
9
  def self.record(event:, event_metadata:, exception: nil)
6
10
  return if exists?(event_metadata[:checksum])
7
11
 
@@ -17,6 +17,5 @@ module PhobosDBCheckpoint
17
17
  end
18
18
 
19
19
  load 'active_record/railties/databases.rake'
20
-
21
20
  end
22
21
  end
@@ -1,3 +1,3 @@
1
1
  module PhobosDBCheckpoint
2
- VERSION = '2.2.0'
2
+ VERSION = '2.3.0'
3
3
  end
@@ -1,4 +1,4 @@
1
- class Phobos01CreateEvents < ActiveRecord::Migration[<%= ActiveRecord::Migration.current_version %>]
1
+ class Phobos01CreateEvents < ActiveRecord::Migration[<%= ActiveRecord::VERSION::STRING.to_f %>]
2
2
  def up
3
3
  create_table :phobos_db_checkpoint_events do |t|
4
4
  t.string :topic, index: true
@@ -1,7 +1,7 @@
1
- class Phobos02CreateFailures < ActiveRecord::Migration[<%= ActiveRecord::Migration.current_version %>]
1
+ class Phobos02CreateFailures < ActiveRecord::Migration[<%= ActiveRecord::VERSION::STRING.to_f %>]
2
2
  def up
3
3
  create_table :phobos_db_checkpoint_failures do |t|
4
- t.timestamp :created_at, index: false
4
+ t.timestamp :created_at, index: true
5
5
  t.string :topic, index: true
6
6
  t.string :group_id, index: true
7
7
  t.string :entity_id, index: true
@@ -0,0 +1,38 @@
1
+ class Phobos03AddCreatedAtToEvents < ActiveRecord::Migration[<%= ActiveRecord::VERSION::STRING.to_f %>]
2
+ def up
3
+ add_column :phobos_db_checkpoint_events, :created_at, :datetime
4
+
5
+ add_index :phobos_db_checkpoint_events,
6
+ [:event_time],
7
+ name: :phobos_events_event_time_desc_nulls_last_idx,
8
+ order: {event_time: 'desc nulls last'},
9
+ using: :btree
10
+
11
+ add_index :phobos_db_checkpoint_events,
12
+ [:created_at],
13
+ name: :phobos_events_created_at_desc_nulls_last_idx,
14
+ order: {created_at: 'desc nulls last'},
15
+ using: :btree
16
+
17
+ add_index :phobos_db_checkpoint_failures,
18
+ [:event_time],
19
+ name: :phobos_failures_event_time_desc_nulls_last_idx,
20
+ order: {event_time: 'desc nulls last'},
21
+ using: :btree
22
+
23
+ add_index :phobos_db_checkpoint_failures,
24
+ [:created_at],
25
+ name: :phobos_failures_created_at_desc_nulls_last_idx,
26
+ order: {created_at: 'desc nulls last'},
27
+ using: :btree
28
+ end
29
+
30
+ def down
31
+ remove_index :phobos_db_checkpoint_events, name: :phobos_events_event_time_desc_nulls_last_idx
32
+ remove_index :phobos_db_checkpoint_events, name: :phobos_events_created_at_desc_nulls_last_idx
33
+ remove_index :phobos_db_checkpoint_failures, name: :phobos_failures_event_time_desc_nulls_last_idx
34
+ remove_index :phobos_db_checkpoint_failures, name: :phobos_failures_created_at_desc_nulls_last_idx
35
+
36
+ remove_column :phobos_db_checkpoint_events, :created_at
37
+ end
38
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: phobos_db_checkpoint
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.0
4
+ version: 2.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Túlio Ornelas
@@ -13,7 +13,7 @@ authors:
13
13
  autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
- date: 2017-03-08 00:00:00.000000000 Z
16
+ date: 2017-03-09 00:00:00.000000000 Z
17
17
  dependencies:
18
18
  - !ruby/object:Gem::Dependency
19
19
  name: bundler
@@ -269,6 +269,7 @@ files:
269
269
  - templates/database.yml.example
270
270
  - templates/migrate/phobos_01_create_events.rb.erb
271
271
  - templates/migrate/phobos_02_create_failures.rb.erb
272
+ - templates/migrate/phobos_03_add_created_at_to_events.rb.erb
272
273
  - templates/new_migration.rb.erb
273
274
  - templates/phobos_boot.rb
274
275
  homepage: https://github.com/klarna/phobos_db_checkpoint
@@ -292,7 +293,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
292
293
  version: '0'
293
294
  requirements: []
294
295
  rubyforge_project:
295
- rubygems_version: 2.6.8
296
+ rubygems_version: 2.5.1
296
297
  signing_key:
297
298
  specification_version: 4
298
299
  summary: Phobos DB Checkpoint is a plugin to Phobos and is meant as a drop in replacement