Skip to content

Commit

Permalink
Merge branch 'master' into rails4_merges_master_3rd
Browse files Browse the repository at this point in the history
Conflicts:
	lib/active_record/connection_adapters/oracle_enhanced_schema_statements.rb

Tab character conflicted.
  • Loading branch information
yahonda committed Apr 9, 2013
2 parents 8d98858 + 501debd commit c8aae2a
Show file tree
Hide file tree
Showing 6 changed files with 126 additions and 21 deletions.
21 changes: 18 additions & 3 deletions History.md
@@ -1,4 +1,21 @@
### 1.4.2 / 2012-11-13
### 1.4.2 / 2013-03-18

* No changes since 1.4.2.rc2

### 1.4.2.rc2 / 2013-03-01

* Bug fixes:
* Do not consider the numeric attribute as changed if the old value is zero and the new value is not a string [#247]
* Removed table_name_prefix and table_name_suffix when schema dumper executed [#248]
* Remove_column should raise an ArgumentError when no columns are passed [#246]
* Don't dump type for NUMBER virtual columns [#256]
* Address :returning_id column should be of type Column [#274]
* Migrated versions should be dumped in order [#277]
* Always write serialized LOB columns [#275]
* Truncate the schema_migrations index [#276]
* Split paths on windows machines in the right way [#231]

### 1.4.2.rc1 / 2012-11-13

* Enhancements:
* Wordlist option for context index [#154]
Expand All @@ -12,8 +29,6 @@
* Dump indexes on virtual columns using the column's name instead of the column expression [#211]
* Don't update lobs that haven't changed or are attr_readonly [#212]
* Support dirty tracking with rails 3.2.9
* Do not consider the numeric attribute as changed if the old value is zero and the new value is not a string [#247]
* Removed table_name_prefix and table_name_suffix when schema dumper executed [#248]

### 1.4.1 / 2012-01-27

Expand Down
2 changes: 1 addition & 1 deletion VERSION
@@ -1 +1 @@
1.4.2.rc1
1.4.2
4 changes: 2 additions & 2 deletions activerecord-oracle_enhanced-adapter.gemspec
Expand Up @@ -5,11 +5,11 @@

Gem::Specification.new do |s|
s.name = %q{activerecord-oracle_enhanced-adapter}
s.version = "1.4.2.rc1"
s.version = "1.4.2"

s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = [%q{Raimonds Simanovskis}]
s.date = %q{2012-11-13}
s.date = %q{2013-03-18}
s.description = %q{Oracle "enhanced" ActiveRecord adapter contains useful additional methods for working with new and legacy Oracle databases.
This adapter is superset of original ActiveRecord Oracle adapter.
}
Expand Down
Expand Up @@ -15,7 +15,7 @@

unless ojdbc_jar.nil? || ENV_JAVA['java.class.path'] =~ Regexp.new(ojdbc_jar)
# On Unix environment variable should be PATH, on Windows it is sometimes Path
env_path = (ENV["PATH"] || ENV["Path"] || '').split(/[:;]/)
env_path = (ENV["PATH"] || ENV["Path"] || '').split(File::PATH_SEPARATOR)
# Look for JDBC driver at first in lib subdirectory (application specific JDBC file version)
# then in Ruby load path and finally in environment PATH
if ojdbc_jar_path = ['./lib'].concat($LOAD_PATH).concat(env_path).find{|d| File.exists?(File.join(d,ojdbc_jar))}
Expand Down
Expand Up @@ -22,11 +22,11 @@ module OracleEnhancedSchemaStatements
# end
#
# Create primary key trigger (so that you can skip primary key value in INSERT statement).
# By default trigger name will be "table_name_pkt", you can override the name with
# By default trigger name will be "table_name_pkt", you can override the name with
# :trigger_name option (but it is not recommended to override it as then this trigger will
# not be detected by ActiveRecord model and it will still do prefetching of sequence value).
# Example:
#
#
# create_table :users, :primary_key_trigger => true do |t|
# # ...
# end
Expand All @@ -37,11 +37,11 @@ module OracleEnhancedSchemaStatements
# t.string :first_name, :comment => “Given name”
# t.string :last_name, :comment => “Surname”
# end

def create_table(name, options = {}, &block)
create_sequence = options[:id] != false
column_comments = {}

table_definition = TableDefinition.new(self)
table_definition.primary_key(options[:primary_key] || Base.get_primary_key(name.to_s.singularize)) unless options[:id] == false

Expand Down Expand Up @@ -87,15 +87,15 @@ def column(name, type, options = {})
end
create_sql << " #{options[:options]}"
execute create_sql

create_sequence_and_trigger(name, options) if create_sequence

add_table_comment name, options[:comment]
column_comments.each do |column_name, comment|
add_comment name, column_name, comment
end
table_definition.indexes.each_pair { |c,o| add_index name, c, o }

end

def rename_table(table_name, new_name) #:nodoc:
Expand All @@ -120,6 +120,35 @@ def drop_table(name, options = {}) #:nodoc:
self.all_schema_indexes = nil
end

def initialize_schema_migrations_table
sm_table = ActiveRecord::Migrator.schema_migrations_table_name

unless table_exists?(sm_table)
index_name = "#{Base.table_name_prefix}unique_schema_migrations#{Base.table_name_suffix}"
if index_name.length > index_name_length
truncate_to = index_name_length - index_name.to_s.length - 1
truncated_name = "unique_schema_migrations"[0..truncate_to]
index_name = "#{Base.table_name_prefix}#{truncated_name}#{Base.table_name_suffix}"
end

create_table(sm_table, :id => false) do |schema_migrations_table|
schema_migrations_table.column :version, :string, :null => false
end
add_index sm_table, :version, :unique => true, :name => index_name

# Backwards-compatibility: if we find schema_info, assume we've
# migrated up to that point:
si_table = Base.table_name_prefix + 'schema_info' + Base.table_name_suffix
if table_exists?(si_table)
ActiveSupport::Deprecation.warn "Usage of the schema table `#{si_table}` is deprecated. Please switch to using `schema_migrations` table"

old_version = select_value("SELECT version FROM #{quote_table_name(si_table)}").to_i
assume_migrated_upto_version(old_version)
drop_table(si_table)
end
end
end

# clear cached indexes when adding new index
def add_index(table_name, column_name, options = {}) #:nodoc:
column_names = Array(column_name)
Expand Down Expand Up @@ -192,10 +221,10 @@ def index_name(table_name, options) #:nodoc:
options = {} unless options.is_a?(Hash)
identifier_max_length = options[:identifier_max_length] || index_name_length
return default_name if default_name.length <= identifier_max_length

# remove 'index', 'on' and 'and' keywords
shortened_name = "i_#{table_name}_#{Array(options[:column]) * '_'}"

# leave just first three letters from each word
if shortened_name.length > identifier_max_length
shortened_name = shortened_name.split('_').map{|w| w[0,3]}.join('_')
Expand Down
Expand Up @@ -190,6 +190,7 @@ class ::TestEmployee < ActiveRecord::Base

it "should not generate NoMethodError for :returning_id:Symbol" do
set_logger
@conn.reconnect! unless @conn.active?
insert_id = @conn.insert("INSERT INTO test_employees (first_name) VALUES ('Yasuo')", nil, "id")
@logger.output(:error).should_not match(/^Could not log "sql.active_record" event. NoMethodError: undefined method `name' for :returning_id:Symbol/)
clear_logger
Expand Down Expand Up @@ -322,7 +323,7 @@ def create_test_employees_table(table_comment=nil, column_comments={})
drop_table :test_employees
end
Object.send(:remove_const, "TestEmployee")
ActiveRecord::Base.table_name_prefix = nil
ActiveRecord::Base.table_name_prefix = ''
ActiveRecord::Base.clear_cache! if ActiveRecord::Base.respond_to?(:"clear_cache!")
end

Expand Down Expand Up @@ -545,8 +546,8 @@ class ::TestEmployee < ActiveRecord::Base; end
end

describe "foreign key constraints" do
let(:table_name_prefix) { nil }
let(:table_name_suffix) { nil }
let(:table_name_prefix) { '' }
let(:table_name_suffix) { '' }

before(:each) do
ActiveRecord::Base.table_name_prefix = table_name_prefix
Expand Down Expand Up @@ -576,8 +577,8 @@ class ::TestComment < ActiveRecord::Base
drop_table :test_comments rescue nil
drop_table :test_posts rescue nil
end
ActiveRecord::Base.table_name_prefix = nil
ActiveRecord::Base.table_name_suffix = nil
ActiveRecord::Base.table_name_prefix = ''
ActiveRecord::Base.table_name_suffix = ''
ActiveRecord::Base.clear_cache! if ActiveRecord::Base.respond_to?(:"clear_cache!")
end

Expand Down Expand Up @@ -1317,5 +1318,65 @@ class <<@conn
ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.default_tablespaces.delete(:index)
@would_execute_sql.should =~ /CREATE +INDEX .* ON .* \(.*\) TABLESPACE #{DATABASE_NON_DEFAULT_TABLESPACE}/
end

describe "#initialize_schema_migrations_table" do
# In Rails 2.3 to 3.2.x the index name for the migrations
# table is hard-coded. We can modify the index name here
# so we can support prefixes/suffixes that would
# cause the index to be too long.
#
# Rails 4 can use this solution as well.
after(:each) do
ActiveRecord::Base.table_name_prefix = ''
ActiveRecord::Base.table_name_suffix = ''
end

def add_schema_migrations_index
schema_define do
initialize_schema_migrations_table
end
end

context "without prefix or suffix" do
it "should not truncate the index name" do
add_schema_migrations_index

@would_execute_sql.should include('CREATE UNIQUE INDEX "UNIQUE_SCHEMA_MIGRATIONS" ON "SCHEMA_MIGRATIONS" ("VERSION")')
end
end

context "with prefix" do
before { ActiveRecord::Base.table_name_prefix = 'toolong_' }

it "should truncate the 'unique_schema_migrations' portion of the index name to fit the prefix within the limit" do
add_schema_migrations_index

@would_execute_sql.should include('CREATE UNIQUE INDEX "TOOLONG_UNIQUE_SCHEMA_MIGRATIO" ON "TOOLONG_SCHEMA_MIGRATIONS" ("VERSION")')
end
end

context "with suffix" do
before { ActiveRecord::Base.table_name_suffix = '_toolong' }

it "should truncate the 'unique_schema_migrations' portion of the index name to fit the suffix within the limit" do
add_schema_migrations_index

@would_execute_sql.should include('CREATE UNIQUE INDEX "UNIQUE_SCHEMA_MIGRATIO_TOOLONG" ON "SCHEMA_MIGRATIONS_TOOLONG" ("VERSION")')
end
end

context "with prefix and suffix" do
before do
ActiveRecord::Base.table_name_prefix = 'begin_'
ActiveRecord::Base.table_name_suffix = '_end'
end

it "should truncate the 'unique_schema_migrations' portion of the index name to fit the suffix within the limit" do
add_schema_migrations_index

@would_execute_sql.should include('CREATE UNIQUE INDEX "BEGIN_UNIQUE_SCHEMA_MIGRAT_END" ON "BEGIN_SCHEMA_MIGRATIONS_END" ("VERSION")')
end
end
end
end
end

0 comments on commit c8aae2a

Please sign in to comment.