pg_easy_replicate 0.3.0 → 0.3.2
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 +4 -4
- data/Gemfile.lock +3 -3
- data/README.md +5 -0
- data/docker-compose.yml +1 -1
- data/lib/pg_easy_replicate/ddl_audit.rb +12 -7
- data/lib/pg_easy_replicate/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 62d1f99ef5e2e12aa5969d9bda1a0e9d4df32a61102d712e3409386ca9e35697
|
4
|
+
data.tar.gz: 074aaabbd3be3ceef65bc3949f91d694d9d597ba7e49000c8fcf01d8ccb425a7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d504dfa0c0d41e3f095186a65e0103ce297a65104d6c130b479dae199992455e0732215d9748914f71c3b2fb33db9735d619b3ad59226f0103f78a9b47701bad
|
7
|
+
data.tar.gz: d99b662637e65c6e9547f081dcecb51fc34ef29c3c5ed38e23f3b4e12d94c1861c8a3420f1bef1fbc79167dd9d709f1c9ba191cb16e57882c385083cf3d88951
|
data/Gemfile.lock
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
pg_easy_replicate (0.3.
|
4
|
+
pg_easy_replicate (0.3.2)
|
5
5
|
ougai (~> 2.0.0)
|
6
6
|
pg (~> 1.5.3)
|
7
7
|
pg_query (~> 5.1.0)
|
8
|
-
sequel (>= 5.69, < 5.
|
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.
|
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
@@ -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
|
-
|
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.
|
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
|
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.
|
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
|
-
|
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',
|
161
|
+
VALUES ('#{group_name}', TG_EVENT, 'table', affected_table, 'table_rewrite');
|
157
162
|
END IF;
|
158
163
|
END LOOP;
|
159
164
|
END IF;
|
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.
|
4
|
+
version: 0.3.2
|
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.
|
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.
|
74
|
+
version: '5.84'
|
75
75
|
- !ruby/object:Gem::Dependency
|
76
76
|
name: thor
|
77
77
|
requirement: !ruby/object:Gem::Requirement
|