-
Notifications
You must be signed in to change notification settings - Fork 21.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #42429 from Flixt/fix-mysql-check-constraints-quoting
Fix duplicate escaping of quotes for check constraint expressions in MySQL schema
- Loading branch information
Showing
3 changed files
with
51 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
activerecord/test/cases/adapters/mysql2/check_constraint_quoting_test.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# frozen_string_literal: true | ||
|
||
require "cases/helper" | ||
require "support/schema_dumping_helper" | ||
|
||
if ActiveRecord::Base.connection.supports_check_constraints? | ||
class Mysql2CheckConstraintQuotingTest < ActiveRecord::Mysql2TestCase | ||
include SchemaDumpingHelper | ||
|
||
setup do | ||
@connection = ActiveRecord::Base.connection | ||
@connection.create_table "trades", force: true do |t| | ||
t.string :name | ||
end | ||
end | ||
|
||
teardown do | ||
@connection.drop_table "trades", if_exists: true rescue nil | ||
end | ||
|
||
def test_check_constraint_no_duplicate_expression_quoting | ||
@connection.add_check_constraint :trades, "name != 'forbidden_string'" | ||
|
||
check_constraints = @connection.check_constraints("trades") | ||
assert_equal 1, check_constraints.size | ||
|
||
expression = check_constraints.first.expression | ||
if ActiveRecord::Base.connection.mariadb? | ||
assert_equal "`name` <> 'forbidden_string'", expression | ||
else | ||
assert_equal "`name` <> _utf8mb4'forbidden_string'", expression | ||
end | ||
end | ||
end | ||
end |