Ticket #9899: mysql_move_to_schema_migration.diff
| File mysql_move_to_schema_migration.diff, 15.9 kB (added by mikong, 1 year ago) |
|---|
-
test/aaa_create_tables_test.rb
old new 23 23 end 24 24 25 25 def test_drop_and_create_courses_table 26 recreate Course, '2' unless use_migrations ?26 recreate Course, '2' unless use_migrations_for_courses? 27 27 assert true 28 28 end 29 29 30 30 private 31 31 def use_migrations? 32 coursesSQL = ActiveRecord::Base.connection.adapter_name.downcase + "2.sql"33 not File.exists? "#{@base_path}/#{ coursesSQL}"32 unittest_sql_filename = ActiveRecord::Base.connection.adapter_name.downcase + ".sql" 33 not File.exists? "#{@base_path}/#{unittest_sql_filename}" 34 34 end 35 36 def use_migrations_for_courses? 37 unittest2_sql_filename = ActiveRecord::Base.connection.adapter_name.downcase + "2.sql" 38 not File.exists? "#{@base_path}/#{unittest2_sql_filename}" 39 end 35 40 36 41 def recreate(base, suffix = nil) 37 42 connection = base.connection -
test/fixtures/db_definitions/schema.rb
old new 1 1 ActiveRecord::Schema.define do 2 2 3 # adapter name is checked because we are under a transition of 4 # moving the sql files under activerecord/test/fixtures/db_definitions 5 # to this file, schema.rb. 6 if adapter_name == "MySQL" 7 8 create_table :accounts, :force => true do |t| 9 t.column :firm_id, :integer 10 t.column :credit_limit, :integer 11 end 12 13 create_table :funny_jokes, :force => true do |t| 14 t.column :name, :string 15 end 16 17 create_table :companies, :force => true do |t| 18 t.column :type, :string 19 t.column :ruby_type, :string 20 t.column :firm_id, :integer 21 t.column :name, :string 22 t.column :client_of, :integer 23 t.column :rating, :integer, :default => 1 24 end 25 26 create_table :topics, :force => true, :options => 'TYPE=InnoDB DEFAULT CHARSET=utf8' do |t| 27 t.column :title, :string 28 t.column :author_name, :string 29 t.column :author_email_address, :string 30 t.column :written_on, :datetime 31 t.column :bonus_time, :time 32 t.column :last_read, :date 33 t.column :content, :text 34 t.column :approved, :boolean, :default => true 35 t.column :replies_count, :integer, :default => 0 36 t.column :parent_id, :integer 37 t.column :type, :string 38 end 39 40 create_table :developers, :force => true do |t| 41 t.column :name, :string 42 t.column :salary, :integer, :default => 70000 43 t.column :created_at, :datetime 44 t.column :updated_at, :datetime 45 end 46 47 create_table :projects, :force => true do |t| 48 t.column :name, :string 49 t.column :type, :string 50 end 51 52 create_table :developers_projects, :force => true, :id => false do |t| 53 t.column :developer_id, :integer, :null => false 54 t.column :project_id, :integer, :null => false 55 t.column :joined_on, :date 56 t.column :access_level, :integer, :default => 1 57 end 58 59 create_table :orders, :force => true do |t| 60 t.column :name, :string 61 t.column :billing_customer_id, :integer 62 t.column :shipping_customer_id, :integer 63 end 64 65 create_table :customers, :force => true do |t| 66 t.column :name, :string 67 t.column :balance, :integer, :default => 0 68 t.column :address_street, :string 69 t.column :address_city, :string 70 t.column :address_country, :string 71 t.column :gps_location, :string 72 end 73 74 create_table :movies, :force => true, :id => false do |t| 75 t.column :movieid, :primary_key 76 t.column :name, :string 77 end 78 79 create_table :subscribers, :force => true, :id => false do |t| 80 t.column :nick, :string, :null => false 81 t.column :name, :string 82 end 83 add_index :subscribers, :nick, :unique => true 84 85 create_table :booleantests, :force => true do |t| 86 t.column :value, :integer 87 end 88 89 create_table :auto_id_tests, :force => true, :id => false do |t| 90 t.column :auto_id, :primary_key 91 t.column :value, :integer 92 end 93 94 create_table :entrants, :force => true do |t| 95 t.column :name, :string, :null => false 96 t.column :course_id, :integer, :null => false 97 end 98 99 create_table :colnametests, :force => true do |t| 100 t.column :references, :integer, :null => false 101 end 102 103 create_table :mixins, :force => true do |t| 104 t.column :parent_id, :integer 105 t.column :pos, :integer 106 t.column :created_at, :datetime 107 t.column :updated_at, :datetime 108 t.column :lft, :integer 109 t.column :rgt, :integer 110 t.column :root_id, :integer 111 t.column :type, :string 112 end 113 114 create_table :people, :force => true do |t| 115 t.column :first_name, :string, :null => false 116 t.column :lock_version, :integer, :null => false, :default => 0 117 end 118 119 create_table :readers, :force => true do |t| 120 t.column :post_id, :integer, :null => false 121 t.column :person_id, :integer, :null => false 122 end 123 124 create_table :binaries, :force => true do |t| 125 t.column :data, :binary 126 end 127 128 create_table :computers, :force => true do |t| 129 t.column :developer, :integer, :null => false 130 t.column :extendedWarranty, :integer, :null => false 131 end 132 133 create_table :posts, :force => true do |t| 134 t.column :author_id, :integer 135 t.column :title, :string, :null => false 136 t.column :body, :text, :null => false 137 t.column :type, :string 138 end 139 140 create_table :tasks, :force => true do |t| 141 t.column :starting, :datetime, :null => false, :default => '1000-01-01 00:00:00' 142 t.column :ending, :datetime, :null => false, :default => '1000-01-01 00:00:00' 143 end 144 145 create_table :comments, :force => true do |t| 146 t.column :post_id, :integer, :null => false 147 t.column :body, :text, :null => false 148 t.column :type, :string 149 end 150 151 create_table :authors, :force => true do |t| 152 t.column :name, :string, :null => false 153 end 154 155 create_table :categories, :force => true do |t| 156 t.column :name, :string, :null => false 157 t.column :type, :string 158 end 159 160 create_table :categories_posts, :force => true, :id => false do |t| 161 t.column :category_id, :integer, :null => false 162 t.column :post_id, :integer, :null => false 163 end 164 165 # fk_test_has_fk should be before fk_test_has_pk 166 create_table :fk_test_has_fk, :force => true do |t| 167 t.column :fk_id, :integer, :null => false 168 end 169 170 create_table :fk_test_has_pk, :force => true do |t| 171 end 172 173 execute 'alter table fk_test_has_fk 174 add FOREIGN KEY (`fk_id`) REFERENCES `fk_test_has_pk`(`id`)' 175 176 create_table :keyboards, :force => true, :id => false do |t| 177 t.column :key_number, :primary_key 178 t.column :name, :string 179 end 180 181 create_table :legacy_things, :force => true do |t| 182 t.column :tps_report_number, :integer 183 t.column :version, :integer, :null => false, :default => 0 184 end 185 186 create_table :numeric_data, :force => true do |t| 187 t.column :bank_balance, :decimal, :precision => 10, :scale => 2 188 t.column :big_bank_balance, :decimal, :precision => 15, :scale => 2 189 t.column :world_population, :decimal, :precision => 10 190 t.column :my_house_population, :decimal, :precision => 2 191 t.column :decimal_number_with_default, :decimal, :precision => 3, :scale => 2, :default => 2.78 192 end 193 194 create_table :mixed_case_monkeys, :force => true, :id => false do |t| 195 t.column :monkeyID, :primary_key 196 t.column :fleaCount, :integer 197 end 198 199 create_table :minimalistics, :force => true do |t| 200 end 201 end 202 3 203 # For Firebird, set the sequence values 10000 when create_table is called; 4 204 # this prevents primary key collisions between "normally" created records 5 205 # and fixture-based (YAML) records. -
test/fixtures/db_definitions/mysql.sql
old new 1 CREATE TABLE `accounts` (2 `id` int(11) NOT NULL auto_increment,3 `firm_id` int(11) default NULL,4 `credit_limit` int(5) default NULL,5 PRIMARY KEY (`id`)6 ) TYPE=InnoDB;7 8 CREATE TABLE `funny_jokes` (9 `id` int(11) NOT NULL auto_increment,10 `name` varchar(50) default NULL,11 PRIMARY KEY (`id`)12 ) TYPE=InnoDB;13 14 CREATE TABLE `companies` (15 `id` int(11) NOT NULL auto_increment,16 `type` varchar(50) default NULL,17 `ruby_type` varchar(50) default NULL,18 `firm_id` int(11) default NULL,19 `name` varchar(50) default NULL,20 `client_of` int(11) default NULL,21 `rating` int(11) default NULL default 1,22 PRIMARY KEY (`id`)23 ) TYPE=InnoDB;24 25 26 CREATE TABLE `topics` (27 `id` int(11) NOT NULL auto_increment,28 `title` varchar(255) default NULL,29 `author_name` varchar(255) default NULL,30 `author_email_address` varchar(255) default NULL,31 `written_on` datetime default NULL,32 `bonus_time` time default NULL,33 `last_read` date default NULL,34 `content` text,35 `approved` tinyint(1) default 1,36 `replies_count` int(11) default 0,37 `parent_id` int(11) default NULL,38 `type` varchar(50) default NULL,39 PRIMARY KEY (`id`)40 ) TYPE=InnoDB DEFAULT CHARSET=utf8;41 42 CREATE TABLE `developers` (43 `id` int(11) NOT NULL auto_increment,44 `name` varchar(100) default NULL,45 `salary` int(11) default 70000,46 `created_at` datetime default NULL,47 `updated_at` datetime default NULL,48 PRIMARY KEY (`id`)49 ) TYPE=InnoDB;50 51 CREATE TABLE `projects` (52 `id` int(11) NOT NULL auto_increment,53 `name` varchar(100) default NULL,54 `type` VARCHAR(255) default NULL,55 PRIMARY KEY (`id`)56 ) TYPE=InnoDB;57 58 CREATE TABLE `developers_projects` (59 `developer_id` int(11) NOT NULL,60 `project_id` int(11) NOT NULL,61 `joined_on` date default NULL,62 `access_level` smallint default 163 ) TYPE=InnoDB;64 65 CREATE TABLE `orders` (66 `id` int(11) NOT NULL auto_increment,67 `name` varchar(100) default NULL,68 `billing_customer_id` int(11) default NULL,69 `shipping_customer_id` int(11) default NULL,70 PRIMARY KEY (`id`)71 ) TYPE=InnoDB;72 73 CREATE TABLE `customers` (74 `id` int(11) NOT NULL auto_increment,75 `name` varchar(100) default NULL,76 `balance` int(6) default 0,77 `address_street` varchar(100) default NULL,78 `address_city` varchar(100) default NULL,79 `address_country` varchar(100) default NULL,80 `gps_location` varchar(100) default NULL,81 PRIMARY KEY (`id`)82 ) TYPE=InnoDB;83 84 CREATE TABLE `movies` (85 `movieid` int(11) NOT NULL auto_increment,86 `name` varchar(100) default NULL,87 PRIMARY KEY (`movieid`)88 ) TYPE=InnoDB;89 90 CREATE TABLE `subscribers` (91 `nick` varchar(100) NOT NULL,92 `name` varchar(100) default NULL,93 PRIMARY KEY (`nick`)94 ) TYPE=InnoDB;95 96 CREATE TABLE `booleantests` (97 `id` int(11) NOT NULL auto_increment,98 `value` integer default NULL,99 PRIMARY KEY (`id`)100 ) TYPE=InnoDB;101 102 CREATE TABLE `auto_id_tests` (103 `auto_id` int(11) NOT NULL auto_increment,104 `value` integer default NULL,105 PRIMARY KEY (`auto_id`)106 ) TYPE=InnoDB;107 108 CREATE TABLE `entrants` (109 `id` INTEGER NOT NULL auto_increment PRIMARY KEY,110 `name` VARCHAR(255) NOT NULL,111 `course_id` INTEGER NOT NULL112 );113 114 CREATE TABLE `colnametests` (115 `id` int(11) NOT NULL auto_increment,116 `references` int(11) NOT NULL,117 PRIMARY KEY (`id`)118 ) TYPE=InnoDB;119 120 CREATE TABLE `mixins` (121 `id` int(11) NOT NULL auto_increment,122 `parent_id` int(11) default NULL,123 `pos` int(11) default NULL,124 `created_at` datetime default NULL,125 `updated_at` datetime default NULL,126 `lft` int(11) default NULL,127 `rgt` int(11) default NULL,128 `root_id` int(11) default NULL,129 `type` varchar(40) default NULL,130 PRIMARY KEY (`id`)131 ) TYPE=InnoDB;132 133 CREATE TABLE `people` (134 `id` INTEGER NOT NULL auto_increment PRIMARY KEY,135 `first_name` VARCHAR(40) NOT NULL,136 `lock_version` INTEGER NOT NULL DEFAULT 0137 ) TYPE=InnoDB;138 139 CREATE TABLE `readers` (140 `id` int(11) NOT NULL auto_increment PRIMARY KEY,141 `post_id` INTEGER NOT NULL,142 `person_id` INTEGER NOT NULL143 ) TYPE=InnoDB;144 145 CREATE TABLE `binaries` (146 `id` int(11) NOT NULL auto_increment,147 `data` mediumblob,148 PRIMARY KEY (`id`)149 ) TYPE=InnoDB;150 151 CREATE TABLE `computers` (152 `id` INTEGER NOT NULL auto_increment PRIMARY KEY,153 `developer` INTEGER NOT NULL,154 `extendedWarranty` INTEGER NOT NULL155 ) TYPE=InnoDB;156 157 CREATE TABLE `posts` (158 `id` INTEGER NOT NULL auto_increment PRIMARY KEY,159 `author_id` INTEGER,160 `title` VARCHAR(255) NOT NULL,161 `body` TEXT NOT NULL,162 `type` VARCHAR(255) default NULL163 ) TYPE=InnoDB;164 165 CREATE TABLE `comments` (166 `id` INTEGER NOT NULL auto_increment PRIMARY KEY,167 `post_id` INTEGER NOT NULL,168 `body` TEXT NOT NULL,169 `type` VARCHAR(255) default NULL170 ) TYPE=InnoDB;171 172 CREATE TABLE `authors` (173 `id` INTEGER NOT NULL auto_increment PRIMARY KEY,174 `name` VARCHAR(255) NOT NULL175 ) TYPE=InnoDB;176 177 CREATE TABLE `tasks` (178 `id` int(11) NOT NULL auto_increment,179 `starting` datetime NOT NULL default '1000-01-01 00:00:00',180 `ending` datetime NOT NULL default '1000-01-01 00:00:00',181 PRIMARY KEY (`id`)182 ) TYPE=InnoDB;183 184 CREATE TABLE `categories` (185 `id` int(11) NOT NULL auto_increment,186 `name` VARCHAR(255) NOT NULL,187 `type` VARCHAR(255) default NULL,188 PRIMARY KEY (`id`)189 ) TYPE=InnoDB;190 191 CREATE TABLE `categories_posts` (192 `category_id` int(11) NOT NULL,193 `post_id` int(11) NOT NULL194 ) TYPE=InnoDB;195 196 CREATE TABLE `fk_test_has_pk` (197 `id` INTEGER NOT NULL auto_increment PRIMARY KEY198 ) TYPE=InnoDB;199 200 CREATE TABLE `fk_test_has_fk` (201 `id` INTEGER NOT NULL auto_increment PRIMARY KEY,202 `fk_id` INTEGER NOT NULL,203 204 FOREIGN KEY (`fk_id`) REFERENCES `fk_test_has_pk`(`id`)205 ) TYPE=InnoDB;206 207 208 CREATE TABLE `keyboards` (209 `key_number` int(11) NOT NULL auto_increment primary key,210 `name` varchar(50) default NULL211 );212 213 -- Altered lock_version column name.214 CREATE TABLE `legacy_things` (215 `id` int(11) NOT NULL auto_increment,216 `tps_report_number` int(11) default NULL,217 `version` int(11) NOT NULL default 0,218 PRIMARY KEY (`id`)219 ) TYPE=InnoDB;220 221 CREATE TABLE `numeric_data` (222 `id` INTEGER NOT NULL auto_increment PRIMARY KEY,223 `bank_balance` decimal(10,2),224 `big_bank_balance` decimal(15,2),225 `world_population` decimal(10),226 `my_house_population` decimal(2),227 `decimal_number_with_default` decimal(3,2) DEFAULT 2.78228 ) TYPE=InnoDB;229 230 CREATE TABLE mixed_case_monkeys (231 `monkeyID` int(11) NOT NULL auto_increment,232 `fleaCount` int(11),233 PRIMARY KEY (`monkeyID`)234 ) TYPE=InnoDB;235 236 CREATE TABLE `minimalistics` (237 `id` INTEGER NOT NULL auto_increment PRIMARY KEY238 ); -
test/fixtures/db_definitions/mysql.drop.sql
old new 1 DROP TABLE accounts;2 DROP TABLE funny_jokes;3 DROP TABLE companies;4 DROP TABLE topics;5 DROP TABLE developers;6 DROP TABLE projects;7 DROP TABLE developers_projects;8 DROP TABLE customers;9 DROP TABLE orders;10 DROP TABLE movies;11 DROP TABLE subscribers;12 DROP TABLE booleantests;13 DROP TABLE auto_id_tests;14 DROP TABLE entrants;15 DROP TABLE colnametests;16 DROP TABLE mixins;17 DROP TABLE people;18 DROP TABLE readers;19 DROP TABLE binaries;20 DROP TABLE computers;21 DROP TABLE tasks;22 DROP TABLE posts;23 DROP TABLE comments;24 DROP TABLE authors;25 DROP TABLE categories;26 DROP TABLE categories_posts;27 DROP TABLE fk_test_has_fk;28 DROP TABLE fk_test_has_pk;29 DROP TABLE keyboards;30 DROP TABLE legacy_things;31 DROP TABLE numeric_data;32 DROP TABLE mixed_case_monkeys;33 DROP TABLE minimalistics;