activerecord-jdbc-adapter 1.3.0.beta2 → 1.3.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +14 -8
- data/.travis.yml +40 -31
- data/.yardopts +4 -0
- data/Appraisals +2 -5
- data/CONTRIBUTING.md +46 -0
- data/Gemfile +21 -4
- data/Gemfile.lock +42 -17
- data/{History.txt → History.md} +142 -75
- data/README.md +102 -104
- data/RUNNING_TESTS.md +76 -0
- data/Rakefile.jdbc +20 -0
- data/activerecord-jdbc-adapter.gemspec +35 -18
- data/gemfiles/rails23.gemfile +4 -3
- data/gemfiles/rails23.gemfile.lock +9 -6
- data/gemfiles/rails30.gemfile +4 -3
- data/gemfiles/rails30.gemfile.lock +9 -6
- data/gemfiles/rails31.gemfile +4 -3
- data/gemfiles/rails31.gemfile.lock +9 -6
- data/gemfiles/rails32.gemfile +4 -3
- data/gemfiles/rails32.gemfile.lock +17 -14
- data/gemfiles/rails40.gemfile +5 -5
- data/gemfiles/rails40.gemfile.lock +17 -69
- data/lib/active_record/connection_adapters/firebird_adapter.rb +1 -0
- data/lib/active_record/connection_adapters/sqlserver_adapter.rb +1 -0
- data/lib/arel/visitors/compat.rb +22 -3
- data/lib/arel/visitors/db2.rb +8 -4
- data/lib/arel/visitors/derby.rb +14 -13
- data/lib/arel/visitors/firebird.rb +5 -4
- data/lib/arel/visitors/hsqldb.rb +11 -9
- data/lib/arel/visitors/sql_server.rb +89 -61
- data/lib/arjdbc.rb +1 -1
- data/lib/arjdbc/db2/adapter.rb +181 -212
- data/lib/arjdbc/db2/as400.rb +31 -18
- data/lib/arjdbc/db2/column.rb +167 -0
- data/lib/arjdbc/db2/connection_methods.rb +2 -0
- data/lib/arjdbc/derby/adapter.rb +206 -107
- data/lib/arjdbc/derby/connection_methods.rb +4 -9
- data/lib/arjdbc/firebird.rb +1 -0
- data/lib/arjdbc/firebird/adapter.rb +202 -64
- data/lib/arjdbc/firebird/connection_methods.rb +20 -0
- data/lib/arjdbc/h2/adapter.rb +56 -36
- data/lib/arjdbc/hsqldb/adapter.rb +99 -68
- data/lib/arjdbc/jdbc/adapter.rb +474 -265
- data/lib/arjdbc/jdbc/adapter_java.jar +0 -0
- data/lib/arjdbc/jdbc/adapter_require.rb +8 -7
- data/lib/arjdbc/jdbc/arel_support.rb +132 -0
- data/lib/arjdbc/jdbc/base_ext.rb +8 -7
- data/lib/arjdbc/jdbc/callbacks.rb +16 -10
- data/lib/arjdbc/jdbc/column.rb +25 -3
- data/lib/arjdbc/jdbc/connection.rb +28 -55
- data/lib/arjdbc/jdbc/extension.rb +14 -14
- data/lib/arjdbc/jdbc/java.rb +6 -3
- data/lib/arjdbc/jdbc/jdbc.rake +1 -1
- data/lib/arjdbc/jdbc/quoted_primary_key.rb +2 -2
- data/lib/arjdbc/jdbc/rake_tasks.rb +1 -1
- data/lib/arjdbc/jdbc/type_converter.rb +5 -2
- data/lib/arjdbc/mssql/adapter.rb +160 -280
- data/lib/arjdbc/mssql/column.rb +182 -0
- data/lib/arjdbc/mssql/connection_methods.rb +37 -4
- data/lib/arjdbc/mssql/explain_support.rb +13 -21
- data/lib/arjdbc/mssql/limit_helpers.rb +79 -42
- data/lib/arjdbc/mssql/lock_methods.rb +77 -0
- data/lib/arjdbc/mssql/utils.rb +11 -11
- data/lib/arjdbc/mysql/adapter.rb +165 -247
- data/lib/arjdbc/mysql/column.rb +123 -0
- data/lib/arjdbc/mysql/connection_methods.rb +3 -6
- data/lib/arjdbc/oracle/adapter.rb +282 -288
- data/lib/arjdbc/oracle/column.rb +122 -0
- data/lib/arjdbc/oracle/connection_methods.rb +3 -0
- data/lib/arjdbc/postgresql/adapter.rb +336 -574
- data/lib/arjdbc/postgresql/column.rb +458 -0
- data/lib/arjdbc/postgresql/connection_methods.rb +1 -2
- data/lib/arjdbc/postgresql/schema_creation.rb +38 -0
- data/lib/arjdbc/sqlite3/adapter.rb +189 -145
- data/lib/arjdbc/sqlite3/explain_support.rb +1 -1
- data/lib/arjdbc/tasks/oracle/enhanced_structure_dump.rb +8 -8
- data/lib/arjdbc/util/quoted_cache.rb +60 -0
- data/lib/arjdbc/util/table_copier.rb +110 -0
- data/lib/arjdbc/version.rb +6 -7
- data/pom.xml +56 -2
- data/rakelib/02-test.rake +72 -83
- data/rakelib/db.rake +29 -17
- data/src/java/arjdbc/ArJdbcModule.java +21 -18
- data/src/java/arjdbc/db2/DB2RubyJdbcConnection.java +84 -12
- data/src/java/arjdbc/derby/DerbyModule.java +140 -143
- data/src/java/arjdbc/derby/DerbyRubyJdbcConnection.java +58 -7
- data/src/java/arjdbc/h2/H2Module.java +43 -0
- data/src/java/arjdbc/informix/InformixRubyJdbcConnection.java +7 -6
- data/src/java/arjdbc/jdbc/RubyJdbcConnection.java +1223 -648
- data/src/java/arjdbc/mssql/MSSQLRubyJdbcConnection.java +24 -23
- data/src/java/arjdbc/mysql/MySQLModule.java +33 -32
- data/src/java/arjdbc/mysql/MySQLRubyJdbcConnection.java +147 -30
- data/src/java/arjdbc/oracle/OracleModule.java +13 -13
- data/src/java/arjdbc/oracle/OracleRubyJdbcConnection.java +114 -6
- data/src/java/arjdbc/postgresql/PostgreSQLRubyJdbcConnection.java +166 -36
- data/src/java/arjdbc/sqlite3/SQLite3RubyJdbcConnection.java +101 -19
- data/src/java/arjdbc/util/QuotingUtils.java +19 -19
- metadata +240 -394
- data/bench/bench_attributes.rb +0 -13
- data/bench/bench_attributes_new.rb +0 -14
- data/bench/bench_create.rb +0 -12
- data/bench/bench_find_all.rb +0 -12
- data/bench/bench_find_all_mt.rb +0 -25
- data/bench/bench_model.rb +0 -85
- data/bench/bench_new.rb +0 -12
- data/bench/bench_new_valid.rb +0 -12
- data/bench/bench_valid.rb +0 -13
- data/lib/arel/engines/sql/compilers/db2_compiler.rb +0 -9
- data/lib/arel/engines/sql/compilers/derby_compiler.rb +0 -6
- data/lib/arel/engines/sql/compilers/h2_compiler.rb +0 -6
- data/lib/arel/engines/sql/compilers/hsqldb_compiler.rb +0 -15
- data/lib/arel/engines/sql/compilers/jdbc_compiler.rb +0 -6
- data/lib/arel/engines/sql/compilers/mssql_compiler.rb +0 -46
- data/lib/arjdbc/jdbc/missing_functionality_helper.rb +0 -98
- data/lib/arjdbc/mssql/lock_helpers.rb +0 -76
- data/lib/arjdbc/mssql/tsql_methods.rb +0 -58
- data/lib/arjdbc/postgresql/column_cast.rb +0 -134
- data/test/activerecord/connections/native_jdbc_mysql/connection.rb +0 -25
- data/test/activerecord/jall.sh +0 -7
- data/test/activerecord/jtest.sh +0 -3
- data/test/assets/flowers.jpg +0 -0
- data/test/binary.rb +0 -67
- data/test/db/db2.rb +0 -43
- data/test/db/db2/binary_test.rb +0 -6
- data/test/db/db2/has_many_through_test.rb +0 -6
- data/test/db/db2/rake_test.rb +0 -82
- data/test/db/db2/rake_test_data.sql +0 -35
- data/test/db/db2/reset_column_information_test.rb +0 -5
- data/test/db/db2/serialize_test.rb +0 -6
- data/test/db/db2/simple_test.rb +0 -81
- data/test/db/db2/test_helper.rb +0 -6
- data/test/db/db2/unit_test.rb +0 -73
- data/test/db/derby.rb +0 -12
- data/test/db/derby/binary_test.rb +0 -6
- data/test/db/derby/migration_test.rb +0 -74
- data/test/db/derby/rake_test.rb +0 -96
- data/test/db/derby/reset_column_information_test.rb +0 -6
- data/test/db/derby/row_locking_test.rb +0 -20
- data/test/db/derby/schema_dump_test.rb +0 -5
- data/test/db/derby/serialize_test.rb +0 -6
- data/test/db/derby/simple_test.rb +0 -173
- data/test/db/derby/test_helper.rb +0 -6
- data/test/db/derby/unit_test.rb +0 -32
- data/test/db/derby/xml_column_test.rb +0 -17
- data/test/db/h2.rb +0 -11
- data/test/db/h2/binary_test.rb +0 -6
- data/test/db/h2/change_column_test.rb +0 -68
- data/test/db/h2/identity_column_test.rb +0 -35
- data/test/db/h2/offset_test.rb +0 -49
- data/test/db/h2/rake_test.rb +0 -98
- data/test/db/h2/schema_dump_test.rb +0 -29
- data/test/db/h2/serialize_test.rb +0 -6
- data/test/db/h2/simple_test.rb +0 -56
- data/test/db/hsqldb.rb +0 -11
- data/test/db/hsqldb/binary_test.rb +0 -6
- data/test/db/hsqldb/rake_test.rb +0 -101
- data/test/db/hsqldb/schema_dump_test.rb +0 -19
- data/test/db/hsqldb/serialize_test.rb +0 -6
- data/test/db/hsqldb/simple_test.rb +0 -17
- data/test/db/informix.rb +0 -13
- data/test/db/jdbc.rb +0 -16
- data/test/db/jdbc_derby.rb +0 -14
- data/test/db/jdbc_h2.rb +0 -17
- data/test/db/jdbc_mysql.rb +0 -13
- data/test/db/jdbc_postgres.rb +0 -23
- data/test/db/jndi_config.rb +0 -32
- data/test/db/jndi_pooled_config.rb +0 -32
- data/test/db/mssql.rb +0 -11
- data/test/db/mssql/binary_test.rb +0 -6
- data/test/db/mssql/exec_proc_test.rb +0 -46
- data/test/db/mssql/identity_insert_test.rb +0 -18
- data/test/db/mssql/ignore_system_views_test.rb +0 -40
- data/test/db/mssql/limit_offset_test.rb +0 -190
- data/test/db/mssql/multibyte_test.rb +0 -16
- data/test/db/mssql/multiple_connections_test.rb +0 -71
- data/test/db/mssql/rake_test.rb +0 -143
- data/test/db/mssql/reset_column_information_test.rb +0 -6
- data/test/db/mssql/row_locking_test.rb +0 -7
- data/test/db/mssql/serialize_test.rb +0 -6
- data/test/db/mssql/simple_test.rb +0 -140
- data/test/db/mssql/transaction_test.rb +0 -6
- data/test/db/mssql/types_test.rb +0 -205
- data/test/db/mssql/unit_test.rb +0 -249
- data/test/db/mysql.rb +0 -4
- data/test/db/mysql/_rails_test_mysql.32.out +0 -6585
- data/test/db/mysql/binary_test.rb +0 -6
- data/test/db/mysql/connection_test.rb +0 -51
- data/test/db/mysql/index_length_test.rb +0 -58
- data/test/db/mysql/multibyte_test.rb +0 -10
- data/test/db/mysql/nonstandard_primary_key_test.rb +0 -39
- data/test/db/mysql/rake_test.rb +0 -97
- data/test/db/mysql/reset_column_information_test.rb +0 -6
- data/test/db/mysql/schema_dump_test.rb +0 -228
- data/test/db/mysql/serialize_test.rb +0 -6
- data/test/db/mysql/simple_test.rb +0 -187
- data/test/db/mysql/statement_escaping_test.rb +0 -46
- data/test/db/mysql/transaction_test.rb +0 -6
- data/test/db/mysql/types_test.rb +0 -30
- data/test/db/mysql/unit_test.rb +0 -93
- data/test/db/mysql_config.rb +0 -7
- data/test/db/oracle.rb +0 -27
- data/test/db/oracle/binary_test.rb +0 -6
- data/test/db/oracle/limit_test.rb +0 -24
- data/test/db/oracle/multibyte_test.rb +0 -22
- data/test/db/oracle/rake_test.rb +0 -100
- data/test/db/oracle/reset_column_information_test.rb +0 -6
- data/test/db/oracle/serialize_test.rb +0 -6
- data/test/db/oracle/simple_test.rb +0 -140
- data/test/db/oracle/specific_test.rb +0 -180
- data/test/db/oracle/transaction_test.rb +0 -31
- data/test/db/oracle/unit_test.rb +0 -31
- data/test/db/postgres.rb +0 -11
- data/test/db/postgres/_rails_test_postgres.32.out +0 -6405
- data/test/db/postgres/a_custom_primary_key_test.rb +0 -50
- data/test/db/postgres/active_schema_unit_test.rb +0 -68
- data/test/db/postgres/array_type_test.rb +0 -101
- data/test/db/postgres/binary_test.rb +0 -6
- data/test/db/postgres/connection_test.rb +0 -63
- data/test/db/postgres/data_types_test.rb +0 -703
- data/test/db/postgres/hstore_test.rb +0 -200
- data/test/db/postgres/information_schema_leak_test.rb +0 -30
- data/test/db/postgres/json_test.rb +0 -86
- data/test/db/postgres/ltree_test.rb +0 -51
- data/test/db/postgres/mixed_case_test.rb +0 -29
- data/test/db/postgres/native_types_test.rb +0 -124
- data/test/db/postgres/rake_test.rb +0 -117
- data/test/db/postgres/reserved_test.rb +0 -22
- data/test/db/postgres/reset_column_information_test.rb +0 -6
- data/test/db/postgres/row_locking_test.rb +0 -21
- data/test/db/postgres/schema_dump_test.rb +0 -95
- data/test/db/postgres/schema_test.rb +0 -115
- data/test/db/postgres/simple_test.rb +0 -260
- data/test/db/postgres/table_alias_length_test.rb +0 -16
- data/test/db/postgres/transaction_test.rb +0 -6
- data/test/db/postgres/unit_test.rb +0 -31
- data/test/db/postgres_config.rb +0 -10
- data/test/db/sqlite3.rb +0 -6
- data/test/db/sqlite3/_rails_test_sqlite3.32.out +0 -6274
- data/test/db/sqlite3/has_many_though_test.rb +0 -6
- data/test/db/sqlite3/rake_test.rb +0 -71
- data/test/db/sqlite3/reset_column_information_test.rb +0 -6
- data/test/db/sqlite3/schema_dump_test.rb +0 -6
- data/test/db/sqlite3/serialize_test.rb +0 -6
- data/test/db/sqlite3/simple_test.rb +0 -268
- data/test/db/sqlite3/transaction_test.rb +0 -32
- data/test/db/sqlite3/type_conversion_test.rb +0 -104
- data/test/has_many_through.rb +0 -61
- data/test/informix_simple_test.rb +0 -48
- data/test/jdbc/db2.rb +0 -36
- data/test/jdbc/oracle.rb +0 -34
- data/test/jdbc_column_test.rb +0 -23
- data/test/jdbc_common.rb +0 -16
- data/test/jdbc_connection_test.rb +0 -196
- data/test/jndi_callbacks_test.rb +0 -33
- data/test/jndi_test.rb +0 -55
- data/test/manualTestDatabase.rb +0 -191
- data/test/models/add_not_null_column_to_table.rb +0 -9
- data/test/models/auto_id.rb +0 -15
- data/test/models/binary.rb +0 -18
- data/test/models/custom_pk_name.rb +0 -15
- data/test/models/data_types.rb +0 -40
- data/test/models/entry.rb +0 -41
- data/test/models/mixed_case.rb +0 -22
- data/test/models/reserved_word.rb +0 -15
- data/test/models/rights_and_roles.rb +0 -57
- data/test/models/string_id.rb +0 -17
- data/test/models/thing.rb +0 -17
- data/test/models/topic.rb +0 -32
- data/test/models/validates_uniqueness_of_string.rb +0 -19
- data/test/rails/mysql.rb +0 -13
- data/test/rails/sqlite3/version.rb +0 -6
- data/test/rails_stub.rb +0 -31
- data/test/rake_test_support.rb +0 -298
- data/test/row_locking.rb +0 -102
- data/test/schema_dump.rb +0 -182
- data/test/serialize.rb +0 -275
- data/test/shared_helper.rb +0 -35
- data/test/simple.rb +0 -1317
- data/test/sybase_jtds_simple_test.rb +0 -28
- data/test/sybase_reset_column_information_test.rb +0 -6
- data/test/test_helper.rb +0 -304
- data/test/transaction.rb +0 -109
@@ -1,51 +0,0 @@
|
|
1
|
-
require 'db/mysql'
|
2
|
-
|
3
|
-
class MySQLConnectionTest < Test::Unit::TestCase
|
4
|
-
|
5
|
-
def test_mysql_default_in_strict_mode
|
6
|
-
assert_equal [["STRICT_ALL_TABLES"]], select_rows("SELECT @@SESSION.sql_mode")
|
7
|
-
end if ar_version('4.0')
|
8
|
-
|
9
|
-
def test_mysql_strict_mode_disabled
|
10
|
-
run_without_connection do |orig_connection|
|
11
|
-
ActiveRecord::Base.establish_connection(orig_connection.merge({:strict => false}))
|
12
|
-
assert_equal [['']], select_rows("SELECT @@SESSION.sql_mode")
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
def test_mysql_set_session_variable
|
17
|
-
run_without_connection do |orig_connection|
|
18
|
-
ActiveRecord::Base.establish_connection(orig_connection.deep_merge({:variables => {:default_week_format => 3}}))
|
19
|
-
rows = select_rows("SELECT @@SESSION.DEFAULT_WEEK_FORMAT")
|
20
|
-
assert_equal 3, rows.first.first.to_i
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
def test_mysql_set_session_variable_to_default
|
25
|
-
run_without_connection do |orig_connection|
|
26
|
-
ActiveRecord::Base.establish_connection(orig_connection.deep_merge({:variables => {:default_week_format => :default}}))
|
27
|
-
global_mode_rows = select_rows "SELECT @@GLOBAL.DEFAULT_WEEK_FORMAT"
|
28
|
-
session_mode_rows = select_rows "SELECT @@SESSION.DEFAULT_WEEK_FORMAT"
|
29
|
-
assert_equal global_mode_rows, session_mode_rows
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
protected
|
34
|
-
|
35
|
-
def select_rows(sql)
|
36
|
-
result = ActiveRecord::Base.connection.exec_query(sql)
|
37
|
-
result.respond_to?(:rows) ? result.rows : [ result.first.map { |_,value| value } ]
|
38
|
-
end
|
39
|
-
|
40
|
-
private
|
41
|
-
|
42
|
-
def run_without_connection
|
43
|
-
original_connection = ActiveRecord::Base.remove_connection
|
44
|
-
begin
|
45
|
-
yield original_connection
|
46
|
-
ensure
|
47
|
-
ActiveRecord::Base.establish_connection(original_connection)
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
end
|
@@ -1,58 +0,0 @@
|
|
1
|
-
require 'jdbc_common'
|
2
|
-
require 'db/mysql'
|
3
|
-
|
4
|
-
class MySQLIndexLengthDBSetup < ActiveRecord::Migration
|
5
|
-
def self.up
|
6
|
-
execute <<-SQL
|
7
|
-
CREATE TABLE index_length_test (
|
8
|
-
int_column INT,
|
9
|
-
text_column TEXT,
|
10
|
-
second_text_column TEXT,
|
11
|
-
INDEX ix_int (int_column),
|
12
|
-
INDEX ix_length_text (text_column(255))
|
13
|
-
)
|
14
|
-
SQL
|
15
|
-
end
|
16
|
-
|
17
|
-
def self.down
|
18
|
-
drop_table 'index_length_test'
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
class MySQLIndexLengthTest < Test::Unit::TestCase
|
23
|
-
def setup
|
24
|
-
MySQLIndexLengthDBSetup.up
|
25
|
-
@connection = ActiveRecord::Base.connection
|
26
|
-
end
|
27
|
-
|
28
|
-
def teardown
|
29
|
-
MySQLIndexLengthDBSetup.down
|
30
|
-
end
|
31
|
-
|
32
|
-
def test_index_length
|
33
|
-
index = @connection.indexes('index_length_test').find { |idx| idx.name == 'ix_length_text' }
|
34
|
-
assert_not_nil index
|
35
|
-
assert_equal "index_length_test", index.table
|
36
|
-
assert_equal "ix_length_text", index.name
|
37
|
-
assert !index.unique
|
38
|
-
assert_equal ["text_column"], index.columns
|
39
|
-
assert_equal [255], index.lengths
|
40
|
-
end
|
41
|
-
|
42
|
-
def test_add_index
|
43
|
-
@connection.add_index 'index_length_test', ['text_column', 'second_text_column'],
|
44
|
-
:name => 'added_index', :length => {'text_column' => 32, 'second_text_column' => 64}
|
45
|
-
|
46
|
-
index = @connection.indexes('index_length_test').find { |idx| idx.name == 'added_index' }
|
47
|
-
assert_not_nil index
|
48
|
-
assert_equal ['text_column', 'second_text_column'], index.columns
|
49
|
-
assert_equal [32, 64], index.lengths
|
50
|
-
end
|
51
|
-
|
52
|
-
def test_index_without_length
|
53
|
-
index = @connection.indexes('index_length_test').find { |idx| idx.name == 'ix_int' }
|
54
|
-
assert_not_nil index
|
55
|
-
assert_equal ['int_column'], index.columns
|
56
|
-
assert_equal [nil], index.lengths
|
57
|
-
end
|
58
|
-
end
|
@@ -1,39 +0,0 @@
|
|
1
|
-
require 'jdbc_common'
|
2
|
-
require 'db/mysql'
|
3
|
-
|
4
|
-
class MysqlNonstandardPrimaryKeyTest < Test::Unit::TestCase
|
5
|
-
|
6
|
-
class Project < ActiveRecord::Migration
|
7
|
-
def self.up
|
8
|
-
create_table :project, :primary_key => "project_id" do |t|
|
9
|
-
t.string :projectType, :limit => 31
|
10
|
-
t.boolean :published
|
11
|
-
t.datetime :created_date
|
12
|
-
t.text :abstract, :title
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
def self.down
|
17
|
-
drop_table :project
|
18
|
-
end
|
19
|
-
|
20
|
-
end
|
21
|
-
|
22
|
-
def setup
|
23
|
-
Project.up
|
24
|
-
end
|
25
|
-
|
26
|
-
def teardown
|
27
|
-
Project.down
|
28
|
-
end
|
29
|
-
|
30
|
-
def test_nonstandard_primary_key
|
31
|
-
output = schema_dump
|
32
|
-
if ar_version('4.0')
|
33
|
-
assert_match %r(primary_key: "project_id"), output, "non-standard primary key not preserved"
|
34
|
-
else
|
35
|
-
assert_match %r(:primary_key => "project_id"), output, "non-standard primary key not preserved"
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
end
|
data/test/db/mysql/rake_test.rb
DELETED
@@ -1,97 +0,0 @@
|
|
1
|
-
require 'rake_test_support'
|
2
|
-
require 'db/mysql'
|
3
|
-
|
4
|
-
class MySQLRakeTest < Test::Unit::TestCase
|
5
|
-
include RakeTestSupport
|
6
|
-
|
7
|
-
def db_config
|
8
|
-
MYSQL_CONFIG
|
9
|
-
end
|
10
|
-
|
11
|
-
def do_teardown
|
12
|
-
drop_rake_test_database(:silence)
|
13
|
-
end
|
14
|
-
|
15
|
-
test 'rake db:create (and db:drop)' do
|
16
|
-
# omit_unless find_executable?("mysql")
|
17
|
-
Rake::Task["db:create"].invoke
|
18
|
-
with_mysql do |mysql|
|
19
|
-
mysql << "show databases where `Database` = '#{db_name}';"
|
20
|
-
mysql.close_write
|
21
|
-
output = mysql.read
|
22
|
-
assert output =~ /#{db_name}/m, "db name: #{db_name.inspect} not matched in:\n#{output}"
|
23
|
-
end if find_executable?("mysql")
|
24
|
-
|
25
|
-
Rake::Task["db:drop"].invoke
|
26
|
-
with_mysql do |mysql|
|
27
|
-
mysql << "show databases where `Database` = '#{db_name}';"
|
28
|
-
mysql.close_write
|
29
|
-
output = mysql.read
|
30
|
-
assert_nil output =~ /#{db_name}/m, "db name: #{db_name.inspect} matched in:\n#{output}"
|
31
|
-
end if find_executable?("mysql")
|
32
|
-
end
|
33
|
-
|
34
|
-
test 'rake db:test:purge' do
|
35
|
-
# Rake::Task["db:create"].invoke
|
36
|
-
create_rake_test_database do |connection|
|
37
|
-
connection.create_table('users') { |t| t.string :name }
|
38
|
-
end
|
39
|
-
|
40
|
-
Rake::Task["db:test:purge"].invoke
|
41
|
-
|
42
|
-
ActiveRecord::Base.establish_connection db_config.merge :database => db_name
|
43
|
-
assert_false ActiveRecord::Base.connection.table_exists?('users')
|
44
|
-
ActiveRecord::Base.connection.disconnect!
|
45
|
-
end
|
46
|
-
|
47
|
-
test 'rake db:structure:dump (and db:structure:load)' do
|
48
|
-
# Rake::Task["db:create"].invoke
|
49
|
-
create_rake_test_database do |connection|
|
50
|
-
create_schema_migrations_table(connection)
|
51
|
-
connection.create_table('users') { |t| t.string :name; t.timestamps }
|
52
|
-
end
|
53
|
-
|
54
|
-
structure_sql = File.join('db', structure_sql_filename)
|
55
|
-
begin
|
56
|
-
Dir.mkdir 'db' # db/structure.sql
|
57
|
-
Rake::Task["db:structure:dump"].invoke
|
58
|
-
|
59
|
-
assert File.exists?(structure_sql)
|
60
|
-
assert_match /CREATE TABLE `users`/, File.read(structure_sql)
|
61
|
-
|
62
|
-
# db:structure:load
|
63
|
-
drop_rake_test_database(:silence)
|
64
|
-
create_rake_test_database
|
65
|
-
Rake::Task["db:structure:load"].invoke
|
66
|
-
|
67
|
-
ActiveRecord::Base.establish_connection db_config.merge :database => db_name
|
68
|
-
assert ActiveRecord::Base.connection.table_exists?('users')
|
69
|
-
ActiveRecord::Base.connection.disconnect!
|
70
|
-
ensure
|
71
|
-
File.delete(structure_sql) if File.exists?(structure_sql)
|
72
|
-
Dir.rmdir 'db'
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
setup { rm_r 'db' if File.exist?('db') }
|
77
|
-
|
78
|
-
test 'rake db:charset' do
|
79
|
-
create_rake_test_database
|
80
|
-
expect_rake_output 'utf8'
|
81
|
-
Rake::Task["db:charset"].invoke
|
82
|
-
end
|
83
|
-
|
84
|
-
test 'rake db:collation' do
|
85
|
-
create_rake_test_database
|
86
|
-
expect_rake_output /utf8_.*?_ci/
|
87
|
-
Rake::Task["db:collation"].invoke
|
88
|
-
end
|
89
|
-
|
90
|
-
private
|
91
|
-
|
92
|
-
def with_mysql(args = nil)
|
93
|
-
exec = "mysql -u #{db_config[:username]} --password=#{db_config[:password]} #{args}"
|
94
|
-
IO.popen(exec, "r+") { |mysql| yield(mysql) }
|
95
|
-
end
|
96
|
-
|
97
|
-
end
|
@@ -1,228 +0,0 @@
|
|
1
|
-
require 'db/mysql'
|
2
|
-
require 'schema_dump'
|
3
|
-
begin; require 'active_support/core_ext/numeric/bytes'; rescue LoadError; end
|
4
|
-
|
5
|
-
class MysqlSchemaDumpTest < Test::Unit::TestCase
|
6
|
-
include SchemaDumpTestMethods
|
7
|
-
|
8
|
-
def self.startup
|
9
|
-
super
|
10
|
-
MigrationSetup.setup!
|
11
|
-
end
|
12
|
-
|
13
|
-
def self.shutdown
|
14
|
-
MigrationSetup.teardown!
|
15
|
-
super
|
16
|
-
end
|
17
|
-
|
18
|
-
def setup!; end # MigrationSetup#setup!
|
19
|
-
def teardown!; end # MigrationSetup#teardown!
|
20
|
-
|
21
|
-
ActiveRecord::Schema.define do
|
22
|
-
create_table :big_fields, :force => true do |t|
|
23
|
-
t.binary :tiny_blob, :limit => 255
|
24
|
-
t.binary :normal_blob, :limit => 65535
|
25
|
-
t.binary :medium_blob, :limit => 16777215
|
26
|
-
t.binary :long_blob, :limit => 2147483647
|
27
|
-
t.text :tiny_text, :limit => 255
|
28
|
-
t.text :normal_text, :limit => 65535
|
29
|
-
t.text :medium_text, :limit => 16777215
|
30
|
-
t.text :long_text, :limit => 2147483647
|
31
|
-
t.text :just_text, :null => false
|
32
|
-
# MySQL does not allow default values for blobs.
|
33
|
-
# Fake it out with a big varchar below.
|
34
|
-
t.string :string_col, :null => true, :default => '', :limit => 1024
|
35
|
-
t.binary :var_binary, :limit => 255
|
36
|
-
t.binary :var_binary_large, :limit => 4095
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
def test_schema_dump_should_not_add_default_value_for_mysql_text_field
|
41
|
-
output = standard_dump
|
42
|
-
assert_match %r{t.text\s+"just_text",[\s|:]+null[\s\:\=\>]+false$}, output
|
43
|
-
end
|
44
|
-
|
45
|
-
def test_schema_dump_includes_length_for_mysql_blob_and_text_fields
|
46
|
-
output = standard_dump
|
47
|
-
assert_match %r{t.binary\s+"tiny_blob",[\s|:]+limit[\s\:\=\>]+255$}, output
|
48
|
-
assert_match %r{t.binary\s+"normal_blob"$}, output
|
49
|
-
assert_match %r{t.binary\s+"medium_blob",[\s|:]+limit[\s\:\=\>]+16777215$}, output
|
50
|
-
assert_match %r{t.binary\s+"long_blob",[\s|:]+limit[\s\:\=\>]+2147483647$}, output
|
51
|
-
assert_match %r{t.text\s+"tiny_text",[\s|:]+limit[\s\:\=\>]+255$}, output
|
52
|
-
assert_match %r{t.text\s+"normal_text"$}, output
|
53
|
-
assert_match %r{t.text\s+"medium_text",[\s|:]+limit[\s\:\=\>]+16777215$}, output
|
54
|
-
assert_match %r{t.text\s+"long_text",[\s|:]+limit[\s\:\=\>]+2147483647$}, output
|
55
|
-
end
|
56
|
-
|
57
|
-
def test_schema_dump_includes_length_for_mysql_binary_fields
|
58
|
-
output = standard_dump
|
59
|
-
assert_match %r{t.binary\s+"var_binary",[\s|:]+limit[\s\:\=\>]+255$}, output
|
60
|
-
assert_match %r{t.binary\s+"var_binary_large",[\s|:]+limit[\s\:\=\>]+4095$}, output
|
61
|
-
end
|
62
|
-
|
63
|
-
end
|
64
|
-
|
65
|
-
class MysqlInfoTest < Test::Unit::TestCase
|
66
|
-
|
67
|
-
class DBSetup < ActiveRecord::Migration
|
68
|
-
|
69
|
-
def self.up
|
70
|
-
create_table :books do |t|
|
71
|
-
t.string :title
|
72
|
-
t.timestamps
|
73
|
-
end
|
74
|
-
|
75
|
-
create_table :cars, :primary_key => 'legacy_id' do |t|
|
76
|
-
t.string :name
|
77
|
-
t.date :production_started_on
|
78
|
-
end
|
79
|
-
|
80
|
-
create_table :cats, :id => false do |t|
|
81
|
-
t.string :name
|
82
|
-
end
|
83
|
-
|
84
|
-
create_table :memos do |t|
|
85
|
-
t.text :text, :limit => 16.megabytes
|
86
|
-
end
|
87
|
-
end
|
88
|
-
|
89
|
-
def self.down
|
90
|
-
drop_table :books
|
91
|
-
drop_table :cars
|
92
|
-
drop_table :cats
|
93
|
-
drop_table :memos
|
94
|
-
end
|
95
|
-
|
96
|
-
end
|
97
|
-
|
98
|
-
def self.startup
|
99
|
-
super
|
100
|
-
DBSetup.up
|
101
|
-
end
|
102
|
-
|
103
|
-
def self.shutdown
|
104
|
-
DBSetup.down
|
105
|
-
super
|
106
|
-
end
|
107
|
-
|
108
|
-
## primary_key
|
109
|
-
def test_should_return_the_primary_key_of_a_table
|
110
|
-
assert_equal 'id', connection.primary_key('books')
|
111
|
-
end
|
112
|
-
|
113
|
-
def test_should_be_able_to_return_a_custom_primary_key
|
114
|
-
assert_equal 'legacy_id', connection.primary_key('cars')
|
115
|
-
end
|
116
|
-
|
117
|
-
def test_should_return_nil_for_a_table_without_a_primary_key
|
118
|
-
assert_nil connection.primary_key('cats')
|
119
|
-
end
|
120
|
-
|
121
|
-
## structure_dump
|
122
|
-
def test_should_include_the_tables_in_a_structure_dump
|
123
|
-
# TODO: Improve these tests, I added this one because no other tests exists for this method.
|
124
|
-
dump = connection.structure_dump
|
125
|
-
assert dump.include?('CREATE TABLE `books`')
|
126
|
-
assert dump.include?('CREATE TABLE `cars`')
|
127
|
-
assert dump.include?('CREATE TABLE `cats`')
|
128
|
-
assert dump.include?('CREATE TABLE `memos`')
|
129
|
-
end
|
130
|
-
|
131
|
-
def test_should_include_longtext_in_schema_dump
|
132
|
-
strio = StringIO.new
|
133
|
-
ActiveRecord::SchemaDumper::dump(connection, strio)
|
134
|
-
dump = strio.string
|
135
|
-
assert_match %r{t.text\s+"text",[\s|:]+limit[\s\:\=\>]+2147483647$}, dump
|
136
|
-
end
|
137
|
-
|
138
|
-
# JRUBY-5040
|
139
|
-
def test_schema_dump_should_not_have_limits_on_datetime
|
140
|
-
dump = schema_dump
|
141
|
-
dump.lines.grep(/datetime/).each { |line| assert line !~ /limit/ }
|
142
|
-
end
|
143
|
-
|
144
|
-
def test_schema_dump_should_not_have_limits_on_date
|
145
|
-
dump = schema_dump
|
146
|
-
dump.lines.grep(/date/).each { |line| assert line !~ /limit/ }
|
147
|
-
end
|
148
|
-
|
149
|
-
def test_should_include_limit
|
150
|
-
text_column = connection.columns('memos').find { |c| c.name == 'text' }
|
151
|
-
assert_equal 2147483647, text_column.limit
|
152
|
-
end
|
153
|
-
|
154
|
-
def test_should_set_sqltype_to_longtext
|
155
|
-
text_column = connection.columns('memos').find { |c| c.name == 'text' }
|
156
|
-
assert text_column.sql_type =~ /^longtext/i, "longtext sql type expected for: #{text_column.inspect}"
|
157
|
-
end
|
158
|
-
|
159
|
-
def test_should_set_type_to_text
|
160
|
-
text_column = connection.columns('memos').find { |c| c.name == 'text' }
|
161
|
-
assert_equal :text, text_column.type
|
162
|
-
end
|
163
|
-
|
164
|
-
def test_verify_url_has_options
|
165
|
-
url = connection.config[:url]
|
166
|
-
assert url =~ /characterEncoding=utf8/
|
167
|
-
assert url =~ /useUnicode=true/
|
168
|
-
assert url =~ /zeroDateTimeBehavior=convertToNull/
|
169
|
-
end
|
170
|
-
|
171
|
-
def test_no_limits_for_some_data_types
|
172
|
-
DbTypeMigration.up
|
173
|
-
#
|
174
|
-
# AR-3.2 :
|
175
|
-
#
|
176
|
-
# create_table "db_types", :force => true do |t|
|
177
|
-
# t.datetime "sample_timestamp"
|
178
|
-
# t.datetime "sample_datetime"
|
179
|
-
# t.date "sample_date"
|
180
|
-
# t.time "sample_time"
|
181
|
-
# t.decimal "sample_decimal", :precision => 15, :scale => 0
|
182
|
-
# t.decimal "sample_small_decimal", :precision => 3, :scale => 2
|
183
|
-
# t.decimal "sample_default_decimal", :precision => 10, :scale => 0
|
184
|
-
# t.float "sample_float"
|
185
|
-
# t.binary "sample_binary"
|
186
|
-
# t.boolean "sample_boolean"
|
187
|
-
# t.string "sample_string", :default => ""
|
188
|
-
# t.integer "sample_integer", :limit => 8
|
189
|
-
# t.integer "sample_integer_with_limit_2", :limit => 2
|
190
|
-
# t.integer "sample_integer_with_limit_8", :limit => 8
|
191
|
-
# t.integer "sample_integer_no_limit"
|
192
|
-
# t.integer "sample_integer_neg_default", :default => -1
|
193
|
-
# t.text "sample_text"
|
194
|
-
# end
|
195
|
-
#
|
196
|
-
# AR-2.3 :
|
197
|
-
#
|
198
|
-
# create_table "db_types", :force => true do |t|
|
199
|
-
# t.datetime "sample_timestamp"
|
200
|
-
# t.datetime "sample_datetime"
|
201
|
-
# t.date "sample_date"
|
202
|
-
# t.time "sample_time"
|
203
|
-
# t.integer "sample_decimal", :limit => 15, :precision => 15, :scale => 0
|
204
|
-
# t.decimal "sample_small_decimal", :precision => 3, :scale => 2
|
205
|
-
# t.integer "sample_default_decimal", :limit => 10, :precision => 10, :scale => 0
|
206
|
-
# t.float "sample_float"
|
207
|
-
# t.binary "sample_binary"
|
208
|
-
# t.boolean "sample_boolean"
|
209
|
-
# t.string "sample_string", :default => ""
|
210
|
-
# t.integer "sample_integer", :limit => 8
|
211
|
-
# t.integer "sample_integer_with_limit_2", :limit => 2
|
212
|
-
# t.integer "sample_integer_with_limit_8", :limit => 8
|
213
|
-
# t.integer "sample_integer_no_limit"
|
214
|
-
# t.integer "sample_integer_neg_default", :default => -1
|
215
|
-
# t.text "sample_text"
|
216
|
-
# end
|
217
|
-
#
|
218
|
-
dump = schema_dump
|
219
|
-
if ar_version('3.0')
|
220
|
-
assert_nil dump.lines.detect {|l| l =~ /\.(float|date|datetime|integer|time|timestamp) .* :limit/ && l !~ /sample_integer/ }, dump
|
221
|
-
else
|
222
|
-
puts "test_no_limits_for_some_data_types assertion skipped on #{ActiveRecord::VERSION::STRING}"
|
223
|
-
end
|
224
|
-
ensure
|
225
|
-
DbTypeMigration.down
|
226
|
-
end
|
227
|
-
|
228
|
-
end
|