alterity 1.0.0 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b468009cfd8631b397ea59fcb1750aada7238d5b8910f6cc492cf4778bdc2fa6
4
- data.tar.gz: 02e17258c42233d8198ad62cf15841d6c3fe78b4b2730f64100e1771693686a1
3
+ metadata.gz: 1e235d55d20337f7ff9bf2b4eed178c3585c4ff682bda637a34339c507644438
4
+ data.tar.gz: b41b2d051afdbb66a42f5ce00e2daff2b8e9b4f8935fa3c9f01e64ab0148d9e4
5
5
  SHA512:
6
- metadata.gz: 8929653022fbcec5f31c5583c619d252547928319276b020021404ad38cdbf2a2fae1861f9748009fcc97f99c0bc7a07f698397d6c8d20d41bbd96251b7a3693
7
- data.tar.gz: ec349e1dfee9361ef937e55fe8911da437fad1c7dfc74446ff7f7ce2608943e0755f238297e5073f8786b2a6a0d9dc71c6785a1b91f1d7b04efe4b4a548a1b46
6
+ metadata.gz: 749cd02d5f7b2b6feb3e5e3b63c52274f701946cc03fd067b51f5c4214d7a2c73fab365ca329323058d1fb7c09999d3c1c7a8608bcb9574faa406bc244ad08cd
7
+ data.tar.gz: a0234815613fe77cf4db1950b8ef72de5c0def70b6abe45394c4efa1d5c7b1154d99454f81d9babcd8f00f58cbdf63edcd2f9cb181c22102e08cbaf7aa15691e
data/lib/alterity.rb CHANGED
@@ -54,6 +54,10 @@ class Alterity
54
54
  def prepare_replicas_dsns_table
55
55
  return if config.replicas_dsns_table.blank?
56
56
 
57
+ dsns = config.replicas_dsns.dup
58
+ # Automatically remove master
59
+ dsns.reject! { |dsn| dsn.split(",").include?("h=#{config.host}") }
60
+
57
61
  database = config.replicas_dsns_database
58
62
  table = "#{database}.#{config.replicas_dsns_table}"
59
63
  connection = ActiveRecord::Base.connection
@@ -67,11 +71,11 @@ class Alterity
67
71
  ) ENGINE=InnoDB
68
72
  SQL
69
73
  connection.execute "TRUNCATE #{table}"
70
- return if config.replicas_dsns.empty?
74
+ return if dsns.empty?
71
75
 
72
76
  connection.execute <<~SQL
73
77
  INSERT INTO #{table} (dsn) VALUES
74
- #{config.replicas_dsns.map { |dsn| "('#{dsn}')" }.join(',')}
78
+ #{dsns.map { |dsn| "('#{dsn}')" }.join(',')}
75
79
  SQL
76
80
  end
77
81
  end
@@ -23,9 +23,6 @@ class Alterity
23
23
  parts = dsn.split(",")
24
24
  # automatically add default port
25
25
  parts << "P=3306" unless parts.any? { |part| part.start_with?("P=") }
26
- # automatically remove master
27
- next if parts.include?("h=#{host}") && parts.include?("P=#{port}")
28
-
29
26
  parts.join(",")
30
27
  end.compact
31
28
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class Alterity
4
- VERSION = "1.0.0"
4
+ VERSION = "1.1.0"
5
5
  end
@@ -15,7 +15,12 @@ Alterity.configure do |config|
15
15
  table: "replicas_dsns",
16
16
  dsns: [
17
17
  "h=host1",
18
- "h=host2"
18
+ "h=host2",
19
+ # we may encounter an app where the replica host is actually pointing to master;
20
+ # pt-osc doesn't deal well with this and will wait forever.
21
+ # So we're testing here that Alterity will detect that this is master (same as config.host),
22
+ # and will not insert it into the `replicas_dsns` table.
23
+ "h=#{ENV['MYSQL_HOST']}"
19
24
  ]
20
25
  )
21
26
  end
@@ -56,7 +56,7 @@ bundle e rails g migration add_color_to_shirts color:string
56
56
 
57
57
  # Test default configuration works as expected
58
58
  bundle e rails db:migrate --trace
59
- rails runner 'Shirt.columns.map(&:name).include?("color") || exit(1)'
59
+ bundle e rails runner 'Shirt.columns.map(&:name).include?("color") || exit(1)'
60
60
 
61
61
  # Now test custom command and replication setup
62
62
  cp ../spec/bin/custom_config.rb config/initializers/alterity.rb
@@ -66,3 +66,6 @@ bundle e rails g migration add_color2_to_shirts color2:string
66
66
  bundle e rails db:migrate --trace
67
67
 
68
68
  ruby ../spec/bin/test_custom_config_result.rb
69
+
70
+ # Also testing what's in replicas_dsns, also checking that master was detected and removed.
71
+ bundle e rails runner 'res=ActiveRecord::Base.connection.execute("select dsn from percona.replicas_dsns").to_a.flatten;p(res); res == ["h=host1,P=3306", "h=host2,P=3306"] || exit(1)'
@@ -2,7 +2,7 @@
2
2
 
3
3
  result = File.read("/tmp/custom_command_result.txt").downcase.strip
4
4
 
5
- expected_result = %({:host=>"127.0.0.1", :port=>nil, :username=>"root", :database=>"alterity_test", :replicas_dsns_database=>"percona", :replicas_dsns_table=>"replicas_dsns", :replicas_dsns=>["h=host1,P=3306", "h=host2,P=3306"]}
5
+ expected_result = %({:host=>"127.0.0.1", :port=>nil, :username=>"root", :database=>"alterity_test", :replicas_dsns_database=>"percona", :replicas_dsns_table=>"replicas_dsns", :replicas_dsns=>["h=host1,P=3306", "h=host2,P=3306", "h=127.0.0.1,P=3306"]}
6
6
  shirts
7
7
  "ADD \\`color2\\` VARCHAR(255)").downcase.strip
8
8
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: alterity
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Maximin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-04-05 00:00:00.000000000 Z
11
+ date: 2021-04-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mysql2