aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test
diff options
context:
space:
mode:
Diffstat (limited to 'activerecord/test')
-rw-r--r--activerecord/test/aaa_create_tables_test.rb14
-rw-r--r--activerecord/test/fixtures/db_definitions/mysql.drop.sql33
-rwxr-xr-xactiverecord/test/fixtures/db_definitions/mysql.sql238
-rw-r--r--activerecord/test/fixtures/db_definitions/mysql2.drop.sql2
-rw-r--r--activerecord/test/fixtures/db_definitions/mysql2.sql5
-rw-r--r--activerecord/test/fixtures/db_definitions/schema.rb209
-rw-r--r--activerecord/test/fixtures/db_definitions/schema2.rb11
7 files changed, 231 insertions, 281 deletions
diff --git a/activerecord/test/aaa_create_tables_test.rb b/activerecord/test/aaa_create_tables_test.rb
index b5feee1d2a..3db6cb52d0 100644
--- a/activerecord/test/aaa_create_tables_test.rb
+++ b/activerecord/test/aaa_create_tables_test.rb
@@ -23,14 +23,22 @@ class AAACreateTablesTest < Test::Unit::TestCase
end
def test_drop_and_create_courses_table
- recreate Course, '2' unless use_migrations?
+ if Course.connection.supports_migrations?
+ eval(File.read("#{File.dirname(__FILE__)}/fixtures/db_definitions/schema2.rb"))
+ end
+ recreate Course, '2' unless use_migrations_for_courses?
assert true
end
private
def use_migrations?
- coursesSQL = ActiveRecord::Base.connection.adapter_name.downcase + "2.sql"
- not File.exists? "#{@base_path}/#{coursesSQL}"
+ unittest_sql_filename = ActiveRecord::Base.connection.adapter_name.downcase + ".sql"
+ not File.exists? "#{@base_path}/#{unittest_sql_filename}"
+ end
+
+ def use_migrations_for_courses?
+ unittest2_sql_filename = ActiveRecord::Base.connection.adapter_name.downcase + "2.sql"
+ not File.exists? "#{@base_path}/#{unittest2_sql_filename}"
end
def recreate(base, suffix = nil)
diff --git a/activerecord/test/fixtures/db_definitions/mysql.drop.sql b/activerecord/test/fixtures/db_definitions/mysql.drop.sql
deleted file mode 100644
index 419cdaa52c..0000000000
--- a/activerecord/test/fixtures/db_definitions/mysql.drop.sql
+++ /dev/null
@@ -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 customers;
-DROP TABLE orders;
-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 tasks;
-DROP TABLE posts;
-DROP TABLE comments;
-DROP TABLE authors;
-DROP TABLE categories;
-DROP TABLE categories_posts;
-DROP TABLE fk_test_has_fk;
-DROP TABLE fk_test_has_pk;
-DROP TABLE keyboards;
-DROP TABLE legacy_things;
-DROP TABLE numeric_data;
-DROP TABLE mixed_case_monkeys;
-DROP TABLE minimalistics;
diff --git a/activerecord/test/fixtures/db_definitions/mysql.sql b/activerecord/test/fixtures/db_definitions/mysql.sql
deleted file mode 100755
index a2195a4f5a..0000000000
--- a/activerecord/test/fixtures/db_definitions/mysql.sql
+++ /dev/null
@@ -1,238 +0,0 @@
-CREATE TABLE `accounts` (
- `id` int(11) NOT NULL auto_increment,
- `firm_id` int(11) default NULL,
- `credit_limit` int(5) default NULL,
- PRIMARY KEY (`id`)
-) TYPE=InnoDB;
-
-CREATE TABLE `funny_jokes` (
- `id` int(11) NOT NULL auto_increment,
- `name` varchar(50) default NULL,
- PRIMARY KEY (`id`)
-) TYPE=InnoDB;
-
-CREATE TABLE `companies` (
- `id` int(11) NOT NULL auto_increment,
- `type` varchar(50) default NULL,
- `ruby_type` varchar(50) default NULL,
- `firm_id` int(11) default NULL,
- `name` varchar(50) default NULL,
- `client_of` int(11) default NULL,
- `rating` int(11) default NULL default 1,
- PRIMARY KEY (`id`)
-) TYPE=InnoDB;
-
-
-CREATE TABLE `topics` (
- `id` int(11) NOT NULL auto_increment,
- `title` varchar(255) default NULL,
- `author_name` varchar(255) default NULL,
- `author_email_address` varchar(255) default NULL,
- `written_on` datetime default NULL,
- `bonus_time` time default NULL,
- `last_read` date default NULL,
- `content` text,
- `approved` tinyint(1) default 1,
- `replies_count` int(11) default 0,
- `parent_id` int(11) default NULL,
- `type` varchar(50) default NULL,
- PRIMARY KEY (`id`)
-) TYPE=InnoDB DEFAULT CHARSET=utf8;
-
-CREATE TABLE `developers` (
- `id` int(11) NOT NULL auto_increment,
- `name` varchar(100) default NULL,
- `salary` int(11) default 70000,
- `created_at` datetime default NULL,
- `updated_at` datetime default NULL,
- PRIMARY KEY (`id`)
-) TYPE=InnoDB;
-
-CREATE TABLE `projects` (
- `id` int(11) NOT NULL auto_increment,
- `name` varchar(100) default NULL,
- `type` VARCHAR(255) default NULL,
- PRIMARY KEY (`id`)
-) TYPE=InnoDB;
-
-CREATE TABLE `developers_projects` (
- `developer_id` int(11) NOT NULL,
- `project_id` int(11) NOT NULL,
- `joined_on` date default NULL,
- `access_level` smallint default 1
-) TYPE=InnoDB;
-
-CREATE TABLE `orders` (
- `id` int(11) NOT NULL auto_increment,
- `name` varchar(100) default NULL,
- `billing_customer_id` int(11) default NULL,
- `shipping_customer_id` int(11) default NULL,
- PRIMARY KEY (`id`)
-) TYPE=InnoDB;
-
-CREATE TABLE `customers` (
- `id` int(11) NOT NULL auto_increment,
- `name` varchar(100) default NULL,
- `balance` int(6) 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`)
-) TYPE=InnoDB;
-
-CREATE TABLE `movies` (
- `movieid` int(11) NOT NULL auto_increment,
- `name` varchar(100) default NULL,
- PRIMARY KEY (`movieid`)
-) TYPE=InnoDB;
-
-CREATE TABLE `subscribers` (
- `nick` varchar(100) NOT NULL,
- `name` varchar(100) default NULL,
- PRIMARY KEY (`nick`)
-) TYPE=InnoDB;
-
-CREATE TABLE `booleantests` (
- `id` int(11) NOT NULL auto_increment,
- `value` integer default NULL,
- PRIMARY KEY (`id`)
-) TYPE=InnoDB;
-
-CREATE TABLE `auto_id_tests` (
- `auto_id` int(11) NOT NULL auto_increment,
- `value` integer default NULL,
- PRIMARY KEY (`auto_id`)
-) TYPE=InnoDB;
-
-CREATE TABLE `entrants` (
- `id` INTEGER NOT NULL auto_increment PRIMARY KEY,
- `name` VARCHAR(255) NOT NULL,
- `course_id` INTEGER NOT NULL
-);
-
-CREATE TABLE `colnametests` (
- `id` int(11) NOT NULL auto_increment,
- `references` int(11) NOT NULL,
- PRIMARY KEY (`id`)
-) TYPE=InnoDB;
-
-CREATE TABLE `mixins` (
- `id` int(11) NOT NULL auto_increment,
- `parent_id` int(11) default NULL,
- `pos` int(11) default NULL,
- `created_at` datetime default NULL,
- `updated_at` datetime default NULL,
- `lft` int(11) default NULL,
- `rgt` int(11) default NULL,
- `root_id` int(11) default NULL,
- `type` varchar(40) default NULL,
- PRIMARY KEY (`id`)
-) TYPE=InnoDB;
-
-CREATE TABLE `people` (
- `id` INTEGER NOT NULL auto_increment PRIMARY KEY,
- `first_name` VARCHAR(40) NOT NULL,
- `lock_version` INTEGER NOT NULL DEFAULT 0
-) TYPE=InnoDB;
-
-CREATE TABLE `readers` (
- `id` int(11) NOT NULL auto_increment PRIMARY KEY,
- `post_id` INTEGER NOT NULL,
- `person_id` INTEGER NOT NULL
-) TYPE=InnoDB;
-
-CREATE TABLE `binaries` (
- `id` int(11) NOT NULL auto_increment,
- `data` mediumblob,
- PRIMARY KEY (`id`)
-) TYPE=InnoDB;
-
-CREATE TABLE `computers` (
- `id` INTEGER NOT NULL auto_increment PRIMARY KEY,
- `developer` INTEGER NOT NULL,
- `extendedWarranty` INTEGER NOT NULL
-) TYPE=InnoDB;
-
-CREATE TABLE `posts` (
- `id` INTEGER NOT NULL auto_increment PRIMARY KEY,
- `author_id` INTEGER,
- `title` VARCHAR(255) NOT NULL,
- `body` TEXT NOT NULL,
- `type` VARCHAR(255) default NULL
-) TYPE=InnoDB;
-
-CREATE TABLE `comments` (
- `id` INTEGER NOT NULL auto_increment PRIMARY KEY,
- `post_id` INTEGER NOT NULL,
- `body` TEXT NOT NULL,
- `type` VARCHAR(255) default NULL
-) TYPE=InnoDB;
-
-CREATE TABLE `authors` (
- `id` INTEGER NOT NULL auto_increment PRIMARY KEY,
- `name` VARCHAR(255) NOT NULL
-) TYPE=InnoDB;
-
-CREATE TABLE `tasks` (
- `id` int(11) NOT NULL auto_increment,
- `starting` datetime NOT NULL default '1000-01-01 00:00:00',
- `ending` datetime NOT NULL default '1000-01-01 00:00:00',
- PRIMARY KEY (`id`)
-) TYPE=InnoDB;
-
-CREATE TABLE `categories` (
- `id` int(11) NOT NULL auto_increment,
- `name` VARCHAR(255) NOT NULL,
- `type` VARCHAR(255) default NULL,
- PRIMARY KEY (`id`)
-) TYPE=InnoDB;
-
-CREATE TABLE `categories_posts` (
- `category_id` int(11) NOT NULL,
- `post_id` int(11) NOT NULL
-) TYPE=InnoDB;
-
-CREATE TABLE `fk_test_has_pk` (
- `id` INTEGER NOT NULL auto_increment PRIMARY KEY
-) TYPE=InnoDB;
-
-CREATE TABLE `fk_test_has_fk` (
- `id` INTEGER NOT NULL auto_increment PRIMARY KEY,
- `fk_id` INTEGER NOT NULL,
-
- FOREIGN KEY (`fk_id`) REFERENCES `fk_test_has_pk`(`id`)
-) TYPE=InnoDB;
-
-
-CREATE TABLE `keyboards` (
- `key_number` int(11) NOT NULL auto_increment primary key,
- `name` varchar(50) default NULL
-);
-
--- Altered lock_version column name.
-CREATE TABLE `legacy_things` (
- `id` int(11) NOT NULL auto_increment,
- `tps_report_number` int(11) default NULL,
- `version` int(11) NOT NULL default 0,
- PRIMARY KEY (`id`)
-) TYPE=InnoDB;
-
-CREATE TABLE `numeric_data` (
- `id` INTEGER NOT NULL auto_increment 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
-) TYPE=InnoDB;
-
-CREATE TABLE mixed_case_monkeys (
- `monkeyID` int(11) NOT NULL auto_increment,
- `fleaCount` int(11),
- PRIMARY KEY (`monkeyID`)
-) TYPE=InnoDB;
-
-CREATE TABLE `minimalistics` (
- `id` INTEGER NOT NULL auto_increment PRIMARY KEY
-);
diff --git a/activerecord/test/fixtures/db_definitions/mysql2.drop.sql b/activerecord/test/fixtures/db_definitions/mysql2.drop.sql
deleted file mode 100644
index df00ffd7c9..0000000000
--- a/activerecord/test/fixtures/db_definitions/mysql2.drop.sql
+++ /dev/null
@@ -1,2 +0,0 @@
-DROP TABLE courses;
-
diff --git a/activerecord/test/fixtures/db_definitions/mysql2.sql b/activerecord/test/fixtures/db_definitions/mysql2.sql
deleted file mode 100644
index 0bfd2e6fca..0000000000
--- a/activerecord/test/fixtures/db_definitions/mysql2.sql
+++ /dev/null
@@ -1,5 +0,0 @@
-CREATE TABLE `courses` (
- `id` INTEGER NOT NULL PRIMARY KEY,
- `name` VARCHAR(255) NOT NULL
-) TYPE=InnoDB;
-
diff --git a/activerecord/test/fixtures/db_definitions/schema.rb b/activerecord/test/fixtures/db_definitions/schema.rb
index 52cd9f36f0..88f99f51ac 100644
--- a/activerecord/test/fixtures/db_definitions/schema.rb
+++ b/activerecord/test/fixtures/db_definitions/schema.rb
@@ -1,5 +1,214 @@
ActiveRecord::Schema.define do
+ # adapter name is checked because we are under a transition of
+ # moving the sql files under activerecord/test/fixtures/db_definitions
+ # to this file, schema.rb.
+ if adapter_name == "MySQL"
+
+ # Please keep these create table statements in alphabetical order
+ # unless the ordering matters. In which case, define them below
+ create_table :accounts, :force => true do |t|
+ t.integer :firm_id
+ t.integer :credit_limit
+ end
+
+ create_table :authors, :force => true do |t|
+ t.string :name, :null => false
+ end
+
+ create_table :auto_id_tests, :force => true, :id => false do |t|
+ t.primary_key :auto_id
+ t.integer :value
+ end
+
+ create_table :binaries, :force => true do |t|
+ t.binary :data
+ end
+
+ create_table :booleantests, :force => true do |t|
+ t.integer :value
+ end
+
+ create_table :categories, :force => true do |t|
+ t.string :name, :null => false
+ t.string :type
+ end
+
+ create_table :categories_posts, :force => true, :id => false do |t|
+ t.integer :category_id, :null => false
+ t.integer :post_id, :null => false
+ end
+
+ create_table :colnametests, :force => true do |t|
+ t.integer :references, :null => false
+ end
+
+ create_table :comments, :force => true do |t|
+ t.integer :post_id, :null => false
+ t.text :body, :null => false
+ t.string :type
+ end
+
+ create_table :companies, :force => true do |t|
+ t.string :type
+ t.string :ruby_type
+ t.integer :firm_id
+ t.string :name
+ t.integer :client_of
+ t.integer :rating, :default => 1
+ end
+
+ create_table :computers, :force => true do |t|
+ t.integer :developer, :null => false
+ t.integer :extendedWarranty, :null => false
+ end
+
+
+ create_table :customers, :force => true do |t|
+ t.string :name
+ t.integer :balance, :default => 0
+ t.string :address_street
+ t.string :address_city
+ t.string :address_country
+ t.string :gps_location
+ end
+
+ create_table :developers, :force => true do |t|
+ t.string :name
+ t.integer :salary, :default => 70000
+ t.datetime :created_at
+ t.datetime :updated_at
+ end
+
+ create_table :developers_projects, :force => true, :id => false do |t|
+ t.integer :developer_id, :null => false
+ t.integer :project_id, :null => false
+ t.date :joined_on
+ t.integer :access_level, :default => 1
+ end
+
+ create_table :entrants, :force => true do |t|
+ t.string :name, :null => false
+ t.integer :course_id, :null => false
+ end
+
+ create_table :funny_jokes, :force => true do |t|
+ t.string :name
+ end
+
+ create_table :keyboards, :force => true, :id => false do |t|
+ t.primary_key :key_number
+ t.string :name
+ end
+
+ create_table :legacy_things, :force => true do |t|
+ t.integer :tps_report_number
+ t.integer :version, :null => false, :default => 0
+ end
+
+ create_table :minimalistics, :force => true do |t|
+ end
+
+ create_table :mixed_case_monkeys, :force => true, :id => false do |t|
+ t.primary_key :monkeyID
+ t.integer :fleaCount
+ end
+
+ create_table :mixins, :force => true do |t|
+ t.integer :parent_id
+ t.integer :pos
+ t.datetime :created_at
+ t.datetime :updated_at
+ t.integer :lft
+ t.integer :rgt
+ t.integer :root_id
+ t.string :type
+ end
+
+ create_table :movies, :force => true, :id => false do |t|
+ t.primary_key :movieid
+ t.string :name
+ end
+
+ create_table :numeric_data, :force => true do |t|
+ t.decimal :bank_balance, :precision => 10, :scale => 2
+ t.decimal :big_bank_balance, :precision => 15, :scale => 2
+ t.decimal :world_population, :precision => 10, :scale => 0
+ t.decimal :my_house_population, :precision => 2, :scale => 0
+ t.decimal :decimal_number_with_default, :precision => 3, :scale => 2, :default => 2.78
+ end
+
+ create_table :orders, :force => true do |t|
+ t.string :name
+ t.integer :billing_customer_id
+ t.integer :shipping_customer_id
+ end
+
+ create_table :people, :force => true do |t|
+ t.string :first_name, :null => false
+ t.integer :lock_version, :null => false, :default => 0
+ end
+
+ create_table :posts, :force => true do |t|
+ t.integer :author_id
+ t.string :title, :null => false
+ t.text :body, :null => false
+ t.string :type
+ end
+
+ create_table :projects, :force => true do |t|
+ t.string :name
+ t.string :type
+ end
+
+ create_table :readers, :force => true do |t|
+ t.integer :post_id, :null => false
+ t.integer :person_id, :null => false
+ end
+
+ create_table :subscribers, :force => true, :id => false do |t|
+ t.string :nick, :null => false
+ t.string :name
+ end
+ add_index :subscribers, :nick, :unique => true
+
+ create_table :tasks, :force => true do |t|
+ t.datetime :starting
+ t.datetime :ending
+ end
+
+ create_table :topics, :force => true do |t|
+ t.string :title
+ t.string :author_name
+ t.string :author_email_address
+ t.datetime :written_on
+ t.time :bonus_time
+ t.date :last_read
+ t.text :content
+ t.boolean :approved, :default => true
+ t.integer :replies_count, :default => 0
+ t.integer :parent_id
+ t.string :type
+ end
+
+
+
+ ### These tables are created last as the order is significant
+
+ # fk_test_has_fk should be before fk_test_has_pk
+ create_table :fk_test_has_fk, :force => true do |t|
+ t.integer :fk_id, :null => false
+ end
+
+ create_table :fk_test_has_pk, :force => true do |t|
+ end
+
+ execute 'alter table fk_test_has_fk
+ add FOREIGN KEY (`fk_id`) REFERENCES `fk_test_has_pk`(`id`)'
+
+
+ end
+
# For Firebird, set the sequence values 10000 when create_table is called;
# this prevents primary key collisions between "normally" created records
# and fixture-based (YAML) records.
diff --git a/activerecord/test/fixtures/db_definitions/schema2.rb b/activerecord/test/fixtures/db_definitions/schema2.rb
new file mode 100644
index 0000000000..863237d271
--- /dev/null
+++ b/activerecord/test/fixtures/db_definitions/schema2.rb
@@ -0,0 +1,11 @@
+ActiveRecord::Schema.define do
+
+ # adapter name is checked because we are under a transition of
+ # moving the sql files under activerecord/test/fixtures/db_definitions
+ # to this file, schema.rb.
+ if adapter_name == "MySQL"
+ Course.connection.create_table :courses, :force => true do |t|
+ t.column :name, :string, :null => false
+ end
+ end
+end