Permalink
Browse files

Added migration support for Oracle (closes #2647) [Michael Schoen]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@2817 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
1 parent 14b60fc commit 68160b34854f6b886b3cf9fe3045af1d18128747 @dhh dhh committed Oct 29, 2005
View
@@ -1,5 +1,7 @@
*SVN*
+* Added migration support for Oracle #2647 [Michael Schoen]
+
* Worked around that connection can't be reset if allow_concurrency is off. #2648 [Michael Schoen <schoenm@earthlink.net>]
* Fixed SQL Server adapter to pass even more tests and do even better #2634 [rtomayko@gmail.com]
@@ -232,14 +232,14 @@ def column(name, type, options = {})
@columns << column unless @columns.include? column
self
end
-
+
# Returns a String whose contents are the column definitions
# concatenated together. This string can then be pre and appended to
# to generate the final SQL to create the table.
def to_sql
@columns * ', '
end
-
+
private
def native
@base.native_database_types
@@ -239,8 +239,8 @@ def type_to_sql(type, limit = nil) #:nodoc:
end
def add_column_options!(sql, options) #:nodoc:
- sql << " NOT NULL" if options[:null] == false
sql << " DEFAULT #{quote(options[:default], options[:column])}" unless options[:default].nil?
+ sql << " NOT NULL" if options[:null] == false
end
end
end

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -18,7 +18,7 @@ def test_schema_define
ActiveRecord::Schema.define(:version => 7) do
create_table :fruits do |t|
t.column :color, :string
- t.column :size, :string
+ t.column :fruit_size, :string # NOTE: "size" is reserved in Oracle
t.column :texture, :string
t.column :flavor, :string
end
@@ -238,9 +238,6 @@ def test_preserving_date_objects
end
def test_preserving_time_objects
- # Oracle does not have a TIME datatype.
- return true if current_adapter?(:OCIAdapter)
-
assert_kind_of(
Time, Topic.find(1).bonus_time,
"The bonus_time attribute should be of the Time class"
@@ -650,7 +647,7 @@ def test_multiparameter_mass_assignment_protector
end
def test_attributes_on_dummy_time
- # Oracle and SQL Server does not have a TIME datatype.
+ # Oracle and SQL Server do not have a TIME datatype.
return true if current_adapter?(:SQLServerAdapter) || current_adapter?(:OCIAdapter)
attributes = {
@@ -1084,4 +1081,4 @@ def assert_readers(model, exceptions)
expected_readers = model.column_names - (model.serialized_attributes.keys + exceptions + ['id'])
assert_equal expected_readers.sort, model.read_methods.keys.sort
end
-end
+end
@@ -15,14 +15,10 @@ def test_find_all_with_limit
end
def test_find_all_with_prepared_limit_and_offset
- if current_adapter?(:OCIAdapter)
- assert_raises(ArgumentError) { Entrant.find_all nil, "id ASC", [2, 1] }
- else
- entrants = Entrant.find_all nil, "id ASC", [2, 1]
+ entrants = Entrant.find_all nil, "id ASC", [2, 1]
- assert_equal(2, entrants.size)
- assert_equal(entrants(:second).name, entrants.first.name)
- end
+ assert_equal(2, entrants.size)
+ assert_equal(entrants(:second).name, entrants.first.name)
end
def test_find_first
@@ -52,9 +52,6 @@ def test_inserts
end
def test_inserts_with_pre_and_suffix
- # not supported yet in OCI adapter
- return true if current_adapter?(:OCIAdapter)
-
ActiveRecord::Base.connection.create_table :prefix_topics_suffix do |t|
t.column :title, :string
t.column :author_name, :string
@@ -84,8 +84,14 @@ def test_create_table_with_defaults
four = columns.detect { |c| c.name == "four" }
assert_equal "hello", one.default
- assert_equal true, two.default
- assert_equal false, three.default
+ if current_adapter?(:OCIAdapter)
+ # Oracle doesn't support native booleans
+ assert_equal true, two.default == 1
+ assert_equal false, three.default != 0
+ else
+ assert_equal true, two.default
+ assert_equal false, three.default
+ end
assert_equal 1, four.default
ensure
@@ -147,8 +153,8 @@ def test_native_types
assert_equal Fixnum, bob.age.class
assert_equal Time, bob.birthday.class
- if current_adapter?(:SQLServerAdapter)
- # SQL Server doesn't differentiate between date/time
+ if current_adapter?(:SQLServerAdapter) or current_adapter?(:OCIAdapter)
+ # SQL Server and Oracle don't differentiate between date/time
assert_equal Time, bob.favorite_day.class
else
assert_equal Date, bob.favorite_day.class
@@ -231,21 +237,26 @@ def test_rename_table
begin
ActiveRecord::Base.connection.create_table :octopuses do |t|
t.column :url, :string
- end
+ end
ActiveRecord::Base.connection.rename_table :octopuses, :octopi
-
+
assert_nothing_raised do
- ActiveRecord::Base.connection.execute "INSERT INTO octopi (url) VALUES ('http://www.foreverflying.com/octopus-black7.jpg')"
+ if current_adapter?(:OCIAdapter)
+ # Oracle requires the explicit sequence for the pk
+ ActiveRecord::Base.connection.execute "INSERT INTO octopi (id, url) VALUES (octopi_seq.nextval, 'http://www.foreverflying.com/octopus-black7.jpg')"
+ else
+ ActiveRecord::Base.connection.execute "INSERT INTO octopi (url) VALUES ('http://www.foreverflying.com/octopus-black7.jpg')"
+ end
end
assert_equal 'http://www.foreverflying.com/octopus-black7.jpg', ActiveRecord::Base.connection.select_value("SELECT url FROM octopi WHERE id=1")
-
+
ensure
ActiveRecord::Base.connection.drop_table :octopuses rescue nil
ActiveRecord::Base.connection.drop_table :octopi rescue nil
end
end
-
+
def test_change_column
Person.connection.add_column "people", "bio", :string
assert_nothing_raised { Person.connection.change_column "people", "bio", :text }
@@ -398,4 +409,4 @@ def test_add_drop_table_with_prefix_and_suffix
Reminder.reset_table_name
end
end
-end
+end
@@ -77,10 +77,14 @@ def test_readonly_constraint
assert !Post.find(1, :readonly => false).readonly?
end
- Post.constrain(:joins => ', developers') do
- assert Post.find(1).readonly?
- assert Post.find(1, :readonly => true).readonly?
- assert !Post.find(1, :readonly => false).readonly?
+ # Oracle barfs on this because the join includes unqualified and
+ # conflicting column names
+ unless current_adapter?(:OCIAdapter)
+ Post.constrain(:joins => ', developers') do
+ assert Post.find(1).readonly?
+ assert Post.find(1, :readonly => true).readonly?
+ assert !Post.find(1, :readonly => false).readonly?
+ end
end
Post.constrain(:readonly => true) do
@@ -3,19 +3,17 @@
require 'stringio'
if ActiveRecord::Base.connection.respond_to?(:tables)
- unless current_adapter?(:OCIAdapter)
- class SchemaDumperTest < Test::Unit::TestCase
- def test_schema_dump
- stream = StringIO.new
- ActiveRecord::SchemaDumper.dump(ActiveRecord::Base.connection, stream)
- output = stream.string
+ class SchemaDumperTest < Test::Unit::TestCase
+ def test_schema_dump
+ stream = StringIO.new
+ ActiveRecord::SchemaDumper.dump(ActiveRecord::Base.connection, stream)
+ output = stream.string
- assert_match %r{create_table "accounts"}, output
- assert_match %r{create_table "authors"}, output
- assert_no_match %r{create_table "schema_info"}, output
- end
+ assert_match %r{create_table "accounts"}, output
+ assert_match %r{create_table "authors"}, output
+ assert_no_match %r{create_table "schema_info"}, output
end
-
end
+
end

0 comments on commit 68160b3

Please sign in to comment.