aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/CHANGELOG2
-rw-r--r--activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb4
-rw-r--r--activerecord/lib/active_record/connection_adapters/frontbase_adapter.rb2
-rw-r--r--activerecord/lib/active_record/connection_adapters/oracle_adapter.rb8
-rw-r--r--activerecord/test/defaults_test.rb2
-rw-r--r--activerecord/test/fixtures/db_definitions/oracle.sql17
-rw-r--r--activerecord/test/migration_test.rb39
7 files changed, 66 insertions, 8 deletions
diff --git a/activerecord/CHANGELOG b/activerecord/CHANGELOG
index 94a46d3064..313e9daf10 100644
--- a/activerecord/CHANGELOG
+++ b/activerecord/CHANGELOG
@@ -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]
diff --git a/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb b/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb
index 8a8d956ca8..8891c10c7c 100644
--- a/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb
+++ b/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb
@@ -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
diff --git a/activerecord/lib/active_record/connection_adapters/frontbase_adapter.rb b/activerecord/lib/active_record/connection_adapters/frontbase_adapter.rb
index db9d2ccf3d..cd48978f4e 100644
--- a/activerecord/lib/active_record/connection_adapters/frontbase_adapter.rb
+++ b/activerecord/lib/active_record/connection_adapters/frontbase_adapter.rb
@@ -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/)
diff --git a/activerecord/lib/active_record/connection_adapters/oracle_adapter.rb b/activerecord/lib/active_record/connection_adapters/oracle_adapter.rb
index 53cf2a439a..6a0209fceb 100644
--- a/activerecord/lib/active_record/connection_adapters/oracle_adapter.rb
+++ b/activerecord/lib/active_record/connection_adapters/oracle_adapter.rb
@@ -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:
diff --git a/activerecord/test/defaults_test.rb b/activerecord/test/defaults_test.rb
index cf99978f9e..39dcc82b49 100644
--- a/activerecord/test/defaults_test.rb
+++ b/activerecord/test/defaults_test.rb
@@ -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
diff --git a/activerecord/test/fixtures/db_definitions/oracle.sql b/activerecord/test/fixtures/db_definitions/oracle.sql
index ccf472c905..869c59fb75 100644
--- a/activerecord/test/fixtures/db_definitions/oracle.sql
+++ b/activerecord/test/fixtures/db_definitions/oracle.sql
@@ -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,
diff --git a/activerecord/test/migration_test.rb b/activerecord/test/migration_test.rb
index ce79ffc80e..355c459818 100644
--- a/activerecord/test/migration_test.rb
+++ b/activerecord/test/migration_test.rb
@@ -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
+