Skip to content
This repository was archived by the owner on May 13, 2022. It is now read-only.
This repository was archived by the owner on May 13, 2022. It is now read-only.

doesn't work with annotate gem and MySQL and postgres #221

@dayweek

Description

@dayweek

Hi guys, I have this error when I updated schema_plus from 1.8.9 to 2.0.0

Output:

stark@Tony-Stark ~/Documents/railspool -  $ bundle exec annotate
ActiveRecord::ConnectionAdapters::Mysql2Adapter
Unable to annotate app/models/b/foo.rb: undefined method `query' for #<ActiveRecord::ConnectionAdapters::Mysql2Adapter:0x007f8d7da3fa18>
    /Users/stark/.rvm/gems/ruby-2.1.6@pool/gems/schema_plus_pg_indexes-0.1.4/lib/schema_plus_pg_indexes/middleware/postgresql/schema.rb:39:in `implement'
    /Users/stark/.rvm/gems/ruby-2.1.6@pool/gems/modware-0.1.2/lib/modware/stack.rb:53:in `call_implementation'
    /Users/stark/.rvm/gems/ruby-2.1.6@pool/gems/modware-0.1.2/lib/modware/stack.rb:85:in `_modware_continue'
    /Users/stark/.rvm/gems/ruby-2.1.6@pool/gems/modware-0.1.2/lib/modware/stack.rb:77:in `_modware_call'
    /Users/stark/.rvm/gems/ruby-2.1.6@pool/gems/modware-0.1.2/lib/modware/stack.rb:83:in `_modware_continue'
    /Users/stark/.rvm/gems/ruby-2.1.6@pool/gems/modware-0.1.2/lib/modware/stack.rb:77:in `_modware_call'
    /Users/stark/.rvm/gems/ruby-2.1.6@pool/gems/modware-0.1.2/lib/modware/stack.rb:44:in `execute'
    /Users/stark/.rvm/gems/ruby-2.1.6@pool/gems/modware-0.1.2/lib/modware/stack.rb:20:in `start'
    /Users/stark/.rvm/gems/ruby-2.1.6@pool/gems/schema_monkey-2.1.0/lib/schema_monkey/stack.rb:34:in `start'
    /Users/stark/.rvm/gems/ruby-2.1.6@pool/gems/schema_plus_core-0.5.0/lib/schema_plus/core/active_record/connection_adapters/mysql2_adapter.rb:32:in `indexes'
    /Users/stark/.rvm/gems/ruby-2.1.6@pool/gems/annotate-2.6.10/lib/annotate/annotate_models.rb:216:in `get_index_info'
    /Users/stark/.rvm/gems/ruby-2.1.6@pool/gems/annotate-2.6.10/lib/annotate/annotate_models.rb:193:in `get_schema_info'
    /Users/stark/.rvm/gems/ruby-2.1.6@pool/gems/annotate-2.6.10/lib/annotate/annotate_models.rb:346:in `annotate'
    /Users/stark/.rvm/gems/ruby-2.1.6@pool/gems/annotate-2.6.10/lib/annotate/annotate_models.rb:485:in `annotate_model_file'
    /Users/stark/.rvm/gems/ruby-2.1.6@pool/gems/annotate-2.6.10/lib/annotate/annotate_models.rb:471:in `block in do_annotations'
    /Users/stark/.rvm/gems/ruby-2.1.6@pool/gems/annotate-2.6.10/lib/annotate/annotate_models.rb:470:in `each'
    /Users/stark/.rvm/gems/ruby-2.1.6@pool/gems/annotate-2.6.10/lib/annotate/annotate_models.rb:470:in `do_annotations'
    /Users/stark/.rvm/gems/ruby-2.1.6@pool/gems/annotate-2.6.10/bin/annotate:185:in `<top (required)>'
    /Users/stark/.rvm/gems/ruby-2.1.6@pool/bin/annotate:23:in `load'
    /Users/stark/.rvm/gems/ruby-2.1.6@pool/bin/annotate:23:in `<main>'
    /Users/stark/.rvm/gems/ruby-2.1.6@pool/bin/ruby_executable_hooks:15:in `eval'
    /Users/stark/.rvm/gems/ruby-2.1.6@pool/bin/ruby_executable_hooks:15:in `<main>'
Nothing to annotate.

I have two 2 models: A::Api and B::Foo

so A::Api model is in app/models/a dir and B::Foo is in app/models/b

A::Api model

class A::Api < ActiveRecord::Base
end

B::Foo model

module B
  class Foo < Base
    self.table_name = 'foos'
  end
end

And there is also B::Base in app/models/b

module B
  class Base < ActiveRecord::Base
    self.abstract_class = true

    def self.establish_connection
      if database_url = MYSQL_DATABASE_URL
        uri = URI.parse(database_url)
        super({
          'adapter' => uri.scheme,
          'database' => uri.path.split('/').last,
          'host' => uri.host,
          'username' => uri.user,
          'password' => uri.password,
          'reconnect' => true
        })
      end
    end

    establish_connection
  end
end

MYSQL_DATABASE_URL is set in initializer from env var.

rake task for configuring annotate:

  task :set_annotation_options do
    # Just some example settings from annotate 2.6.0.beta1
    Annotate.set_defaults({
                              'position_in_routes'   => "before",
                              'position_in_class'    => "before",
                              'position_in_test'     => "before",
                              'position_in_fixture'  => "before",
                              'position_in_factory'  => "before",
                              'show_indexes'         => "true", # if false it works
                              'simple_indexes'       => "false",
                              'model_dir'            => "app/models",
                              'include_version'      => "false",
                              'require'              => "",
                              'exclude_tests'        => "true",
                              'exclude_fixtures'     => "false",
                              'exclude_factories'    => "false",
                              'ignore_model_sub_dir' => "false",
                              'skip_on_db_migrate'   => "false",
                              'format_bare'          => "true",
                              'format_rdoc'          => "false",
                              'format_markdown'      => "false",
                              'sort'                 => "true",
                              'force'                => "false",
                              'trace'                => "true",
                          })
  end

Basically A::Api connects to postgres by default (database.yml) and B::Foo connects to MySQL. When I remove schema_plus gem, or downgrade it to 1.8.9 or set show_indexes to false in the task it works. So I assume it is an issue in schema_plus (schema_plus_pg_indexes perhaps?). The order in which the models are annotated is important in order to reproduce this.

Environment:

  * schema_auto_foreign_keys (0.1.0)
  * schema_monkey (2.1.0)
  * schema_plus (2.0.0)
  * schema_plus_columns (0.1.0)
  * schema_plus_core (0.5.0)
  * schema_plus_db_default (0.1.0)
  * schema_plus_default_expr (0.1.0)
  * schema_plus_enums (0.1.0)
  * schema_plus_foreign_keys (0.1.2)
  * schema_plus_indexes (0.2.0)
  * schema_plus_pg_indexes (0.1.4)
  * schema_plus_tables (0.1.0)
  * schema_plus_views (0.2.3)
  * mysql2 (0.3.18)
  * rails (4.2.3)
  * annotate (2.6.10)
  * pg (0.18.2)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions