Skip to content

Commit a4fc93c

Browse files
fcheungNZKoz
authored andcommitted
Use schema.rb for all databases
Move adapter specific schema into their own files Signed-off-by: Michael Koziarski <[email protected]>
1 parent 0a94f16 commit a4fc93c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+432
-2928
lines changed

activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -617,7 +617,7 @@ def reset_pk_sequence!(table, pk = nil, sequence = nil) #:nodoc:
617617
quoted_sequence = quote_column_name(sequence)
618618

619619
select_value <<-end_sql, 'Reset sequence'
620-
SELECT setval('#{sequence}', (SELECT COALESCE(MAX(#{pk})+(SELECT increment_by FROM #{quoted_sequence}), (SELECT min_value FROM #{quoted_sequence})) FROM #{quote_table_name(table)}), false)
620+
SELECT setval('#{quoted_sequence}', (SELECT COALESCE(MAX(#{quote_column_name pk})+(SELECT increment_by FROM #{quoted_sequence}), (SELECT min_value FROM #{quoted_sequence})) FROM #{quote_table_name(table)}), false)
621621
end_sql
622622
else
623623
@logger.warn "#{table} has primary key #{pk} with no default sequence" if @logger

activerecord/test/cases/aaa_create_tables_test.rb

Lines changed: 7 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -4,65 +4,21 @@
44
class AAACreateTablesTest < ActiveRecord::TestCase
55
self.use_transactional_fixtures = false
66

7-
def test_drop_and_create_main_tables
8-
recreate ActiveRecord::Base unless use_migrations?
9-
assert true
10-
end
11-
127
def test_load_schema
13-
if ActiveRecord::Base.connection.supports_migrations?
14-
eval(File.read(SCHEMA_ROOT + "/schema.rb"))
15-
else
16-
recreate ActiveRecord::Base, '3'
8+
eval(File.read(SCHEMA_ROOT + "/schema.rb"))
9+
if File.exists?(adapter_specific_schema_file)
10+
eval(File.read(adapter_specific_schema_file))
1711
end
1812
assert true
1913
end
2014

2115
def test_drop_and_create_courses_table
22-
if Course.connection.supports_migrations?
23-
eval(File.read(SCHEMA_ROOT + "/schema2.rb"))
24-
end
25-
recreate Course, '2' unless use_migrations_for_courses?
16+
eval(File.read(SCHEMA_ROOT + "/schema2.rb"))
2617
assert true
2718
end
2819

2920
private
30-
def use_migrations?
31-
unittest_sql_filename = ActiveRecord::Base.connection.adapter_name.downcase + ".sql"
32-
not File.exist? SCHEMA_ROOT + "/#{unittest_sql_filename}"
33-
end
34-
35-
def use_migrations_for_courses?
36-
unittest2_sql_filename = ActiveRecord::Base.connection.adapter_name.downcase + "2.sql"
37-
not File.exist? SCHEMA_ROOT + "/#{unittest2_sql_filename}"
38-
end
39-
40-
def recreate(base, suffix = nil)
41-
connection = base.connection
42-
adapter_name = connection.adapter_name.downcase + suffix.to_s
43-
execute_sql_file SCHEMA_ROOT + "/#{adapter_name}.drop.sql", connection
44-
execute_sql_file SCHEMA_ROOT + "/#{adapter_name}.sql", connection
45-
end
46-
47-
def execute_sql_file(path, connection)
48-
# OpenBase has a different format for sql files
49-
if current_adapter?(:OpenBaseAdapter) then
50-
File.read(path).split("go").each_with_index do |sql, i|
51-
begin
52-
# OpenBase does not support comments embedded in sql
53-
connection.execute(sql,"SQL statement ##{i}") unless sql.blank?
54-
rescue ActiveRecord::StatementInvalid
55-
#$stderr.puts "warning: #{$!}"
56-
end
57-
end
58-
else
59-
File.read(path).split(';').each_with_index do |sql, i|
60-
begin
61-
connection.execute("\n\n-- statement ##{i}\n#{sql}\n") unless sql.blank?
62-
rescue ActiveRecord::StatementInvalid
63-
#$stderr.puts "warning: #{$!}"
64-
end
65-
end
66-
end
67-
end
21+
def adapter_specific_schema_file
22+
SCHEMA_ROOT + '/' + ActiveRecord::Base.connection.adapter_name.downcase + '_specific_schema.rb'
23+
end
6824
end

activerecord/test/cases/associations/has_many_through_associations_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def test_associating_new
2525
new_person = nil # so block binding catches it
2626

2727
assert_queries(0) do
28-
new_person = Person.new
28+
new_person = Person.new :first_name => 'bob'
2929
end
3030

3131
# Associating new records always saves them

activerecord/test/cases/associations_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def test_bad_collection_keys
4141
end
4242

4343
def test_should_construct_new_finder_sql_after_create
44-
person = Person.new
44+
person = Person.new :first_name => 'clark'
4545
assert_equal [], person.readers.find(:all)
4646
person.save!
4747
reader = Reader.create! :person => person, :post => Post.new(:title => "foo", :body => "bar")

activerecord/test/cases/base_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1704,7 +1704,7 @@ def test_find_on_abstract_base_class_doesnt_use_type_condition
17041704
old_class = LooseDescendant
17051705
Object.send :remove_const, :LooseDescendant
17061706

1707-
descendant = old_class.create!
1707+
descendant = old_class.create! :first_name => 'bob'
17081708
assert_not_nil LoosePerson.find(descendant.id), "Should have found instance of LooseDescendant when finding abstract LoosePerson: #{descendant.inspect}"
17091709
ensure
17101710
unless Object.const_defined?(:LooseDescendant)

activerecord/test/schema/db2.drop.sql

Lines changed: 0 additions & 33 deletions
This file was deleted.

activerecord/test/schema/db2.sql

Lines changed: 0 additions & 235 deletions
This file was deleted.

activerecord/test/schema/db22.drop.sql

Lines changed: 0 additions & 1 deletion
This file was deleted.

activerecord/test/schema/db22.sql

Lines changed: 0 additions & 4 deletions
This file was deleted.

0 commit comments

Comments
 (0)