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 +4 -4
- data/Gemfile.lock +2 -2
- 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: 846d76c9da382a82b36243070402e2e42d7135c6ccd52a1308b4d4ebdb15e4ca
|
4
|
+
data.tar.gz: 159925fe9649bc527a861f4e5eac52102af05542ddfeb8f742e9077a1764fe38
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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.
|
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.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.
|
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
|