multiwoven-integrations 0.35.1 → 0.35.3
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:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 296955c660631759f84e1e24f580a1259ccf8abf867284b0ed4099d7adcf0925
|
|
4
|
+
data.tar.gz: 6f53522bdd3ac2c13fd777db41fd565baee9774d04d5c8bc27369036c0c919ee
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 32039f417c9727aff7ef7fb402a75f57540ba0b539422ade8f10e9b09ca2f759bdcadea9726336380f0dac307862808a98a0773afe0e8756829e3f90702358c8
|
|
7
|
+
data.tar.gz: ef7e2d82a89c99aa839950503243adcc58f8e166d1d75adc575ecf0f34ded253add6a5255a6c4e1710061cef1a4e5488462a939e25253a2ea853acdb4a969c48
|
|
@@ -51,8 +51,8 @@ module Multiwoven::Integrations::Destination
|
|
|
51
51
|
connection_config = sync_config.destination.connection_specification.with_indifferent_access
|
|
52
52
|
raw_table = sync_config.stream.name
|
|
53
53
|
table_name = qualify_table(connection_config[:schema], raw_table)
|
|
54
|
-
primary_key = sync_config.model.primary_key
|
|
55
54
|
db = create_connection(connection_config)
|
|
55
|
+
primary_key = fetch_primary_key(db, connection_config[:schema], raw_table)
|
|
56
56
|
|
|
57
57
|
write_success = 0
|
|
58
58
|
write_failure = 0
|
|
@@ -106,15 +106,19 @@ module Multiwoven::Integrations::Destination
|
|
|
106
106
|
end
|
|
107
107
|
|
|
108
108
|
sql = "INSERT INTO #{table_name} (#{col_list}) VALUES #{values_clauses.join(", ")}"
|
|
109
|
-
|
|
109
|
+
if primary_key.present?
|
|
110
|
+
sql += action.to_s == "destination_insert" ? build_safe_insert_clause(primary_key) : build_upsert_clause(columns, primary_key)
|
|
111
|
+
end
|
|
110
112
|
db.exec(sql)
|
|
111
113
|
end
|
|
112
114
|
|
|
113
|
-
def
|
|
114
|
-
|
|
115
|
+
def build_safe_insert_clause(primary_key)
|
|
116
|
+
" ON CONFLICT (#{quote_ident(primary_key)}) DO NOTHING"
|
|
117
|
+
end
|
|
115
118
|
|
|
119
|
+
def build_upsert_clause(columns, primary_key)
|
|
116
120
|
update_cols = columns.reject { |c| c.to_s == primary_key.to_s }
|
|
117
|
-
return
|
|
121
|
+
return build_safe_insert_clause(primary_key) if update_cols.empty?
|
|
118
122
|
|
|
119
123
|
set_clause = update_cols.map { |c| "#{quote_ident(c)} = EXCLUDED.#{quote_ident(c)}" }.join(", ")
|
|
120
124
|
" ON CONFLICT (#{quote_ident(primary_key)}) DO UPDATE SET #{set_clause}"
|
|
@@ -177,6 +181,23 @@ module Multiwoven::Integrations::Destination
|
|
|
177
181
|
end
|
|
178
182
|
end
|
|
179
183
|
|
|
184
|
+
def fetch_primary_key(db, schema, table)
|
|
185
|
+
schema = schema.presence || "public"
|
|
186
|
+
quoted = "\"#{schema}\".\"#{table}\""
|
|
187
|
+
result = db.exec(<<~SQL)
|
|
188
|
+
SELECT a.attname AS column_name
|
|
189
|
+
FROM pg_index i
|
|
190
|
+
JOIN pg_attribute a ON a.attrelid = i.indrelid AND a.attnum = ANY(i.indkey)
|
|
191
|
+
WHERE i.indrelid = '#{quoted}'::regclass
|
|
192
|
+
AND i.indisprimary
|
|
193
|
+
LIMIT 1
|
|
194
|
+
SQL
|
|
195
|
+
result.first&.dig("column_name")
|
|
196
|
+
rescue StandardError => e
|
|
197
|
+
logger.warn("POSTGRESQL:FETCH_PRIMARY_KEY:EXCEPTION #{e.message}")
|
|
198
|
+
nil
|
|
199
|
+
end
|
|
200
|
+
|
|
180
201
|
def qualify_table(schema, table)
|
|
181
202
|
return table if schema.blank? || schema == "public"
|
|
182
203
|
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: multiwoven-integrations
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.35.
|
|
4
|
+
version: 0.35.3
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Subin T P
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-
|
|
11
|
+
date: 2026-04-23 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: activesupport
|