real_data_tests 0.3.9 → 0.3.11

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: 3a45102a35d4a4d4bff64e68a4edef1b7e29d8c2ca68c0a957ac2589b8ce3b04
4
- data.tar.gz: 506f07bccd0524de51819b128a6a707979e68723e513e829e0437a9d7b503b75
3
+ metadata.gz: a18a6616a26a2d4c65ad746e42ac560dd883c302c7ef73113a960309132de449
4
+ data.tar.gz: fbbe885c19cbffc91eefa9c0f60c56dcdba519d1a5f21458837aa3dadfede2e7
5
5
  SHA512:
6
- metadata.gz: e33a481a786ef940d50eabf13b23ddc8175af68ec16892f685809a7acec88a27786f4b54e6588a890167c90a058d690acc7d1ba7d264e0802549590516d499aa
7
- data.tar.gz: 45dcce0d68ce3011521aea9ffcefc7d355af5544c0cc8cc385b37b897e953cd51d9af928536c8c901f7ff35ba33a52df9886ac186b5182aecc0821c83d6ceb91
6
+ metadata.gz: 41e9ce6c2b3d427d5b04cb671378d44e0d9f5d24556698c86e0b3e3d671df0b7a41b3f30207b2bba9224c7ddc89b869c747195d1deb8c8956f1ee37ab4b0e690
7
+ data.tar.gz: c07e898c90af0d265f637c21e95fbc1a88e83c3a5c7233e11b8517443707005cff23ab1c3984142e21a3307e5e7c53e16a3cd55bb5a8124ba3cb281e1e9c7eba
data/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.3.10] - 2025-01-14
4
+ ### Fixed
5
+ - Enhanced SQL statement parsing in native loader
6
+ - Improved handling of complex ON CONFLICT clauses with multiple closing parentheses
7
+ - Fixed spacing issues between VALUES and ON CONFLICT clauses
8
+ - Enhanced regex pattern for more precise conflict clause extraction
9
+ - Added proper statement reassembly for complex SQL structures
10
+
3
11
  ## [0.3.9] - 2025-01-14
4
12
  ### Fixed
5
13
  - Enhanced SQL statement parsing in native loader
@@ -17,7 +17,7 @@ module RealDataTests
17
17
  end
18
18
  end
19
19
 
20
- # New method that doesn't rely on system commands
20
+ # Native Ruby implementation
21
21
  def load_real_test_data_native(name)
22
22
  dump_path = File.join(RealDataTests.configuration.dump_path, "#{name}.sql")
23
23
  raise Error, "Test data file not found: #{dump_path}" unless File.exist?(dump_path)
@@ -113,10 +113,10 @@ module RealDataTests
113
113
  end
114
114
 
115
115
  def clean_sql_statement(statement)
116
- # First, detect if this is an INSERT statement with VALUES
117
- if statement =~ /INSERT INTO.*VALUES\s*\(/i
118
- # Split the statement into three parts: pre-VALUES, values, and post-VALUES (ON CONFLICT clause)
119
- if statement =~ /(.*VALUES\s*\()(.*)(\)\s*(?:ON CONFLICT.*)?;?\s*$)/i
116
+ # Match either INSERT INTO...VALUES or just VALUES
117
+ if statement =~ /(?:INSERT INTO.*)?VALUES\s*\(/i
118
+ # Split the statement into parts, being careful with the ending
119
+ if statement =~ /(.*?VALUES\s*\()(.*)(\)\s*(?:ON CONFLICT.*)?;?\s*$)/i
120
120
  pre_values = $1
121
121
  values_content = $2
122
122
  post_values = $3
@@ -124,9 +124,10 @@ module RealDataTests
124
124
  # Clean the values content while preserving complex JSON
125
125
  cleaned_values = clean_complex_values(values_content)
126
126
 
127
- # Reassemble the statement
127
+ # Reassemble the statement, ensuring exactly one semicolon at the end
128
128
  statement = "#{pre_values}#{cleaned_values}#{post_values}"
129
- statement += ";" unless statement.end_with?(";")
129
+ statement = statement.gsub(/;*\s*$/, '') # Remove any trailing semicolons and whitespace
130
+ statement += ";"
130
131
  end
131
132
  end
132
133
  statement
@@ -138,6 +139,7 @@ module RealDataTests
138
139
  in_quotes = false
139
140
  in_json = false
140
141
  json_brace_count = 0
142
+ escaped = false
141
143
 
142
144
  chars = values_str.chars
143
145
  i = 0
@@ -145,11 +147,14 @@ module RealDataTests
145
147
  char = chars[i]
146
148
 
147
149
  case char
150
+ when '\\'
151
+ current_value << char
152
+ escaped = !escaped
148
153
  when "'"
149
- # Check if this is an escaped quote
150
- if i > 0 && chars[i-1] != '\\'
154
+ if !escaped
151
155
  in_quotes = !in_quotes
152
156
  end
157
+ escaped = false
153
158
  current_value << char
154
159
  when '{'
155
160
  if !in_quotes
@@ -171,6 +176,7 @@ module RealDataTests
171
176
  current_value << char
172
177
  end
173
178
  else
179
+ escaped = false
174
180
  current_value << char
175
181
  end
176
182
  i += 1
@@ -182,39 +188,6 @@ module RealDataTests
182
188
  values.join(', ')
183
189
  end
184
190
 
185
- def clean_values(values_str)
186
- values = []
187
- current_value = ''
188
- in_quotes = false
189
- nested_level = 0
190
-
191
- values_str.chars.each do |char|
192
- case char
193
- when "'"
194
- in_quotes = !in_quotes
195
- current_value << char
196
- when '{'
197
- nested_level += 1
198
- current_value << char
199
- when '}'
200
- nested_level -= 1
201
- current_value << char
202
- when ','
203
- if !in_quotes && nested_level == 0
204
- values << clean_value(current_value.strip)
205
- current_value = ''
206
- else
207
- current_value << char
208
- end
209
- else
210
- current_value << char
211
- end
212
- end
213
-
214
- values << clean_value(current_value.strip)
215
- values.join(', ')
216
- end
217
-
218
191
  def clean_value(value)
219
192
  return value if value.start_with?("'") # Already quoted
220
193
  return value if value.start_with?("'{") # JSON object
@@ -225,8 +198,46 @@ module RealDataTests
225
198
  if value.match?(/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i)
226
199
  "'#{value}'" # UUID
227
200
  else
201
+ # Handle any other string value, including those with commas
228
202
  "'#{value}'" # Other strings
229
203
  end
230
204
  end
231
205
  end
206
+
207
+ def import
208
+ @logger.info "Starting SQL import..."
209
+
210
+ ActiveRecord::Base.transaction do
211
+ begin
212
+ # Disable foreign key checks and triggers temporarily
213
+ ActiveRecord::Base.connection.execute('SET session_replication_role = replica;')
214
+
215
+ # Split the SQL content into individual statements
216
+ statements = split_sql_statements(@sql_content)
217
+
218
+ statements.each_with_index do |statement, index|
219
+ next if statement.strip.empty?
220
+
221
+ begin
222
+ @logger.info "Executing statement #{index + 1} of #{statements.length}"
223
+ cleaned_statement = clean_sql_statement(statement)
224
+ ActiveRecord::Base.connection.execute(cleaned_statement)
225
+ rescue ActiveRecord::StatementInvalid => e
226
+ @logger.error "Error executing statement #{index + 1}: #{e.message}"
227
+ @logger.error "Statement: #{cleaned_statement[0..100]}..."
228
+ raise
229
+ end
230
+ end
231
+
232
+ @logger.info "Successfully imported all SQL statements"
233
+ rescue StandardError => e
234
+ @logger.error "Error during import: #{e.message}"
235
+ @logger.error e.backtrace.join("\n")
236
+ raise
237
+ ensure
238
+ # Re-enable foreign key checks and triggers
239
+ ActiveRecord::Base.connection.execute('SET session_replication_role = DEFAULT;')
240
+ end
241
+ end
242
+ end
232
243
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RealDataTests
4
- VERSION = "0.3.9"
4
+ VERSION = "0.3.11"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: real_data_tests
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.9
4
+ version: 0.3.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kevin Dias