Permalink
Browse files

Use schema.rb for all databases

Move adapter specific schema into their own files

Signed-off-by: Michael Koziarski <michael@koziarski.com>
  • Loading branch information...
1 parent 0a94f16 commit a4fc93c3a9f59dcd7cf56c6ae1cb1fb749f6678b @fcheung fcheung committed with NZKoz Apr 21, 2008
Showing with 432 additions and 2,928 deletions.
  1. +1 −1 activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
  2. +7 −51 activerecord/test/cases/aaa_create_tables_test.rb
  3. +1 −1 activerecord/test/cases/associations/has_many_through_associations_test.rb
  4. +1 −1 activerecord/test/cases/associations_test.rb
  5. +1 −1 activerecord/test/cases/base_test.rb
  6. +0 −33 activerecord/test/schema/db2.drop.sql
  7. +0 −235 activerecord/test/schema/db2.sql
  8. +0 −1 activerecord/test/schema/db22.drop.sql
  9. +0 −4 activerecord/test/schema/db22.sql
  10. +0 −65 activerecord/test/schema/firebird.drop.sql
  11. +0 −310 activerecord/test/schema/firebird.sql
  12. +0 −2 activerecord/test/schema/firebird2.drop.sql
  13. +0 −6 activerecord/test/schema/firebird2.sql
  14. +0 −33 activerecord/test/schema/frontbase.drop.sql
  15. +0 −273 activerecord/test/schema/frontbase.sql
  16. +0 −1 activerecord/test/schema/frontbase2.drop.sql
  17. +0 −4 activerecord/test/schema/frontbase2.sql
  18. +12 −0 activerecord/test/schema/mysql_specific_schema.rb
  19. +0 −2 activerecord/test/schema/openbase.drop.sql
  20. +0 −318 activerecord/test/schema/openbase.sql
  21. +0 −2 activerecord/test/schema/openbase2.drop.sql
  22. +0 −7 activerecord/test/schema/openbase2.sql
  23. +0 −67 activerecord/test/schema/oracle.drop.sql
  24. +0 −330 activerecord/test/schema/oracle.sql
  25. +0 −2 activerecord/test/schema/oracle2.drop.sql
  26. +0 −6 activerecord/test/schema/oracle2.sql
  27. +0 −44 activerecord/test/schema/postgresql.drop.sql
  28. +0 −294 activerecord/test/schema/postgresql.sql
  29. +0 −1 activerecord/test/schema/postgresql2.drop.sql
  30. +0 −4 activerecord/test/schema/postgresql2.sql
  31. +103 −0 activerecord/test/schema/postgresql_specific_schema.rb
  32. +274 −301 activerecord/test/schema/schema.rb
  33. +2 −7 activerecord/test/schema/schema2.rb
  34. +0 −33 activerecord/test/schema/sqlite.drop.sql
  35. +0 −219 activerecord/test/schema/sqlite.sql
  36. +0 −1 activerecord/test/schema/sqlite2.drop.sql
  37. +0 −4 activerecord/test/schema/sqlite2.sql
  38. +25 −0 activerecord/test/schema/sqlite_specific_schema.rb
  39. +5 −0 activerecord/test/schema/sqlserver_specific_schema.rb
  40. +0 −35 activerecord/test/schema/sybase.drop.sql
  41. +0 −222 activerecord/test/schema/sybase.sql
  42. +0 −2 activerecord/test/schema/sybase2.drop.sql
  43. +0 −5 activerecord/test/schema/sybase2.sql
@@ -617,7 +617,7 @@ def reset_pk_sequence!(table, pk = nil, sequence = nil) #:nodoc:
quoted_sequence = quote_column_name(sequence)
select_value <<-end_sql, 'Reset sequence'
- 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)
+ 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)
end_sql
else
@logger.warn "#{table} has primary key #{pk} with no default sequence" if @logger
@@ -4,65 +4,21 @@
class AAACreateTablesTest < ActiveRecord::TestCase
self.use_transactional_fixtures = false
- def test_drop_and_create_main_tables
- recreate ActiveRecord::Base unless use_migrations?
- assert true
- end
-
def test_load_schema
- if ActiveRecord::Base.connection.supports_migrations?
- eval(File.read(SCHEMA_ROOT + "/schema.rb"))
- else
- recreate ActiveRecord::Base, '3'
+ eval(File.read(SCHEMA_ROOT + "/schema.rb"))
+ if File.exists?(adapter_specific_schema_file)
+ eval(File.read(adapter_specific_schema_file))
end
assert true
end
def test_drop_and_create_courses_table
- if Course.connection.supports_migrations?
- eval(File.read(SCHEMA_ROOT + "/schema2.rb"))
- end
- recreate Course, '2' unless use_migrations_for_courses?
+ eval(File.read(SCHEMA_ROOT + "/schema2.rb"))
assert true
end
private
- def use_migrations?
- unittest_sql_filename = ActiveRecord::Base.connection.adapter_name.downcase + ".sql"
- not File.exist? SCHEMA_ROOT + "/#{unittest_sql_filename}"
- end
-
- def use_migrations_for_courses?
- unittest2_sql_filename = ActiveRecord::Base.connection.adapter_name.downcase + "2.sql"
- not File.exist? SCHEMA_ROOT + "/#{unittest2_sql_filename}"
- end
-
- def recreate(base, suffix = nil)
- connection = base.connection
- adapter_name = connection.adapter_name.downcase + suffix.to_s
- execute_sql_file SCHEMA_ROOT + "/#{adapter_name}.drop.sql", connection
- execute_sql_file SCHEMA_ROOT + "/#{adapter_name}.sql", connection
- end
-
- def execute_sql_file(path, connection)
- # OpenBase has a different format for sql files
- if current_adapter?(:OpenBaseAdapter) then
- File.read(path).split("go").each_with_index do |sql, i|
- begin
- # OpenBase does not support comments embedded in sql
- connection.execute(sql,"SQL statement ##{i}") unless sql.blank?
- rescue ActiveRecord::StatementInvalid
- #$stderr.puts "warning: #{$!}"
- end
- end
- else
- File.read(path).split(';').each_with_index do |sql, i|
- begin
- connection.execute("\n\n-- statement ##{i}\n#{sql}\n") unless sql.blank?
- rescue ActiveRecord::StatementInvalid
- #$stderr.puts "warning: #{$!}"
- end
- end
- end
- end
+ def adapter_specific_schema_file
+ SCHEMA_ROOT + '/' + ActiveRecord::Base.connection.adapter_name.downcase + '_specific_schema.rb'
+ end
end
@@ -25,7 +25,7 @@ def test_associating_new
new_person = nil # so block binding catches it
assert_queries(0) do
- new_person = Person.new
+ new_person = Person.new :first_name => 'bob'
end
# Associating new records always saves them
@@ -41,7 +41,7 @@ def test_bad_collection_keys
end
def test_should_construct_new_finder_sql_after_create
- person = Person.new
+ person = Person.new :first_name => 'clark'
assert_equal [], person.readers.find(:all)
person.save!
reader = Reader.create! :person => person, :post => Post.new(:title => "foo", :body => "bar")
@@ -1704,7 +1704,7 @@ def test_find_on_abstract_base_class_doesnt_use_type_condition
old_class = LooseDescendant
Object.send :remove_const, :LooseDescendant
- descendant = old_class.create!
+ descendant = old_class.create! :first_name => 'bob'
assert_not_nil LoosePerson.find(descendant.id), "Should have found instance of LooseDescendant when finding abstract LoosePerson: #{descendant.inspect}"
ensure
unless Object.const_defined?(:LooseDescendant)
@@ -1,33 +0,0 @@
-DROP TABLE accounts;
-DROP TABLE funny_jokes;
-DROP TABLE companies;
-DROP TABLE topics;
-DROP TABLE developers;
-DROP TABLE projects;
-DROP TABLE developers_projects;
-DROP TABLE orders;
-DROP TABLE customers;
-DROP TABLE movies;
-DROP TABLE subscribers;
-DROP TABLE booleantests;
-DROP TABLE auto_id_tests;
-DROP TABLE entrants;
-DROP TABLE colnametests;
-DROP TABLE mixins;
-DROP TABLE people;
-DROP TABLE readers;
-DROP TABLE binaries;
-DROP TABLE computers;
-DROP TABLE posts;
-DROP TABLE comments;
-DROP TABLE authors;
-DROP TABLE tasks;
-DROP TABLE categories;
-DROP TABLE categories_posts;
-DROP TABLE fk_test_has_pk;
-DROP TABLE fk_test_has_fk;
-DROP TABLE keyboards;
-DROP TABLE legacy_things;
-DROP TABLE numeric_data;
-DROP TABLE mixed_case_monkeys;
-DROP TABLE minimalistics;
@@ -1,235 +0,0 @@
-CREATE TABLE accounts (
- id INT GENERATED BY DEFAULT AS IDENTITY (START WITH 10000),
- firm_id INT DEFAULT NULL,
- credit_limit INT DEFAULT NULL,
- PRIMARY KEY (id)
-);
-
-CREATE TABLE funny_jokes (
- id INT GENERATED BY DEFAULT AS IDENTITY (START WITH 10000),
- name VARCHAR(50) DEFAULT NULL,
- PRIMARY KEY (id)
-);
-
-CREATE TABLE companies (
- id INT GENERATED BY DEFAULT AS IDENTITY (START WITH 10000),
- type VARCHAR(50) DEFAULT NULL,
- ruby_type VARCHAR(50) DEFAULT NULL,
- firm_id INT DEFAULT NULL,
- name VARCHAR(50) DEFAULT NULL,
- client_of INT DEFAULT NULL,
- rating INT DEFAULT 1,
- PRIMARY KEY (id)
-);
-
-CREATE TABLE topics (
- id INT GENERATED BY DEFAULT AS IDENTITY (START WITH 10000),
- title VARCHAR(255) DEFAULT NULL,
- author_name VARCHAR(255) DEFAULT NULL,
- author_email_address VARCHAR(255) DEFAULT NULL,
- written_on TIMESTAMP DEFAULT NULL,
- bonus_time TIME DEFAULT NULL,
- last_read DATE DEFAULT NULL,
- content VARCHAR(3000),
- approved SMALLINT DEFAULT 1,
- replies_count INT DEFAULT 0,
- parent_id INT DEFAULT NULL,
- type VARCHAR(50) DEFAULT NULL,
- PRIMARY KEY (id)
-);
-
-CREATE TABLE developers (
- id INT GENERATED BY DEFAULT AS IDENTITY (START WITH 10000),
- name VARCHAR(100) DEFAULT NULL,
- salary INT DEFAULT 70000,
- created_at TIMESTAMP DEFAULT NULL,
- updated_at TIMESTAMP DEFAULT NULL,
- PRIMARY KEY (id)
-);
-
-CREATE TABLE projects (
- id INT GENERATED BY DEFAULT AS IDENTITY (START WITH 10000),
- name VARCHAR(100) DEFAULT NULL,
- type VARCHAR(255) DEFAULT NULL,
- PRIMARY KEY (id)
-);
-
-CREATE TABLE developers_projects (
- developer_id INT NOT NULL,
- project_id INT NOT NULL,
- joined_on DATE DEFAULT NULL,
- access_level SMALLINT DEFAULT 1
-);
-
-CREATE TABLE orders (
- id INT GENERATED BY DEFAULT AS IDENTITY (START WITH 10000),
- name VARCHAR(100) DEFAULT NULL,
- billing_customer_id INT DEFAULT NULL,
- shipping_customer_id INT DEFAULT NULL,
- PRIMARY KEY (id)
-);
-
-CREATE TABLE customers (
- id INT GENERATED BY DEFAULT AS IDENTITY (START WITH 10000),
- name VARCHAR(100) DEFAULT NULL,
- balance INT DEFAULT 0,
- address_street VARCHAR(100) DEFAULT NULL,
- address_city VARCHAR(100) DEFAULT NULL,
- address_country VARCHAR(100) DEFAULT NULL,
- gps_location VARCHAR(100) DEFAULT NULL,
- PRIMARY KEY (id)
-);
-
-CREATE TABLE movies (
- movieid INT GENERATED BY DEFAULT AS IDENTITY (START WITH 10000),
- name VARCHAR(100) DEFAULT NULL,
- PRIMARY KEY (movieid)
-);
-
-CREATE TABLE subscribers (
- nick VARCHAR(100) NOT NULL,
- name VARCHAR(100) DEFAULT NULL,
- PRIMARY KEY (nick)
-);
-
-CREATE TABLE booleantests (
- id INT GENERATED BY DEFAULT AS IDENTITY (START WITH 10000),
- value INT DEFAULT NULL,
- PRIMARY KEY (id)
-);
-
-CREATE TABLE auto_id_tests (
- auto_id INT GENERATED BY DEFAULT AS IDENTITY (START WITH 10000),
- value INT DEFAULT NULL,
- PRIMARY KEY (auto_id)
-);
-
-CREATE TABLE entrants (
- id INT NOT NULL PRIMARY KEY,
- name VARCHAR(255) NOT NULL,
- course_id INT NOT NULL
-);
-
-CREATE TABLE colnametests (
- id INT GENERATED BY DEFAULT AS IDENTITY (START WITH 10000),
- references INT NOT NULL,
- PRIMARY KEY (id)
-);
-
-CREATE TABLE mixins (
- id INT GENERATED BY DEFAULT AS IDENTITY (START WITH 10000),
- parent_id INT DEFAULT NULL,
- pos INT DEFAULT NULL,
- created_at TIMESTAMP DEFAULT NULL,
- updated_at TIMESTAMP DEFAULT NULL,
- lft INT DEFAULT NULL,
- rgt INT DEFAULT NULL,
- root_id INT DEFAULT NULL,
- type VARCHAR(40) DEFAULT NULL,
- PRIMARY KEY (id)
-);
-
-CREATE TABLE people (
- id INT GENERATED BY DEFAULT AS IDENTITY (START WITH 10000),
- first_name VARCHAR(40) NOT NULL,
- lock_version INT DEFAULT 0,
- PRIMARY KEY (id)
-);
-
-CREATE TABLE readers (
- id INT GENERATED BY DEFAULT AS IDENTITY (START WITH 10000),
- post_id INT NOT NULL,
- person_id INT NOT NULL,
- PRIMARY KEY (id)
-);
-
-CREATE TABLE binaries (
- id INT GENERATED BY DEFAULT AS IDENTITY (START WITH 10000),
- data BLOB(50000),
- PRIMARY KEY (id)
-);
-
-CREATE TABLE computers (
- id INT GENERATED BY DEFAULT AS IDENTITY (START WITH 10000),
- developer INT NOT NULL,
- extendedWarranty INT NOT NULL
-);
-
-CREATE TABLE posts (
- id INT GENERATED BY DEFAULT AS IDENTITY (START WITH 10000),
- author_id INT DEFAULT NULL,
- title VARCHAR(255) DEFAULT NULL,
- type VARCHAR(255) DEFAULT NULL,
- body VARCHAR(3000) DEFAULT NULL
-);
-
-CREATE TABLE comments (
- id INT GENERATED BY DEFAULT AS IDENTITY (START WITH 10000),
- post_id INT DEFAULT NULL,
- type VARCHAR(255) DEFAULT NULL,
- body VARCHAR(3000) DEFAULT NULL
-);
-
-CREATE TABLE authors (
- id INT GENERATED BY DEFAULT AS IDENTITY (START WITH 10000),
- name VARCHAR(255) DEFAULT NULL
-);
-
-CREATE TABLE tasks (
- id INT GENERATED BY DEFAULT AS IDENTITY (START WITH 10000),
- starting TIMESTAMP DEFAULT NULL,
- ending TIMESTAMP DEFAULT NULL
-);
-
-CREATE TABLE categories (
- id INT GENERATED BY DEFAULT AS IDENTITY (START WITH 10000),
- name VARCHAR(255) NOT NULL,
- type VARCHAR(40) DEFAULT NULL
-);
-
-CREATE TABLE categories_posts (
- category_id INT NOT NULL,
- post_id INT NOT NULL
-);
-
-CREATE TABLE keyboards (
- key_number INT GENERATED BY DEFAULT AS IDENTITY (START WITH 10000),
- name VARCHAR(255)
-);
-
-CREATE TABLE fk_test_has_pk (
- id INT NOT NULL PRIMARY KEY
-);
-
-CREATE TABLE fk_test_has_fk (
- id INT NOT NULL PRIMARY KEY,
- fk_id INT NOT NULL,
-
- FOREIGN KEY (fk_id) REFERENCES fk_test_has_pk(id)
-);
-
---This table has an altered lock_version column name
-CREATE TABLE legacy_things (
- id INT GENERATED BY DEFAULT AS IDENTITY (START WITH 10000),
- tps_report_number INT DEFAULT NULL,
- version INT DEFAULT 0,
- PRIMARY KEY (id)
-);
-
-CREATE TABLE numeric_data (
- id INT NOT NULL PRIMARY KEY,
- bank_balance DECIMAL(10,2),
- big_bank_balance DECIMAL(15,2),
- world_population DECIMAL(10),
- my_house_population DECIMAL(2),
- decimal_number_with_default DECIMAL(3,2) DEFAULT 2.78
-);
-
-CREATE TABLE mixed_case_monkeys (
- monkeyID INT NOT NULL PRIMARY KEY,
- fleaCount INT
-);
-
-CREATE TABLE minimalistics (
- id INT NOT NULL PRIMARY KEY
-);
@@ -1 +0,0 @@
-DROP TABLE courses;
@@ -1,4 +0,0 @@
-CREATE TABLE courses (
- id INT NOT NULL PRIMARY KEY,
- name VARCHAR(255) NOT NULL
-);
Oops, something went wrong. Retry.

0 comments on commit a4fc93c

Please sign in to comment.