提交 af64c824 编写于 作者: R Ryuta Kamizono

Prefer `drop_table if_exists: true` over raw SQL

Lowercase raw SQL has been replaced by 07b659ca already. This commit
replaces everything else of raw SQL.
上级 9814eb64
......@@ -139,7 +139,7 @@ def create_test_fixtures(*fixture_names)
# custom drop table, uses execute on connection to drop a table if it exists. note: escapes table_name
def drop_tables_directly(table_names, connection = @connection)
table_names.each do |name|
connection.execute("DROP TABLE IF EXISTS `#{name}`")
connection.drop_table name, if_exists: true
end
end
......
......@@ -138,7 +138,7 @@ def create_test_fixtures(*fixture_names)
# custom drop table, uses execute on connection to drop a table if it exists. note: escapes table_name
def drop_tables_directly(table_names, connection = @connection)
table_names.each do |name|
connection.execute("DROP TABLE IF EXISTS `#{name}`")
connection.drop_table name, if_exists: true
end
end
......
......@@ -20,7 +20,7 @@ def setup
def teardown
return unless @connection
@connection.execute 'DROP TABLE IF EXISTS postgresql_bit_strings'
@connection.drop_table 'postgresql_bit_strings', if_exists: true
end
def test_bit_string_column
......
......@@ -19,7 +19,7 @@ def setup
end
teardown do
@connection.execute 'DROP TABLE IF EXISTS citexts;'
@connection.drop_table 'citexts', if_exists: true
disable_extension!('citext', @connection)
end
......
......@@ -29,7 +29,7 @@ def setup
def teardown
super
@connection.execute 'DROP TABLE IF EXISTS postgresql_composites'
@connection.drop_table 'postgresql_composites', if_exists: true
@connection.execute 'DROP TYPE IF EXISTS full_address'
reset_connection
PostgresqlComposite.reset_column_information
......
......@@ -19,7 +19,7 @@ def setup
end
teardown do
@connection.execute 'DROP TABLE IF EXISTS postgresql_domains'
@connection.drop_table 'postgresql_domains', if_exists: true
@connection.execute 'DROP DOMAIN IF EXISTS custom_money'
reset_connection
end
......
......@@ -21,7 +21,7 @@ def setup
end
teardown do
@connection.execute 'DROP TABLE IF EXISTS postgresql_enums'
@connection.drop_table 'postgresql_enums', if_exists: true
@connection.execute 'DROP TYPE IF EXISTS mood'
reset_connection
end
......
......@@ -13,7 +13,7 @@ class Tsvector < ActiveRecord::Base; end
end
teardown do
@connection.execute 'DROP TABLE IF EXISTS tsvectors;'
@connection.drop_table 'tsvectors', if_exists: true
end
def test_tsvector_column
......
......@@ -18,7 +18,7 @@ def setup
end
teardown do
@connection.execute 'DROP TABLE IF EXISTS postgresql_points'
@connection.drop_table 'postgresql_points', if_exists: true
end
def test_column
......@@ -84,7 +84,7 @@ class PostgresqlGeometric < ActiveRecord::Base; end
end
teardown do
@connection.execute 'DROP TABLE IF EXISTS postgresql_geometrics'
@connection.drop_table 'postgresql_geometrics', if_exists: true
end
def test_geometric_types
......
......@@ -15,7 +15,7 @@ class PostgresqlInfinity < ActiveRecord::Base
end
teardown do
@connection.execute("DROP TABLE IF EXISTS postgresql_infinities")
@connection.drop_table 'postgresql_infinities', if_exists: true
end
test "type casting infinity on a float column" do
......
......@@ -16,7 +16,7 @@ class PostgresqlMoney < ActiveRecord::Base; end
end
teardown do
@connection.execute 'DROP TABLE IF EXISTS postgresql_moneys'
@connection.drop_table 'postgresql_moneys', if_exists: true
end
def test_column
......
......@@ -15,7 +15,7 @@ class PostgresqlNetworkAddress < ActiveRecord::Base; end
end
teardown do
@connection.execute 'DROP TABLE IF EXISTS postgresql_network_addresses'
@connection.drop_table 'postgresql_network_addresses', if_exists: true
end
def test_cidr_column
......
......@@ -12,7 +12,7 @@ class PostgresqlNumber < ActiveRecord::Base; end
end
teardown do
@connection.execute 'DROP TABLE IF EXISTS postgresql_numbers'
@connection.drop_table 'postgresql_numbers', if_exists: true
end
def test_data_type
......
......@@ -227,8 +227,8 @@ def test_pk_and_sequence_for_with_collision_pg_class_oid
"DELETE FROM pg_depend WHERE objid = 'ex2_id_seq'::regclass AND refobjid = 'ex'::regclass AND deptype = 'a'"
)
ensure
@connection.exec_query('DROP TABLE IF EXISTS ex')
@connection.exec_query('DROP TABLE IF EXISTS ex2')
@connection.drop_table 'ex', if_exists: true
@connection.drop_table 'ex2', if_exists: true
end
def test_exec_insert_number
......
......@@ -91,7 +91,7 @@ def setup
end
teardown do
@connection.execute 'DROP TABLE IF EXISTS postgresql_ranges'
@connection.drop_table 'postgresql_ranges', if_exists: true
@connection.execute 'DROP TYPE IF EXISTS floatrange'
reset_connection
end
......
......@@ -7,8 +7,8 @@ def setup
end
def teardown
@connection.execute 'DROP TABLE IF EXISTS "before_rename"'
@connection.execute 'DROP TABLE IF EXISTS "after_rename"'
@connection.drop_table "before_rename", if_exists: true
@connection.drop_table "after_rename", if_exists: true
end
test "renaming a table also renames the primary key index" do
......
......@@ -460,8 +460,8 @@ def test_dump_foreign_key_targeting_different_schema
output = dump_table_schema "wagons"
assert_match %r{\s+add_foreign_key "wagons", "my_schema\.trains", column: "train_id"$}, output
ensure
@connection.execute "DROP TABLE IF EXISTS wagons"
@connection.execute "DROP TABLE IF EXISTS my_schema.trains"
@connection.drop_table "wagons", if_exists: true
@connection.drop_table "my_schema.trains", if_exists: true
@connection.execute "DROP SCHEMA IF EXISTS my_schema"
end
end
......
......@@ -191,7 +191,7 @@ def test_quote_binary_column_escapes_it
binary.save!
assert_equal str, binary.data
ensure
DualEncoding.connection.execute('DROP TABLE IF EXISTS dual_encodings')
DualEncoding.connection.drop_table 'dual_encodings', if_exists: true
end
def test_type_cast_should_not_mutate_encoding
......
......@@ -260,7 +260,7 @@ class Widget < ActiveRecord::Base
end
teardown do
@connection.execute("DROP TABLE IF EXISTS widgets")
@connection.drop_table 'widgets', if_exists: true
end
test "primary key column type with bigserial" do
......
......@@ -362,7 +362,7 @@ class SchemaDumperDefaultsTest < ActiveRecord::TestCase
teardown do
return unless @connection
@connection.execute 'DROP TABLE defaults' if @connection.table_exists? 'defaults'
@connection.drop_table 'defaults', if_exists: true
end
def test_schema_dump_defaults_with_universally_supported_types
......
......@@ -2,7 +2,7 @@
%w(postgresql_times postgresql_oids defaults postgresql_timestamp_with_zones
postgresql_partitioned_table postgresql_partitioned_table_parent).each do |table_name|
execute "DROP TABLE IF EXISTS #{quote_table_name table_name}"
drop_table table_name, if_exists: true
end
execute 'DROP SEQUENCE IF EXISTS companies_nonstd_seq CASCADE'
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册