juliogarciag / rails-atom-schema

(Unmantained) Atom package to show Rails (Active Record) DB Information
3 stars 4 forks source link

Add a configuration panel where to change the rails binary path #2

Closed zedtux closed 6 years ago

zedtux commented 6 years ago

A configuration UI allowing user to change the rails binary path would be great so that it would be easy to cover some advance cases like using a different Ruby version (rvm 2.3 do command) or Docker.

juliogarciag commented 6 years ago

I added that option in the latest version. (1.1.0) Can you take a look?

zedtux commented 6 years ago

The configuration panel is present, but the package is not working:

screen shot 2017-11-16 at 07 57 36

docker-compose exec reporting bundle exec rails --version
Rails 4.2.7.1

But the rails-atom-schema panel is not showing up.

When I toggle it manually:

screen shot 2017-11-16 at 07 58 38

I found this in the dev panel:

/bundle/gems/ruby-ole-1.2.11.7/lib/ole/types/base.rb:265: warning: duplicated key at line 266 ignored: 4095
Running via Spring preloader in process 54
/application/bin/rails:7: warning: already initialized constant APP_PATH
/bundle/gems/zeus-0.15.14/lib/zeus/rails.rb:10: warning: previous definition of APP_PATH was here
/bundle/gems/railties-4.2.7.1/lib/rails/commands/runner.rb:62:in `eval': /bundle/gems/railties-4.2.7.1/lib/rails/commands/runner.rb:62: unknown regexp options - gllah (SyntaxError)
/bundle/gems/railties-4.2.7.1/lib/rails/commands/runner.rb:62: syntax error, unexpected '.'
/Users/guillaumeh/.atom/packages/rails-atom-sche...
                   ^
    from /bundle/gems/railties-4.2.7.1/lib/rails/commands/runner.rb:62:in `<top (required)>'
    from /bundle/gems/activesupport-4.2.7.1/lib/active_support/dependencies.rb:274:in `require'
    from /bundle/gems/activesupport-4.2.7.1/lib/active_support/dependencies.rb:274:in `block in require'
    from /bundle/gems/activesupport-4.2.7.1/lib/active_support/dependencies.rb:240:in `load_dependency'
    from /bundle/gems/activesupport-4.2.7.1/lib/active_support/dependencies.rb:274:in `require'
    from /bundle/gems/railties-4.2.7.1/lib/rails/commands/commands_tasks.rb:123:in `require_command!'
    from /bundle/gems/railties-4.2.7.1/lib/rails/commands/commands_tasks.rb:90:in `runner'
    from /bundle/gems/railties-4.2.7.1/lib/rails/commands/commands_tasks.rb:39:in `run_command!'
    from /bundle/gems/railties-4.2.7.1/lib/rails/commands.rb:17:in `<top (required)>'
    from /bundle/gems/activesupport-4.2.7.1/lib/active_support/dependencies.rb:274:in `require'
    from /bundle/gems/activesupport-4.2.7.1/lib/active_support/dependencies.rb:274:in `block in require'
    from /bundle/gems/activesupport-4.2.7.1/lib/active_support/dependencies.rb:240:in `load_dependency'
    from /bundle/gems/activesupport-4.2.7.1/lib/active_support/dependencies.rb:274:in `require'
    from /application/bin/rails:9:in `<top (required)>'
    from /bundle/gems/zeus-0.15.14/lib/zeus/load_tracking.rb:82:in `load'
    from /bundle/gems/zeus-0.15.14/lib/zeus/load_tracking.rb:82:in `load'
    from /bundle/gems/zeus-0.15.14/lib/zeus/load_tracking.rb:74:in `load'
    from /bundle/gems/activesupport-4.2.7.1/lib/active_support/dependencies.rb:268:in `block in load'
    from /bundle/gems/activesupport-4.2.7.1/lib/active_support/dependencies.rb:240:in `load_dependency'
    from /bundle/gems/activesupport-4.2.7.1/lib/active_support/dependencies.rb:268:in `load'
    from /usr/local/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
    from /usr/local/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
    from -e:1:in `<main>'
"
juliogarciag commented 6 years ago

@zedtux Does docker-compose exec reporting bundle exec rails runner ~/.atom/packages/rails-atom-schema/lib/ruby-scripts/fetch_schema.rb work from a normal console?

zedtux commented 6 years ago

Nope, I have the following error:

/bundle/gems/railties-4.2.9/lib/rails/commands/runner.rb:62:in `eval': /bundle/gems/railties-4.2.9/lib/rails/commands/runner.rb:62: unknown regexp options - gllaha (SyntaxError)
/bundle/gems/railties-4.2.9/lib/rails/commands/runner.rb:62: syntax error, unexpected '.'
/Users/guillaumehain/.atom/packages/rails-atom-sche...
                      ^
    from /bundle/gems/railties-4.2.9/lib/rails/commands/runner.rb:62:in `<top (required)>'
    from /bundle/gems/railties-4.2.9/lib/rails/commands/commands_tasks.rb:123:in `require'
    from /bundle/gems/railties-4.2.9/lib/rails/commands/commands_tasks.rb:123:in `require_command!'
    from /bundle/gems/railties-4.2.9/lib/rails/commands/commands_tasks.rb:90:in `runner'
    from /bundle/gems/railties-4.2.9/lib/rails/commands/commands_tasks.rb:39:in `run_command!'
    from /bundle/gems/railties-4.2.9/lib/rails/commands.rb:17:in `<top (required)>'
    from bin/rails:4:in `require'
    from bin/rails:4:in `<main>'
juliogarciag commented 6 years ago

Which Rails version are you using? Running rails runner [FILE] is documented Rails behavior: http://guides.rubyonrails.org/command_line.html#rails-runner. Anyway, I think the problem is that somehow the path location is assumed in the rails runner "[CODE]" form although you (and the package) haven't passed doble quotes. Maybe that's a problem of how params are passed by docker-compose.

Anyway, If you can find a way to make rails runner [FILE] work there, I can figure out a way to allow to configure the use case.

zedtux commented 6 years ago

I'm using Rails 4.2.9 and when I use a model from my app, there is no errors (and nothing happen as it is a model without code execution).

If you need to execute your script file lib/ruby-scripts/fetch_schema.rb in the Docker container, then it means it needs to be shared in the container so that the runner command will access it.

zedtux commented 6 years ago

So mounting your package as /rails-atom-schema/ works but produces an error:

$ docker-compose run -v ~/.atom/packages/rails-atom-schema/:/rails-atom-schema/ app bundle exec rails runner /rails-atom-schema/lib/ruby-scripts/fetch_schema.rb
/bundle/gems/activerecord-4.2.9/lib/active_record/connection_adapters/postgresql_adapter.rb:592:in `async_exec': PG::UndefinedTable: ERROR:  relation "wice_grid_serialized_queries" does not exist (ActiveRecord::StatementInvalid)
LINE 5:                WHERE a.attrelid = '"wice_grid_serialized_que...
                                          ^
:               SELECT a.attname, format_type(a.atttypid, a.atttypmod),
                     pg_get_expr(d.adbin, d.adrelid), a.attnotnull, a.atttypid, a.atttypmod
                FROM pg_attribute a LEFT JOIN pg_attrdef d
                  ON a.attrelid = d.adrelid AND a.attnum = d.adnum
               WHERE a.attrelid = '"wice_grid_serialized_queries"'::regclass
                 AND a.attnum > 0 AND NOT a.attisdropped
               ORDER BY a.attnum
    from /bundle/gems/activerecord-4.2.9/lib/active_record/connection_adapters/postgresql_adapter.rb:592:in `block in exec_no_cache'
    from /bundle/gems/activerecord-4.2.9/lib/active_record/connection_adapters/abstract_adapter.rb:484:in `block in log'
    from /bundle/gems/activesupport-4.2.9/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
    from /bundle/gems/activerecord-4.2.9/lib/active_record/connection_adapters/abstract_adapter.rb:478:in `log'
    from /bundle/gems/activerecord-4.2.9/lib/active_record/connection_adapters/postgresql_adapter.rb:592:in `exec_no_cache'
    from /bundle/gems/activerecord-4.2.9/lib/active_record/connection_adapters/postgresql_adapter.rb:584:in `execute_and_clear'
    from /bundle/gems/activerecord-4.2.9/lib/active_record/connection_adapters/postgresql/database_statements.rb:160:in `exec_query'
    from /bundle/gems/activerecord-4.2.9/lib/active_record/connection_adapters/postgresql_adapter.rb:733:in `column_definitions'
    from /bundle/gems/activerecord-4.2.9/lib/active_record/connection_adapters/postgresql/schema_statements.rb:197:in `columns'
    from /bundle/gems/activerecord-4.2.9/lib/active_record/connection_adapters/schema_cache.rb:43:in `columns'
    from /bundle/gems/activerecord-4.2.9/lib/active_record/attributes.rb:93:in `columns'
    from /rails-atom-schema/lib/ruby-scripts/fetch_schema.rb:38:in `serialize_model_columns'
    from /rails-atom-schema/lib/ruby-scripts/fetch_schema.rb:33:in `serialize_model_schema'
    from /rails-atom-schema/lib/ruby-scripts/fetch_schema.rb:20:in `block in model_schemas'
    from /rails-atom-schema/lib/ruby-scripts/fetch_schema.rb:19:in `map'
    from /rails-atom-schema/lib/ruby-scripts/fetch_schema.rb:19:in `model_schemas'
    from /rails-atom-schema/lib/ruby-scripts/fetch_schema.rb:11:in `as_json'
    from /rails-atom-schema/lib/ruby-scripts/fetch_schema.rb:96:in `<top (required)>'
    from /bundle/gems/railties-4.2.9/lib/rails/commands/runner.rb:60:in `load'
    from /bundle/gems/railties-4.2.9/lib/rails/commands/runner.rb:60:in `<top (required)>'
    from /bundle/gems/railties-4.2.9/lib/rails/commands/commands_tasks.rb:123:in `require'
    from /bundle/gems/railties-4.2.9/lib/rails/commands/commands_tasks.rb:123:in `require_command!'
    from /bundle/gems/railties-4.2.9/lib/rails/commands/commands_tasks.rb:90:in `runner'
    from /bundle/gems/railties-4.2.9/lib/rails/commands/commands_tasks.rb:39:in `run_command!'
    from /bundle/gems/railties-4.2.9/lib/rails/commands.rb:17:in `<top (required)>'
    from bin/rails:4:in `require'
    from bin/rails:4:in `<main>'
juliogarciag commented 6 years ago

It may be more complex that I thought. I maybe should allow to edit the entire bin/rails [SCRIPT] command instead to allow for things as complex as mounting a file. About the error you're seing, that's being triggered by Rails itself when calling Model.columns, which should be a safe method to run. If you look closely at you error message, it says that a table wasn't found. Maybe migrations were not run or there was another - more deep - problem.

zedtux commented 6 years ago

I maybe should allow to edit the entire bin/rails [SCRIPT] command instead to allow for things as complex as mounting a file.

Well you could also send the content of the file instead of the file path so that Docker doesn't need to have the Ruby script file mounted.

If you look closely at you error message, it says that a table wasn't found. Maybe migrations were not run or there was another - more deep - problem.

I have already checked, and my db/schema.rb file doesn't have this table. I need to check further.