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.

Guidance with parsing CREATE sql for Sql Server #233

@brent-clintel

Description

@brent-clintel

When running rake db:migrate against a SQL Server database I get the following stack trace:

NoMethodError: undefined method `[]' for nil:NilClass
./vendor/ruby/2.1.0/gems/schema_plus_core-1.0.0/lib/schema_plus/core/sql_struct.rb:24:in `parse!'
./vendor/ruby/2.1.0/gems/schema_plus_core-1.0.0/lib/schema_plus/core/active_record/connection_adapters/abstract_adapter.rb:48:in `block in visit_TableDefinition'
...

The sql being parsed is:

CREATE TABLE [schema_migrations] ([version] nvarchar(4000) NOT NULL) 

The regex in the SchemaPlus::Core::SqlStruct#parse! method returns nil because of the brackets used around the table name (possibly amongst other things).

I'm happy to try to fix this my self, but I've never delved into this code base before and have no idea what the purpose of this method is.

I don't actually understand why the sql is being parsed in the first place... there's an assemble method that seems to put all the parts back together... Why? Does the SQL need to be parsed at all?

If nothing more, I'm looking for guidance on how to resolve this:

  • What is the purpose of this method?
  • Why get the parts of the query only to piece it all back together manually?
  • What is the correct way to inject a SQL Server specific implementation?

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