real_data_tests 0.3.10 → 0.3.11

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: f76c93165cf56a1bb2e90311afc6bf92f42f17553271a977dec2e17f39afc67f
4
- data.tar.gz: f1caa35f8eaa904dba0b608484d43d8beffaa7208646e067f046b8add97db10d
3
+ metadata.gz: a18a6616a26a2d4c65ad746e42ac560dd883c302c7ef73113a960309132de449
4
+ data.tar.gz: fbbe885c19cbffc91eefa9c0f60c56dcdba519d1a5f21458837aa3dadfede2e7
5
5
  SHA512:
6
- metadata.gz: 1097a749d0dd8ad287130dbab5a75c0f526de6689e9877d4f218657d6c03ad49ccd8c0c3cd02697306d1fee41c11c0915f11e4c264e2254cb21013e266d130aa
7
- data.tar.gz: c0b6f6c9f84558801e5140eea8da6c5f068ad5adbe4dd3ba520e87fe2ef2259921374d52713e8e3a52775b64bb439f426be72a698d83e5a0144b16a6282cfc14
6
+ metadata.gz: 41e9ce6c2b3d427d5b04cb671378d44e0d9f5d24556698c86e0b3e3d671df0b7a41b3f30207b2bba9224c7ddc89b869c747195d1deb8c8956f1ee37ab4b0e690
7
+ data.tar.gz: c07e898c90af0d265f637c21e95fbc1a88e83c3a5c7233e11b8517443707005cff23ab1c3984142e21a3307e5e7c53e16a3cd55bb5a8124ba3cb281e1e9c7eba
@@ -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)
@@ -202,38 +202,42 @@ module RealDataTests
202
202
  "'#{value}'" # Other strings
203
203
  end
204
204
  end
205
+ end
205
206
 
206
- def clean_values(values_str)
207
- values = []
208
- current_value = ''
209
- in_quotes = false
210
- nested_level = 0
207
+ def import
208
+ @logger.info "Starting SQL import..."
211
209
 
212
- values_str.chars.each do |char|
213
- case char
214
- when "'"
215
- in_quotes = !in_quotes
216
- current_value << char
217
- when '{'
218
- nested_level += 1
219
- current_value << char
220
- when '}'
221
- nested_level -= 1
222
- current_value << char
223
- when ','
224
- if !in_quotes && nested_level == 0
225
- values << clean_value(current_value.strip)
226
- current_value = ''
227
- else
228
- current_value << char
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
229
  end
230
- else
231
- current_value << char
232
230
  end
233
- end
234
231
 
235
- values << clean_value(current_value.strip)
236
- values.join(', ')
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
237
241
  end
238
242
  end
239
243
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RealDataTests
4
- VERSION = "0.3.10"
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.10
4
+ version: 0.3.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kevin Dias