Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

schema_dumper throws SyntaxError when column name contains whitespace #16

Open
odegroot opened this issue Aug 19, 2016 · 1 comment
Open

Comments

@odegroot
Copy link

odegroot commented Aug 19, 2016

Steps to reproduce

  • Create a rails app with a database.
  • Create a table, and put a space in one of the column names. I used PostgreSQL.
  • Run rake db:schema:dump.

Expected

The schema_dumper dumps a schema.rb with a space in the column name.

Actual

The schema_dumper throws a SyntaxError.

+ bundle exec rake db:migrate
rake aborted!
SyntaxError: (eval):1: syntax error, unexpected tSTRING_BEG, expecting keyword_do or '{' or '('
{Name",        limit: 255}
      ^
(eval):1: unterminated string meets end of file
/srv/jenkins/.gem/ruby/gems/schema_plus_core-1.0.2/lib/schema_plus/core/active_record/schema_dumper.rb:78:in `eval'

In this case, the column name was First Name, but it was parsed as name = First with options = Name", limit: 255.

Available workarounds

Remove whitespace from column names.

ALTER TABLE temp_respondents RENAME "First Name" TO "First_Name";

Background info

The error is thrown on this line (https://github.com/SchemaPlus/schema_plus_core/blob/master/lib/schema_plus/core/active_record/schema_dumper.rb#L80), but the bug is in the regex above it: when the column name contains whitespace, it incorrectly only captures part of the column name.

@frogandcode
Copy link

I'm having a similar problem on the same line. The following index:

Indexes:
    "thredded_categories_name_ci" btree (lower(name::text) text_pattern_ops)

is causing db:schema:dump to blow up:

** Execute db:schema:dump
rails aborted!
SyntaxError: (eval):1: syntax error, unexpected tSTRING_BEG, expecting keyword_do or '{' or '('
{text_pattern_ops", name: "thredded_categories_...
                 ^
(eval):1: syntax error, unexpected tIDENTIFIER, expecting end-of-input
...e: "thredded_categories_name_ci"}
...    ^~~~~~~~~~~~~~~~~~~~~~~~~~~
/Users/thornett/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/schema_plus_core-2.1.1/lib/schema_plus/core/active_record/schema_dumper.rb:80:in `eval'
/Users/thornett/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/schema_plus_core-2.1.1/lib/schema_plus/core/active_record/schema_dumper.rb:80:in `block (2 levels) in table'
/Users/thornett/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/schema_plus_core-2.1.1/lib/schema_plus/core/active_record/schema_dumper.rb:69:in `map'
/Users/thornett/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/schema_plus_core-2.1.1/lib/schema_plus/core/active_record/schema_dumper.rb:69:in `block in table'

Presumably the issue is the space in the index declaration necessitated by the text_pattern_ops operator.

This is on Postgres 9.5.6 and Rails 5.1.6.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants