pg_logical_replicator 0.1.5 → 0.1.6

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: 2aab5bea887e74a1be5a02da58eb98b525c7ce3c786c7943136332f1b953c203
4
- data.tar.gz: 201bed281909128a3bf8569360eb30f2d8d85601d9696207fd31919df5a45155
3
+ metadata.gz: d85998326734611fffa7a261b4da9e7aaa23cb0fc8e460c3e2e10206e8c2012d
4
+ data.tar.gz: 375f48b3a024bdcedb8a10c2752c60ea8d4acc5305dc0123d6ab993f6da5d185
5
5
  SHA512:
6
- metadata.gz: 0d41c1e2e0e75e51ed0dccaeffd47efdb6fd7900c720ab0203e9ac7a2c0247b3d73071b3ae91fff3d29b4b9fd3b32b1598cf7be3dfa3c59248ee75c4e685f4a7
7
- data.tar.gz: 9bfa6c1923a933b4ac6d5c8c094da0de2a2230cea61b4d1957f38ecfc9ea8916afe1a4619e32f8abe4711ecd165dfdc833007546644397440a0656f04c1aba36
6
+ metadata.gz: 387f5aa4609c1d69f11eb996fe4ee64890178ced6b7fb9a1f53eaad0233f9050c941362dc51c1b73e7d1133bef7058898ad1375b6550553048a011d224a27eb9
7
+ data.tar.gz: a3a0fe506552ecd598d4a31f7958d24ea6f257fe3e073136143b3252ea24a16c57d7e517577a7221c6e994704a4b4947c58fb7ad6b1de979fd36e6906348cd43
@@ -19,7 +19,7 @@ module PgLogicalReplicator
19
19
  method_option :target_rep_password, type: :string
20
20
  method_option :num_slots, type: :numeric, default: 10
21
21
  method_option :groups, type: :array
22
-
22
+
23
23
  def setup
24
24
  source_host = options[:source_host]
25
25
  source_port = options[:source_port]
@@ -35,11 +35,11 @@ module PgLogicalReplicator
35
35
  target_rep_password = options[:target_rep_password] || target_password
36
36
  num_slots = options[:num_slots]
37
37
  target_groups = options[:groups].map(&:to_i) if options[:groups]
38
-
38
+
39
39
  conn = PG.connect(dbname: source_database, user: source_username, password: source_password, host: source_host, port: source_port)
40
-
40
+
41
41
  query = "SELECT tablename FROM pg_tables WHERE schemaname = 'public' order by tablename ASC;"
42
-
42
+
43
43
  tables = begin
44
44
  result = conn.exec(query)
45
45
  result.map { |row| row['tablename'] }
@@ -47,33 +47,33 @@ module PgLogicalReplicator
47
47
  conn.close if conn
48
48
  end
49
49
  puts "Total Tables: #{tables.size}"
50
-
50
+
51
51
  tables_per_group = tables.size / num_slots
52
52
  puts "Tables per group: #{tables_per_group}"
53
-
53
+
54
54
  dump_dir_root = "~/db-dumps-#{Time.now.strftime('%Y%m%d%H%M%S')}"
55
55
  system("mkdir -p #{dump_dir_root}")
56
-
56
+
57
57
  puts "Target Groups: #{target_groups}"
58
-
58
+
59
59
  tables.each_slice(tables_per_group).with_index do |table_group, group_idx|
60
60
  puts "Processing group #{group_idx + 1} size: #{table_group.size}"
61
-
61
+
62
62
  group_number = group_idx + 1
63
-
63
+
64
64
  next unless target_groups.nil? || target_groups.include?(group_number)
65
-
65
+
66
66
  table_names = table_group.join(',')
67
-
67
+
68
68
  dump_dir = "#{dump_dir_root}/#{group_number}"
69
-
69
+
70
70
  puts "Removing directory: #{dump_dir}"
71
-
71
+
72
72
  FileUtils.rm_rf(dump_dir)
73
-
73
+
74
74
  puts "Creating directory: #{dump_dir}"
75
75
  FileUtils.mkdir_p(dump_dir)
76
-
76
+
77
77
  LogicalReplicationInitializer.new({
78
78
  slot_name: "logical_sub_grp_#{group_number}",
79
79
  publication_name: "logical_pub_grp_#{group_number}",
@@ -83,9 +83,13 @@ module PgLogicalReplicator
83
83
  table_names: table_names,
84
84
  dump_dir: dump_dir
85
85
  }).start
86
+ rescue StandardError => e
87
+ puts "Error: #{e.message}"
88
+ ensure
89
+ FileUtils.rm_rf(dump_dir)
86
90
  end
87
91
  end
88
-
92
+
89
93
  desc 'stop_replication', 'Stop all replication'
90
94
  method_option :source_host, type: :string, required: true
91
95
  method_option :source_port, type: :numeric, default: 5432
@@ -97,7 +101,7 @@ module PgLogicalReplicator
97
101
  method_option :source_password, type: :string, required: true
98
102
  method_option :target_username, type: :string
99
103
  method_option :target_password, type: :string
100
-
104
+
101
105
  def stop_replication
102
106
  source_config = {
103
107
  host: options[:source_host],
@@ -106,7 +110,7 @@ module PgLogicalReplicator
106
110
  user: options[:source_username],
107
111
  password: options[:source_password]
108
112
  }
109
-
113
+
110
114
  target_config = {
111
115
  host: options[:target_host],
112
116
  port: options[:target_port],
@@ -114,10 +118,10 @@ module PgLogicalReplicator
114
118
  user: options[:target_username] || options[:source_username],
115
119
  password: options[:target_password] || options[:source_password]
116
120
  }
117
-
121
+
118
122
  ReplicationStopper.new(source_config, target_config).stop_replication
119
123
  end
120
-
124
+
121
125
  desc 'transfer_schema', 'Transfer schema from source to target database'
122
126
  method_option :source_host, type: :string, required: true
123
127
  method_option :source_port, type: :numeric, default: 5432
@@ -129,7 +133,7 @@ module PgLogicalReplicator
129
133
  method_option :source_password, type: :string, required: true
130
134
  method_option :target_username, type: :string, required: true
131
135
  method_option :target_password, type: :string, required: true
132
-
136
+
133
137
  def transfer_schema
134
138
  SchemaTransfer.new(
135
139
  source_host: options[:source_host],
@@ -1,3 +1,3 @@
1
1
  module PgLogicalReplicator
2
- VERSION = "0.1.5"
2
+ VERSION = "0.1.6"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pg_logical_replicator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - eni9889
@@ -118,7 +118,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
118
118
  - !ruby/object:Gem::Version
119
119
  version: '0'
120
120
  requirements: []
121
- rubygems_version: 3.0.3.1
121
+ rubygems_version: 3.4.10
122
122
  signing_key:
123
123
  specification_version: 4
124
124
  summary: PostgreSQL logical replication setup tool