#1103 ✓resolved
Jordan Ritter

:index should be disallowed for Text (and derived) primitive types

Reported by Jordan Ritter | October 22nd, 2009 @ 07:49 PM | in 1.0.0

Currently, DM accepts :index/:unique_index on Text fields, generating SQL that breaks MySQL (and possibly other adapters).

This is because TEXT/CLOBs aren't indexable, at least not in the same way VARCHARs/etc are.

Repro script and output: https://gist.github.com/10314837e3c9da1dcb85

dm-core/next @ f1de567 (from today)

Comments and changes to this ticket

  • Dan Kubb (dkubb)

    Dan Kubb (dkubb) February 2nd, 2010 @ 12:39 PM

    • State changed from “new” to “unconfirmed”
    • Assigned user cleared.
  • Jordan Ritter

    Jordan Ritter February 3rd, 2010 @ 08:58 AM

    This still happens as of today's latest dm-core/master 121d33 w/ MySQL 5.1.41.

    require 'rubygems'
    require 'dm-core'
    DataMapper::Logger.new(STDOUT, :debug)
    DataMapper.setup(:default, "mysql://root@localhost/foo")
    class Foo
        include DataMapper::Resource
        property :id, Serial
        property :foo, Text, :index => true
     ~ (0.000013) SET sql_auto_is_null = 0
     ~ (0.000003) DROP TABLE IF EXISTS `foos`
     ~ (0.000004) SHOW TABLES LIKE 'foos'
     ~ (0.000001) SHOW VARIABLES LIKE 'character_set_connection'
     ~ (0.000006) SHOW VARIABLES LIKE 'collation_connection'
     ~ (0.000002) CREATE TABLE `foos` (`id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, `foo` TEXT, PRIMARY KEY(`id`)) ENGINE = InnoDB CHARACTER SET utf8 COLLATE utf8_general_ci
     ~ (0.000005) CREATE INDEX `index_foos_foo` ON `foos` (`foo`)
     ~ BLOB/TEXT column 'foo' used in key specification without a key length (code: 1170, sql state: 42000, query: CREATE INDEX `index_foos_foo` ON `foos` (`foo`), uri: mysql://root@localhost/foo)
    .../dm-core.git/lib/dm-core/migrations.rb:146:in `execute_non_query': BLOB/TEXT column 'foo' used in key specification without a key length (DataObjects::SyntaxError)
        from .../dm-core.git/lib/dm-core/migrations.rb:146:in `create_model_storage'
        from .../dm-core.git/lib/dm-core/migrations.rb:144:in `each'
        from .../dm-core.git/lib/dm-core/migrations.rb:144:in `create_model_storage'
        from .../dm-core.git/lib/dm-core/adapters/data_objects_adapter.rb:269:in `with_connection'
        from .../dm-core.git/lib/dm-core/migrations.rb:139:in `create_model_storage'
        from .../dm-core.git/lib/dm-core/migrations.rb:1308:in `create_model_storage'
        from .../dm-core.git/lib/dm-core/migrations.rb:1403:in `auto_migrate_up!'
        from .../dm-core.git/lib/dm-core/migrations.rb:45:in `send'
        from .../dm-core.git/lib/dm-core/migrations.rb:45:in `repository_execute'
        from .../dm-core.git/lib/dm-core/model/descendant_set.rb:33:in `each'
        from .../dm-core.git/lib/dm-core/model/descendant_set.rb:33:in `each'
        from .../dm-core.git/lib/dm-core/migrations.rb:44:in `repository_execute'
        from .../dm-core.git/lib/dm-core/migrations.rb:39:in `auto_migrate_up!'
        from .../dm-core.git/lib/dm-core/migrations.rb:22:in `auto_migrate!'
  • Dan Kubb (dkubb)

    Dan Kubb (dkubb) February 4th, 2010 @ 12:05 AM

    • State changed from “unconfirmed” to “resolved”

    (from [0fd658ab5037adf3b1180f787fec5eeee8e3efcf]) Ensure Text can be auto-migrated when :index and :unique_index are true

    [#1103 state:resolved] http://github.com/datamapper/dm-core/commit/0fd658ab5037adf3b1180f7...

  • Dan Kubb (dkubb)

    Dan Kubb (dkubb) February 4th, 2010 @ 12:07 AM

    • Milestone set to 1.0.0
    • Assigned user set to “Dan Kubb (dkubb)”

    This should be resolved in edge dm-core.

    I am curious though, did you work-around this by not using :index and :unique_index?

  • Dan Kubb (dkubb)

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

People watching this ticket

Referenced by