real_data_tests 0.3.12 → 0.3.14
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 +30 -36
- 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: e7e142b478391e00c15f51378e09dd2b7e1429f8c7d1bdd2bb5d059ae8a968fb
|
4
|
+
data.tar.gz: a4464de621782aebfa90bac25e90458e4feca5c1007898d3537d44866a937c7b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '078fcfb22739b26714d756e10afc54ce10a15b947706f1f8eccee31f65384695b770ea546e69a889c033378fff79d314b1b66c4d86b29b3eab2dbb62e6b93231'
|
7
|
+
data.tar.gz: c02a03e895d13a78e75adcf5c8ff5c6d9ea920d91dbaf463dad5e344bbe890e5877cb42385a65aa1f2df5c57b94cb595c96b78279cb9f1f66616e44e9a50a927
|
@@ -29,26 +29,19 @@ module RealDataTests
|
|
29
29
|
connection.execute('SET session_replication_role = replica;')
|
30
30
|
|
31
31
|
begin
|
32
|
-
# Read the SQL file content
|
33
32
|
sql_content = File.read(dump_path)
|
34
|
-
|
35
|
-
# Split the file into individual statements
|
36
33
|
statements = split_sql_statements(sql_content)
|
37
34
|
|
38
|
-
|
39
|
-
statements.each do |statement|
|
40
|
-
next if statement.strip.empty?
|
35
|
+
statements.each_with_index do |statement, index|
|
41
36
|
begin
|
42
|
-
# Clean up any formatting issues that might cause syntax errors
|
43
37
|
cleaned_statement = clean_sql_statement(statement)
|
38
|
+
puts "Executing Statement ##{index + 1}: #{cleaned_statement}" # Debug log
|
44
39
|
connection.execute(cleaned_statement)
|
45
40
|
rescue ActiveRecord::StatementInvalid => e
|
46
|
-
|
47
|
-
raise Error, "Failed to execute SQL statement: #{e.message}\nStatement: #{cleaned_statement}"
|
41
|
+
raise Error, "Error executing statement ##{index + 1}: #{e.message}\nSQL: #{cleaned_statement}"
|
48
42
|
end
|
49
43
|
end
|
50
44
|
ensure
|
51
|
-
# Re-enable foreign key checks
|
52
45
|
connection.execute('SET session_replication_role = DEFAULT;')
|
53
46
|
end
|
54
47
|
end
|
@@ -75,41 +68,42 @@ module RealDataTests
|
|
75
68
|
statements = []
|
76
69
|
current_statement = ''
|
77
70
|
in_string = false
|
78
|
-
|
79
|
-
quote_char = nil
|
71
|
+
escaped = false
|
80
72
|
|
81
73
|
sql.each_char do |char|
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
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'
|
74
|
+
if char == '\\'
|
75
|
+
escaped = !escaped
|
76
|
+
elsif char == "'" && !escaped
|
77
|
+
in_string = !in_string
|
78
|
+
elsif char == ';' && !in_string
|
79
|
+
# Add the completed statement
|
80
|
+
statements << current_statement.strip unless current_statement.strip.empty?
|
81
|
+
current_statement = ''
|
82
|
+
next
|
94
83
|
end
|
95
|
-
|
84
|
+
escaped = false
|
96
85
|
current_statement << char
|
86
|
+
end
|
97
87
|
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
88
|
+
# Add the last statement if it exists
|
89
|
+
statements << current_statement.strip unless current_statement.strip.empty?
|
90
|
+
|
91
|
+
# Normalize `ON CONFLICT` clauses
|
92
|
+
statements = statements.each_with_object([]) do |stmt, result|
|
93
|
+
if stmt.strip.upcase.start_with?('ON CONFLICT')
|
94
|
+
result[-1] = "#{result.last.strip} #{stmt.strip}"
|
95
|
+
else
|
96
|
+
result << stmt.strip
|
103
97
|
end
|
104
98
|
end
|
105
99
|
|
106
|
-
#
|
107
|
-
statements
|
108
|
-
|
109
|
-
|
110
|
-
# Ensure each statement ends with a semicolon
|
111
|
-
stmt.end_with?(';') ? stmt : "#{stmt};"
|
100
|
+
# Ensure semicolons and spacing
|
101
|
+
statements.map! do |stmt|
|
102
|
+
stmt = stmt.gsub(/\)\s*ON CONFLICT/, ') ON CONFLICT') # Normalize spacing
|
103
|
+
stmt.strip.end_with?(';') ? stmt.strip : "#{stmt.strip};"
|
112
104
|
end
|
105
|
+
|
106
|
+
statements
|
113
107
|
end
|
114
108
|
|
115
109
|
def extract_conflict_clause(statement)
|