-
Notifications
You must be signed in to change notification settings - Fork 20
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
Upgrade to Ecto 2.2 #34
Conversation
Hi @josevalim, I gave upgrading to Ecto 2.2 another go today, came up against a problem and am hoping you can provide assistance. Here is the error I am getting:
It looks like Ecto 2.2 has introduced the type Unfortunately MS SQL Server does not have an equivalent of this field type, previously this conversion was working for us:
However, only one field can have the identity property per table, leading to the error you see above. I am not sure how to proceed here, as MS SQL Server does not have |
any thoughts @jbachhardie ? |
I think the sanest course of action is to push the limitations of the database server back to the user. We already map There are, of course, workarounds, like using |
In Ecto serial/bigserial is meant to be used once, so the semantics you
defined fit perfectly. Mapping bigserial to bigint should be enough.
--
*José Valimwww.plataformatec.com.br
<http://www.plataformatec.com.br/>Founder and Director of R&D*
|
I have implemented the changes described in elixir-ecto/ecto#2155 and also added code to handle Fortunately, the test suite is running to completion, unfortunately there is a whole host of errors which can be seen in the Travis CI build log. Any help fixing them will be appreciated as I am stuck on them, or at least I was at 10pm last night 😄 . |
@shdblowers I have a fix that is coming in a couple minutes. :) |
@shdblowers here we go: https://github.com/josevalim/mssql_ecto/commit/d4eb1d861e2e4ac7d2ee120ad2351ca1e46eaf36 Summary of changes:
All unit tests should pass. I did not run the integration ones. Feel free to cherry pick the commit and do whatever you want with it. :) |
test/test_helper.exs
Outdated
%Ecto.Query{} = query -> query # Ecto v2.1 and previous | ||
end | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There should be a final \n at the end of each file.
Thanks very much for the help @josevalim, I have cherry picked your commit into the branch and all the unit tests are fixed! 🎉 There are still a few issues with the integration tests, I think the main one being that statements with returning that send back the id return it as a string rather than integer, which I need to investigate further. Also, it would probably be a good idea to re-sync the integration tests with those in Ecto, once that is done I think we'll be ready to support 2.2 😄. |
OK, so it looks like the issue is that queries which use Haven't managed to figure out where I need to make the change to fix this issue, but will carry on with it on another day. |
That's probably because |
Yeah I think that's the reason also. I wonder if then the behaviour should either be: A. we attempt to parse returning B. leave the functionality as is and document this behaviour in the README. |
@jbachhardie is the root issue odbc not understanding that bigint is an int? Since it worked for ints, i am thinking the information is available, but we are not using it? Is odbc capable of returning the types once a query is made? @shdblowers question: why did you copy the integration tests to mssql repo? Wouldn't it be better to run the ecto repo integration tests instead and use tags to skip what doesn't make sense for mssql? |
The OTP To be honest I don't think it would even be that much work to make OTP support the full current ODBC types but volunteers with knowledge of C and Erlang's build system are in short supply. |
I cannot help with the C part of things but I can help with the Erlang's build system one. If anyone needs help on getting started there, please let me know or ping me on IRC. Meanwhile, I think documenting that it will return strings on schemaless queries is a fair enough compromise. |
@josevalim with copying the integration tests into our repo, if I remember correctly, it was because some of the tests required slightly tweaking to get it to work of SQL Server and we preferred it passing with a slight tweak than just skipping the test completely. I'd definitely like to get back to requiring them from the deps folder. I'm also not sure on the value of a test that required tweaking to get it to pass. Will look at doing that as part of the PR as new tests have been added since we copied them over from Ecto. |
assert u1.id | ||
post = TestRepo.get!(from(Post, preload: [:users]), post.id) | ||
[u1, u2] = Enum.sort_by(post.users, & &1.id) | ||
[u1, u2] = post.users |> Enum.sort_by(& &1.id) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use a function call when a pipeline is only one function long
@@ -368,10 +445,10 @@ defmodule Ecto.Integration.AssocTest do | |||
]) | |||
|
|||
post = TestRepo.update!(changeset) | |||
[u1, _u2] = Enum.sort_by(post.users, & &1.id) | |||
[u1, _u2] = post.users |> Enum.sort_by(& &1.id) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use a function call when a pipeline is only one function long
assert c1.id | ||
assert c1.post_id == post.id | ||
post = TestRepo.get!(from(Post, preload: [:comments]), post.id) | ||
[c1, c2] = Enum.sort_by(post.comments, & &1.id) | ||
[c1, c2] = post.comments |> Enum.sort_by(& &1.id) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use a function call when a pipeline is only one function long
@@ -281,11 +358,11 @@ defmodule Ecto.Integration.AssocTest do | |||
]) | |||
|
|||
post = TestRepo.update!(changeset) | |||
[c1, _c2] = Enum.sort_by(post.comments, & &1.id) | |||
[c1, _c2] = post.comments |> Enum.sort_by(& &1.id) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use a function call when a pipeline is only one function long
Ebert has finished reviewing this Pull Request and has found:
You can see more details about this review at https://ebertapp.io/github/findmypast-oss/mssql_ecto/pulls/34. |
Quick question that comes to mind: the :odbc adapter doesn't return the types from the query? So we can do the casting in Elixir land? |
@josevalim {:selected, ['test'], [["123456789012345678901234567890123456"]]} with the query type, column names and column values coming back. |
@jbachhardie @josevalim I have finished with re-syncing the integration tests, taking a similar policy to what was done when we first made this library, i.e. preferring to slightly alter the tests to get them to pass rather than ignore them entirely. I'm happy for this to be merged now and released as Any queries / objections before I do so? |
Looks good to me, thank you! Btw, is there anything we can do in the Ecto side to make future versions easier to update? |
Looking at the PR into postgrex was useful on seeing what changes needed to be done at an adapter level. I guess going further with that would be helpful. Sort of like a changelog, but only in the context of what would need to change at an adapter level? |
#25
Description
Changes to be compatible with Ecto 2.2, but also still backwards-compatible with Ecto 2.1
Motivation and Context
Keep reps up-to-date.
How Has This Been Tested?
Docker
Types of changes
Checklist: