Skip to content

schema_dumper throws SyntaxError when column name contains whitespace #16

@odegroot

Description

@odegroot

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.

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