real_data_tests 0.3.10 → 0.3.12
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/real_data_tests/rspec_helper.rb +60 -47
- data/lib/real_data_tests/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e9613e7cdfc987dd88b0726c3cfe9f9bc31cf4877267988c70fe2c52bf96b163
|
4
|
+
data.tar.gz: 654f32e804769aca3cc0415b0455d0d4f481b6fc8e01625a3bd52fc43e11ee6d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 80f42c596ef4fef11a44272c8a94089700428cc414030024410531e74ee6709d55fdff7b0de3b47a733b73aaf5e576cf519c746f9d4af60bfad978feefa5235f
|
7
|
+
data.tar.gz: 0656dede260673942b237c12e94566156fdbed104b864c23b2617c69871088af97afaf6d21fcce6772e3e4a25dcc80e24450f189600d863b6b7a4992c1e9d491
|
@@ -17,7 +17,7 @@ module RealDataTests
|
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
20
|
-
#
|
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)
|
@@ -75,32 +75,41 @@ module RealDataTests
|
|
75
75
|
statements = []
|
76
76
|
current_statement = ''
|
77
77
|
in_string = false
|
78
|
-
|
78
|
+
in_conflict = false
|
79
|
+
quote_char = nil
|
79
80
|
|
80
81
|
sql.each_char do |char|
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
82
|
+
# Detect start of quoted strings
|
83
|
+
if (char == "'" || char == '"') && !in_string
|
84
|
+
in_string = true
|
85
|
+
quote_char = char
|
86
|
+
# Detect end of quoted strings (matching quote type)
|
87
|
+
elsif (char == "'" || char == '"') && in_string && char == quote_char
|
88
|
+
in_string = false
|
89
|
+
# Track if we're in an ON CONFLICT clause
|
90
|
+
elsif char == 'O' && !in_string && current_statement.strip.end_with?(')')
|
91
|
+
# Look ahead to see if this is 'ON CONFLICT'
|
92
|
+
potential_conflict = sql[sql.index(char, sql.rindex(current_statement)), 11]
|
93
|
+
in_conflict = potential_conflict&.upcase == 'ON CONFLICT'
|
94
|
+
end
|
95
|
+
|
96
|
+
current_statement << char
|
97
|
+
|
98
|
+
# Only split on semicolon if we're not in a string and not in an ON CONFLICT clause
|
99
|
+
if char == ';' && !in_string && !in_conflict
|
100
|
+
statements << current_statement.strip
|
101
|
+
current_statement = ''
|
102
|
+
in_conflict = false
|
97
103
|
end
|
98
104
|
end
|
99
105
|
|
100
|
-
# Add
|
106
|
+
# Add any remaining statement
|
101
107
|
statements << current_statement.strip if current_statement.strip.length > 0
|
102
108
|
|
103
|
-
statements
|
109
|
+
statements.map do |stmt|
|
110
|
+
# Ensure each statement ends with a semicolon
|
111
|
+
stmt.end_with?(';') ? stmt : "#{stmt};"
|
112
|
+
end
|
104
113
|
end
|
105
114
|
|
106
115
|
def extract_conflict_clause(statement)
|
@@ -202,38 +211,42 @@ module RealDataTests
|
|
202
211
|
"'#{value}'" # Other strings
|
203
212
|
end
|
204
213
|
end
|
214
|
+
end
|
205
215
|
|
206
|
-
|
207
|
-
|
208
|
-
current_value = ''
|
209
|
-
in_quotes = false
|
210
|
-
nested_level = 0
|
216
|
+
def import
|
217
|
+
@logger.info "Starting SQL import..."
|
211
218
|
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
219
|
+
ActiveRecord::Base.transaction do
|
220
|
+
begin
|
221
|
+
# Disable foreign key checks and triggers temporarily
|
222
|
+
ActiveRecord::Base.connection.execute('SET session_replication_role = replica;')
|
223
|
+
|
224
|
+
# Split the SQL content into individual statements
|
225
|
+
statements = split_sql_statements(@sql_content)
|
226
|
+
|
227
|
+
statements.each_with_index do |statement, index|
|
228
|
+
next if statement.strip.empty?
|
229
|
+
|
230
|
+
begin
|
231
|
+
@logger.info "Executing statement #{index + 1} of #{statements.length}"
|
232
|
+
cleaned_statement = clean_sql_statement(statement)
|
233
|
+
ActiveRecord::Base.connection.execute(cleaned_statement)
|
234
|
+
rescue ActiveRecord::StatementInvalid => e
|
235
|
+
@logger.error "Error executing statement #{index + 1}: #{e.message}"
|
236
|
+
@logger.error "Statement: #{cleaned_statement[0..100]}..."
|
237
|
+
raise
|
229
238
|
end
|
230
|
-
else
|
231
|
-
current_value << char
|
232
239
|
end
|
233
|
-
end
|
234
240
|
|
235
|
-
|
236
|
-
|
241
|
+
@logger.info "Successfully imported all SQL statements"
|
242
|
+
rescue StandardError => e
|
243
|
+
@logger.error "Error during import: #{e.message}"
|
244
|
+
@logger.error e.backtrace.join("\n")
|
245
|
+
raise
|
246
|
+
ensure
|
247
|
+
# Re-enable foreign key checks and triggers
|
248
|
+
ActiveRecord::Base.connection.execute('SET session_replication_role = DEFAULT;')
|
249
|
+
end
|
237
250
|
end
|
238
251
|
end
|
239
252
|
end
|