findmypast-oss / mssql_ecto

Ecto adapter for Mssqlex
Apache License 2.0
49 stars 20 forks source link

App created with phx.new test --database mssql won't compile #26

Closed damonvjanis closed 7 years ago

damonvjanis commented 7 years ago

I've created a new Phoenix 1.3 app with phx.new test --database mssql (which configures the app by default to use mssql_ecto and mssqlex), which I would expect to work out of the box or get me close to a working Phoenix app connected to mssql.

Right after creating the app, if I try to run mix phx.server, it attempts to compile the dependencies and it fails to compile with the following error:

== Compilation error in file lib/mssql_ecto/query_string.ex ==
** (CompileError) lib/mssql_ecto/query_string.ex:251: unknown key :fields for struct Ecto.SubQuery
    lib/mssql_ecto/query_string.ex:251: (module)

This is happening whether I try it in Mac OS or Windows, and regardless of the database configuration.

My goal is to get a test application running that successfully connects to a test SQL Server database on my local machine. I'm expecting to play around with the configuration for a bit but this compilation error is getting in the way of even starting to work with the config.

My environment

shdblowers commented 7 years ago

Hi @damonvjanis

Even with using mssql_ecto with the Phoenix command you also have to follow the installation instructions in the Readme. Specifically to do with installing Erlang ODBC and Microsoft's ODBC Driver.

shdblowers commented 7 years ago

After doing this please let me know if you still cannot get it working.

damonvjanis commented 7 years ago

@shdblowers thanks for taking a look at this.

I apologize, I should have included those details in the original request.

Before running mix phx.new, I had verified that Erlang ODBC was accessible on my system by opening an Erlang shell and entering 1>odbc.start() which returned a response of ok.

I had also previously verified that my environment had the Microsoft ODBC driver by attempting to install the driver (version 13) from the download page, and when it went to install the system informed me that I already had the current version installed. I double-checked by navigating to the 64 bit ODBC application in Windows, selecting the Drivers tab, and the driver was listed.

I've done a little more digging on the issue and here's what I'm finding:

In mssql_ecto/lib/mssql_ecto/query_string line 251, there is a key value pair fields: fields. This is what was throwing the compile error. I took a look in Ecto for where %Ecto.SubQuery{} was being defined, and it's in ecto/lib/ecto/query.ex. On line 5, the struct is defined with the following: defstruct [:query, :params, :select, :cache].

The error is happening because :fields is not on that list. I looked through the GitHub history and found that line 5 changed on August 4th, removing :fields (link to history here).

I was able to get around the compile error by changing fields: fields to params: fields in mssql_ecto/query_string.ex, and I was able to successfully connect to my database. I don't understand Ecto, MSSQL_Ecto or Elixir at a deep enough level to know what the correct fix is, but if I have some time I'll dive into the details and see if I can be more confident in proposing a solution.

jbachhardie commented 7 years ago

I think this is related to https://github.com/findmypast-oss/mssql_ecto/issues/25, right @shdblowers ?

We're not quite there yet with Ecto 2.2 compatibility and I believe the template scaffolds up that version. You should be able to downgrade to Ecto 2.1.x and have everything work.

shdblowers commented 7 years ago

Yes I think so too @jbachhardie.

Will release a patch for this version that changes the dependency on ecto from 2.1 to 2.1.0, which should make this issue more clear.

Will also continue on upgrading to 2.2 when I can

shdblowers commented 7 years ago

That's been done now, here: https://github.com/findmypast-oss/mssql_ecto/commit/ae2d5671e84787e3be8a9248f5c83211d819c0cc