Oracle: create_table takes a :sequence_name option to override the 'tablename_seq' default. Closes #7000.

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@5933 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
Jeremy Kemper 2007-01-15 00:34:43 +00:00
parent 9ccb12a3dd
commit e310344111
7 changed files with 66 additions and 8 deletions

View File

@ -1,5 +1,7 @@
*SVN*
* Oracle: create_table takes a :sequence_name option to override the 'tablename_seq' default. #7000 [Michael Schoen]
* MySQL: retain SSL settings on reconnect. #6976 [randyv2]
* Apply scoping during initialize instead of create. Fixes setting of foreign key when using find_or_initialize_by with scoping. [Cody Fauser]

View File

@ -94,7 +94,7 @@ module ActiveRecord
yield table_definition
if options[:force]
drop_table(name) rescue nil
drop_table(name, options) rescue nil
end
create_sql = "CREATE#{' TEMPORARY' if options[:temporary]} TABLE "
@ -112,7 +112,7 @@ module ActiveRecord
end
# Drops a table from the database.
def drop_table(name)
def drop_table(name, options = {})
execute "DROP TABLE #{name}"
end

View File

@ -778,7 +778,7 @@ module ActiveRecord
end
# Drops a table from the database.
def drop_table(name)
def drop_table(name, options = {})
execute "DROP TABLE #{name} RESTRICT"
rescue ActiveRecord::StatementInvalid => e
raise e unless e.message.match(/Referenced TABLE - \w* - does not exist/)

View File

@ -351,7 +351,8 @@ begin
def create_table(name, options = {}) #:nodoc:
super(name, options)
execute "CREATE SEQUENCE #{name}_seq START WITH 10000" unless options[:id] == false
seq_name = options[:sequence_name] || "#{name}_seq"
execute "CREATE SEQUENCE #{seq_name} START WITH 10000" unless options[:id] == false
end
def rename_table(name, new_name) #:nodoc:
@ -359,9 +360,10 @@ begin
execute "RENAME #{name}_seq TO #{new_name}_seq" rescue nil
end
def drop_table(name) #:nodoc:
def drop_table(name, options = {}) #:nodoc:
super(name)
execute "DROP SEQUENCE #{name}_seq" rescue nil
seq_name = options[:sequence_name] || "#{name}_seq"
execute "DROP SEQUENCE #{seq_name}" rescue nil
end
def remove_index(table_name, options = {}) #:nodoc:

View File

@ -46,7 +46,7 @@ class DefaultTest < Test::Unit::TestCase
end
end
if current_adapter?(:PostgreSQLAdapter, :SQLServerAdapter, :FirebirdAdapter, :OpenBaseAdapter)
if current_adapter?(:PostgreSQLAdapter, :SQLServerAdapter, :FirebirdAdapter, :OpenBaseAdapter, :OracleAdapter)
def test_default_integers
default = Default.new
assert_instance_of Fixnum, default.positive_integer

View File

@ -137,6 +137,23 @@ create table booleantests (
);
create sequence booleantests_seq minvalue 10000;
CREATE TABLE defaults (
id integer not null,
modified_date date default sysdate,
modified_date_function date default sysdate,
fixed_date date default to_date('2004-01-01', 'YYYY-MM-DD'),
modified_time date default sysdate,
modified_time_function date default sysdate,
fixed_time date default TO_DATE('2004-01-01 00:00:00', 'YYYY-MM-DD HH24:MI:SS'),
char1 varchar2(1) default 'Y',
char2 varchar2(50) default 'a varchar field',
char3 clob default 'a text field',
positive_integer integer default 1,
negative_integer integer default -1,
decimal_number number(3,2) default 2.78
);
create sequence defaults_seq minvalue 10000;
create table auto_id_tests (
auto_id integer not null,
value integer default null,

View File

@ -700,6 +700,43 @@ if ActiveRecord::Base.connection.supports_migrations?
assert_equal 2, ActiveRecord::Migrator.current_version
end
def test_create_table_with_custom_sequence_name
return unless current_adapter? :OracleAdapter
# table name is 29 chars, the standard sequence name will
# be 33 chars and fail
assert_raises(ActiveRecord::StatementInvalid) do
begin
Person.connection.create_table :table_with_name_thats_just_ok do |t|
t.column :foo, :string, :null => false
end
ensure
Person.connection.drop_table :table_with_name_thats_just_ok rescue nil
end
end
# should be all good w/ a custom sequence name
assert_nothing_raised do
begin
Person.connection.create_table :table_with_name_thats_just_ok,
:sequence_name => 'suitably_short_seq' do |t|
t.column :foo, :string, :null => false
end
Person.connection.execute("select suitably_short_seq.nextval from dual")
ensure
Person.connection.drop_table :table_with_name_thats_just_ok,
:sequence_name => 'suitably_short_seq' rescue nil
end
end
# confirm the custom sequence got dropped
assert_raises(ActiveRecord::StatementInvalid) do
Person.connection.execute("select suitably_short_seq.nextval from dual")
end
end
end
end