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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e9613e7cdfc987dd88b0726c3cfe9f9bc31cf4877267988c70fe2c52bf96b163
4
- data.tar.gz: 654f32e804769aca3cc0415b0455d0d4f481b6fc8e01625a3bd52fc43e11ee6d
3
+ metadata.gz: e7e142b478391e00c15f51378e09dd2b7e1429f8c7d1bdd2bb5d059ae8a968fb
4
+ data.tar.gz: a4464de621782aebfa90bac25e90458e4feca5c1007898d3537d44866a937c7b
5
5
  SHA512:
6
- metadata.gz: 80f42c596ef4fef11a44272c8a94089700428cc414030024410531e74ee6709d55fdff7b0de3b47a733b73aaf5e576cf519c746f9d4af60bfad978feefa5235f
7
- data.tar.gz: 0656dede260673942b237c12e94566156fdbed104b864c23b2617c69871088af97afaf6d21fcce6772e3e4a25dcc80e24450f189600d863b6b7a4992c1e9d491
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
- # Execute each statement
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
- # Provide detailed error information
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
- in_conflict = false
79
- quote_char = nil
71
+ escaped = false
80
72
 
81
73
  sql.each_char do |char|
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'
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
- # 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
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
- # Add any remaining statement
107
- statements << current_statement.strip if current_statement.strip.length > 0
108
-
109
- statements.map do |stmt|
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)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RealDataTests
4
- VERSION = "0.3.12"
4
+ VERSION = "0.3.14"
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.12
4
+ version: 0.3.14
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kevin Dias