Skip to content

Instantly share code, notes, and snippets.

@nikushi
Last active August 29, 2015 14:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nikushi/5ace69e8c8ed90561f1c to your computer and use it in GitHub Desktop.
Save nikushi/5ace69e8c8ed90561f1c to your computer and use it in GitHub Desktop.

Yohoushi travis rails if running with Rails 2.2.0:

== 20140501115735 AddPathIndexToNodes: migrating ==============================
-- add_index(:nodes, :path, {:length=>255})
rake aborted!
StandardError: An error has occurred, all later migrations canceled:
Index name 'index_nodes_on_path' on table 'nodes' already 

Rails 4.1.1

$ bundle exec rails -v
Rails 4.1.1
$ bundle exec rake db:drop db:create
$ bundle exec rake db:migrate VERSION=20130605091736
$ sqlite3 db/sqlite3 
sqlite> .schema nodes
CREATE TABLE "nodes" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "type" varchar(255), "path" varchar(768) NOT NULL, "description" varchar(255), "visible" boolean DEFAULT 't' NOT NULL, "complex" boolean, "created_at" datetime, "updated_at" datetime);

  => Index was not created. This is as expected.

Rails 4.2.0

$ bundle exec rails -v
Rails 4.2.0
$ bundle exec rake db:drop db:create
$ bundle exec rake db:migrate VERSION=20130605091736
$ sqlite3 db/sqlite3 
sqlite> .schema nodes
CREATE TABLE "nodes" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "type" varchar, "path" varchar(768) NOT NULL, "description" varchar, "visible" boolean DEFAULT 't' NOT NULL, "complex" boolean, "created_at" datetime, "updated_at" datetime);
CREATE INDEX "index_nodes_on_path" ON "nodes" ("path");

  => Index was created. This breaks 20140501115735 AddPathIndexToNodes

It seemsindex: true option of create_table was fixed in Rails 4.2.0.
http://stackoverflow.com/questions/28199958/does-the-index-option-on-rails-column-migrations-work

@nikushi
Copy link
Author

nikushi commented Feb 19, 2015

I've fixed this problem by yohoushi/yohoushi@cf54a6c.

I've checked the schema after running migration.

4.1.9

mysql

mysql> show create table nodes\G
*************************** 1. row ***************************
       Table: nodes
Create Table: CREATE TABLE `nodes` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `type` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
  `path` varchar(768) COLLATE utf8_unicode_ci NOT NULL,
  `description` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
  `visible` tinyint(1) NOT NULL DEFAULT '1',
  `complex` tinyint(1) DEFAULT NULL,
  `created_at` datetime DEFAULT NULL,
  `updated_at` datetime DEFAULT NULL,
  `ancestry` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
  `ancestry_depth` int(11) DEFAULT '0',
  PRIMARY KEY (`id`),
  KEY `index_nodes_on_path` (`path`(255)),
  KEY `index_nodes_on_type_and_path` (`type`,`path`(255)),
  KEY `index_nodes_on_ancestry` (`ancestry`),
  KEY `index_nodes_on_type_and_ancestry` (`type`,`ancestry`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci
1 row in set (0.00 sec)

sqlite

sqlite> .schema nodes
CREATE TABLE "nodes" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "type" varchar(255), "path" varchar(768) NOT NULL, "description" varchar(255), "visible" boolean DEFAULT 't' NOT NULL, "complex" boolean, "created_at" datetime, "updated_at" datetime, "ancestry" varchar(255), "ancestry_depth" integer DEFAULT 0);
CREATE INDEX "index_nodes_on_ancestry" ON "nodes" ("ancestry");
CREATE INDEX "index_nodes_on_path" ON "nodes" ("path");
CREATE INDEX "index_nodes_on_type_and_ancestry" ON "nodes" ("type", "ancestry");
CREATE INDEX "index_nodes_on_type_and_path" ON "nodes" ("type", "path");

4.2.0

mysql

mysql> show create table nodes\G
*************************** 1. row ***************************
       Table: nodes
Create Table: CREATE TABLE `nodes` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `type` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
  `path` varchar(768) COLLATE utf8_unicode_ci NOT NULL,
  `description` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
  `visible` tinyint(1) NOT NULL DEFAULT '1',
  `complex` tinyint(1) DEFAULT NULL,
  `created_at` datetime DEFAULT NULL,
  `updated_at` datetime DEFAULT NULL,
  `ancestry` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
  `ancestry_depth` int(11) DEFAULT '0',
  PRIMARY KEY (`id`),
  KEY `index_nodes_on_path` (`path`(255)),
  KEY `index_nodes_on_type_and_path` (`type`,`path`(255)),
  KEY `index_nodes_on_ancestry` (`ancestry`),
  KEY `index_nodes_on_type_and_ancestry` (`type`,`ancestry`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci
1 row in set (0.00 sec)

sqlite

sqlite> .schema nodes
CREATE TABLE "nodes" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "type" varchar, "path" varchar(768) NOT NULL, "description" varchar, "visible" boolean DEFAULT 't' NOT NULL, "complex" boolean, "created_at" datetime, "updated_at" datetime, "ancestry" varchar(255), "ancestry_depth" integer DEFAULT 0);
CREATE INDEX "index_nodes_on_ancestry" ON "nodes" ("ancestry");
CREATE INDEX "index_nodes_on_path" ON "nodes" ("path");
CREATE INDEX "index_nodes_on_type_and_ancestry" ON "nodes" ("type", "ancestry");
CREATE INDEX "index_nodes_on_type_and_path" ON "nodes" ("type", "path");

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment