pg_easy_replicate 0.3.0 → 0.3.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: 8b12c7664573414ae5b4421e16c2a4d603a1550abd52cd677fa97c0a3f4187d3
4
- data.tar.gz: 03baf5fa2d60d841475024d8e6a4e822546a5f5180ddcdead5ee33ed89bc472b
3
+ metadata.gz: 846d76c9da382a82b36243070402e2e42d7135c6ccd52a1308b4d4ebdb15e4ca
4
+ data.tar.gz: 159925fe9649bc527a861f4e5eac52102af05542ddfeb8f742e9077a1764fe38
5
5
  SHA512:
6
- metadata.gz: c18024373cdf4313723599eaee6f57d84b99ff52afffbbab3a393bae9e453ba43d300f8ec3424396af12fcbf40de46c92846110777a7a6d4ebb6fe9adae47f5f
7
- data.tar.gz: 8f4e8dc80d25b072b6e44a4e17fc6d367fe27368a9643e4e0cc4a39dd846cd1abf247aedbc6e887b1285293939f967131e0d5254ae53751f584af2e13a72c783
6
+ metadata.gz: 512c5ec0e049476d5e02a549effd6d9032642e59eda2507a6a611fae2dfcb136c1efb8fab58f1dd46b12a38dd758195792424415b97e445ad21cb28737048a2c
7
+ data.tar.gz: c36d0cfaebf53e89b58bbdcd52f8394d67196f912bcaaeb2247122bbb1a431d7b850d6c1355058cb810ea718ec9cb268204b568c36aeca98b90174ed67544714
data/Gemfile.lock CHANGED
@@ -5,7 +5,7 @@ PATH
5
5
  ougai (~> 2.0.0)
6
6
  pg (~> 1.5.3)
7
7
  pg_query (~> 5.1.0)
8
- sequel (>= 5.69, < 5.83)
8
+ sequel (>= 5.69, < 5.84)
9
9
  thor (>= 1.2.2, < 1.4.0)
10
10
 
11
11
  GEM
@@ -94,7 +94,7 @@ GEM
94
94
  rubocop-rspec_rails (2.28.2)
95
95
  rubocop (~> 1.40)
96
96
  ruby-progressbar (1.13.0)
97
- sequel (5.82.0)
97
+ sequel (5.83.1)
98
98
  bigdecimal
99
99
  strscan (3.1.0)
100
100
  syntax_tree (6.2.0)
data/README.md CHANGED
@@ -22,9 +22,14 @@ Battle tested in production at [Tines](https://www.tines.com/) 🚀
22
22
  - [Config Check](#config-check-1)
23
23
  - [Bootstrap](#bootstrap-1)
24
24
  - [Start sync](#start-sync)
25
+ - [DDL Changes Management](#ddl-changes-management)
26
+ - [Listing DDL Changes](#listing-ddl-changes)
27
+ - [Applying DDL Changes](#applying-ddl-changes)
25
28
  - [Stats](#stats)
26
29
  - [Performing switchover](#performing-switchover)
27
30
  - [Replicating single database with custom tables](#replicating-single-database-with-custom-tables)
31
+ - [Exclude tables from replication](#exclude-tables-from-replication)
32
+ - [Cleanup](#cleanup)
28
33
  - [Switchover strategies with minimal downtime](#switchover-strategies-with-minimal-downtime)
29
34
  - [Rolling restart strategy](#rolling-restart-strategy)
30
35
  - [DNS Failover strategy](#dns-failover-strategy)
data/docker-compose.yml CHANGED
@@ -1,7 +1,7 @@
1
1
  version: "3.7"
2
2
  services:
3
3
  source_db:
4
- image: postgres:12
4
+ image: postgres:14
5
5
  ports:
6
6
  - "5432:5432"
7
7
  environment:
@@ -113,7 +113,8 @@ module PgEasyReplicate
113
113
  sanitized_group_name = sanitize_identifier(group_name)
114
114
 
115
115
  full_table_names = tables.map { |table| "#{schema_name}.#{table}" }
116
- puts "full_table_names: #{full_table_names}"
116
+ table_pattern = full_table_names.join("|")
117
+
117
118
  conn.run(<<~SQL)
118
119
  CREATE OR REPLACE FUNCTION #{internal_schema_name}.pger_ddl_trigger_#{sanitized_group_name}() RETURNS event_trigger AS $$
119
120
  DECLARE
@@ -126,12 +127,12 @@ module PgEasyReplicate
126
127
  IF TG_EVENT = 'ddl_command_end' THEN
127
128
  FOR obj IN SELECT * FROM pg_event_trigger_ddl_commands()
128
129
  LOOP
129
- IF obj.object_type = 'table' AND obj.object_identity = ANY(ARRAY['#{full_table_names.join("','")}']) THEN
130
+ IF obj.object_identity ~ '^(#{table_pattern})' THEN
130
131
  INSERT INTO #{internal_schema_name}.#{table_name} (group_name, event_type, object_type, object_identity, ddl_command)
131
132
  VALUES ('#{group_name}', TG_EVENT, obj.object_type, obj.object_identity, ddl_command);
132
133
  ELSIF obj.object_type = 'index' THEN
133
134
  SELECT (regexp_match(ddl_command, 'ON\\s+(\\S+)'))[1] INTO affected_table;
134
- IF affected_table = ANY(ARRAY['#{full_table_names.join("','")}']) THEN
135
+ IF affected_table IN ('#{full_table_names.join("','")}') THEN
135
136
  INSERT INTO #{internal_schema_name}.#{table_name} (group_name, event_type, object_type, object_identity, ddl_command)
136
137
  VALUES ('#{group_name}', TG_EVENT, obj.object_type, obj.object_identity, ddl_command);
137
138
  END IF;
@@ -140,8 +141,7 @@ module PgEasyReplicate
140
141
  ELSIF TG_EVENT = 'sql_drop' THEN
141
142
  FOR obj IN SELECT * FROM pg_event_trigger_dropped_objects()
142
143
  LOOP
143
- IF obj.object_type IN ('table', 'index') AND
144
- (obj.object_identity = ANY(ARRAY['#{full_table_names.join("','")}']) OR
144
+ IF (obj.object_identity = ANY(ARRAY['#{full_table_names.join("','")}']) OR
145
145
  obj.object_identity ~ ('^' || '#{schema_name}' || '\\.(.*?)_.*$'))
146
146
  THEN
147
147
  INSERT INTO #{internal_schema_name}.#{table_name} (group_name, event_type, object_type, object_identity, ddl_command)
@@ -151,9 +151,14 @@ module PgEasyReplicate
151
151
  ELSIF TG_EVENT = 'table_rewrite' THEN
152
152
  FOR obj IN SELECT * FROM pg_event_trigger_table_rewrite_oid()
153
153
  LOOP
154
- IF obj.oid::regclass::text = ANY(ARRAY['#{full_table_names.join("','")}']) THEN
154
+ SELECT c.relname, n.nspname INTO affected_table
155
+ FROM pg_class c
156
+ JOIN pg_namespace n ON n.oid = c.relnamespace
157
+ WHERE c.oid = obj.oid;
158
+
159
+ IF affected_table IN ('#{full_table_names.join("','")}') THEN
155
160
  INSERT INTO #{internal_schema_name}.#{table_name} (group_name, event_type, object_type, object_identity, ddl_command)
156
- VALUES ('#{group_name}', TG_EVENT, 'table', obj.oid::regclass::text, ddl_command);
161
+ VALUES ('#{group_name}', TG_EVENT, 'table', affected_table, 'table_rewrite');
157
162
  END IF;
158
163
  END LOOP;
159
164
  END IF;
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PgEasyReplicate
4
- VERSION = "0.3.0"
4
+ VERSION = "0.3.1"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pg_easy_replicate
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shayon Mukherjee
@@ -61,7 +61,7 @@ dependencies:
61
61
  version: '5.69'
62
62
  - - "<"
63
63
  - !ruby/object:Gem::Version
64
- version: '5.83'
64
+ version: '5.84'
65
65
  type: :runtime
66
66
  prerelease: false
67
67
  version_requirements: !ruby/object:Gem::Requirement
@@ -71,7 +71,7 @@ dependencies:
71
71
  version: '5.69'
72
72
  - - "<"
73
73
  - !ruby/object:Gem::Version
74
- version: '5.83'
74
+ version: '5.84'
75
75
  - !ruby/object:Gem::Dependency
76
76
  name: thor
77
77
  requirement: !ruby/object:Gem::Requirement