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

Update to Ecto 3 #44

Open
wants to merge 29 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
8ad832d
copy in all work for updating to ecto 3.0
whossname Aug 4, 2019
6445158
update test instructions
whossname Aug 4, 2019
6758974
update elixir version in travis
whossname Aug 4, 2019
bf769b9
sample integration tests
whossname Aug 4, 2019
495bc73
create docs folder
whossname Aug 4, 2019
1d54f8d
move wait-for-it to bash scripts
whossname Aug 4, 2019
a835070
forgot to move some docs into the docs folder
whossname Aug 4, 2019
ff49a5a
Merge branch 'ecto_3.0' into dev
whossname Aug 4, 2019
d911f69
update issues, add sandbox to supported tests
whossname Aug 4, 2019
8a67e47
focus on migrator support
whossname Aug 4, 2019
3a1d76e
update issues, add sandbox to supported tests
whossname Aug 4, 2019
19df8b5
update version
whossname Aug 4, 2019
b1e67ad
update version
whossname Aug 4, 2019
27eb35d
Merge branch 'ecto_3.0' into dev
whossname Aug 10, 2019
fcc23d6
add lock
whossname Aug 30, 2019
59c931f
revert identity
whossname Aug 30, 2019
7eeda52
organise/document integration tests
whossname Sep 8, 2019
14f92cd
update integration test documentation
whossname Sep 13, 2019
63ee5b5
added type parser test
whossname Sep 14, 2019
c833b79
fix travis
whossname Sep 14, 2019
51342e1
update dependencies
whossname Sep 15, 2019
7c6a38e
fix unit tests
whossname Sep 15, 2019
141d96e
run formatter
whossname Sep 28, 2019
978548e
fix travis
whossname Sep 28, 2019
8872a1a
update documentation
whossname Oct 13, 2019
f11560f
rename type parser test
whossname Oct 13, 2019
aa3d40d
Hex now requires the body of the license to be present to publish a r…
Dec 24, 2019
04b865b
Updating dependencies
Dec 24, 2019
d91e40e
development mssqlex path
whossname Jan 14, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .formatter.exs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# Used by "mix format"
[
inputs: [".formatter.exs", "mix.exs", "{config,lib,test}/**/*.{ex,exs}"],
line_length: 80
inputs: [".formatter.exs", "mix.exs", "{config,lib,test}/**/*.{ex,exs}"]
]
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -135,3 +135,4 @@ $RECYCLE.BIN/


# End of https://www.gitignore.io/api/vim,linux,emacs,elixir,windows,visualstudiocode
tmp
7 changes: 5 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,18 @@ sudo: required

language: elixir
elixir:
- 1.6.5
- 1.8
otp_release:
- 20.0

services:
- docker

install:
- docker-compose build
- docker-compose build mssql_ecto

script:
- docker-compose run mssql_ecto mix format --check-formatted
- docker-compose run mssql_ecto mix compile --warnings-as-errors
- docker-compose run mssql_ecto mix coveralls.travis

Expand Down
6 changes: 3 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM elixir:1.6.5-slim
FROM elixir:1.8.2-slim

ENV DEBIAN_FRONTEND noninteractive

Expand All @@ -19,7 +19,7 @@ ENV LC_ALL en_US.UTF-8
# --- MSSQL ODBC INSTALL ---

RUN apt-get update && \
apt-get -y install curl apt-transport-https gnupg2 && \
apt-get -y install git curl apt-transport-https gnupg2 && \
curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add - && \
curl https://packages.microsoft.com/config/debian/9/prod.list > /etc/apt/sources.list.d/mssql-release.list && \
apt-get update && \
Expand All @@ -36,4 +36,4 @@ RUN mix do deps.get, deps.compile

# --- Be able to run wait for it script ---

RUN chmod +x /usr/src/app/wait-for-it.sh
RUN chmod +x /usr/src/app/bash_scripts/wait-for-it.sh
403 changes: 202 additions & 201 deletions LICENSE

Large diffs are not rendered by default.

104 changes: 37 additions & 67 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
[![Inline docs](http://inch-ci.org/github/findmypast-oss/mssql_ecto.svg?branch=master)](http://inch-ci.org/github/findmypast-oss/mssql_ecto)
[![Ebert](https://ebertapp.io/github/findmypast-oss/mssql_ecto.svg)](https://ebertapp.io/github/findmypast-oss/mssql_ecto)
[![Hex.pm](https://img.shields.io/hexpm/v/mssql_ecto.svg)](https://hex.pm/packages/mssql_ecto)
[![LICENSE](https://img.shields.io/hexpm/l/mssql_ecto.svg)](https://github.com/findmypast-oss/mssql_ecto/blob/master/LICENSE)
[![LICENSE](https://img.shields.io/hexpm/l/mssql_ecto.svg)](https://github.com/findmypast-oss/mssql_ecto/blob/master/docs/LICENSE)

[Ecto](https://github.com/elixir-ecto/ecto) Adapter for
[Mssqlex](https://github.com/findmypast-oss/mssqlex)
Expand All @@ -29,52 +29,13 @@ or
[other platforms](https://docs.microsoft.com/en-us/sql/connect/odbc/microsoft-odbc-driver-for-sql-server)
on the official site.

### Hex
### Mix

#### With [Application Inference](https://elixir-lang.org/blog/2017/01/05/elixir-v1-4-0-released/#application-inference)

If you are using
[application inference](https://elixir-lang.org/blog/2017/01/05/elixir-v1-4-0-released/#application-inference),
i.e. `application` in your `mix.exs` looks something like this:

```elixir
def application do
[extra_applications: [:logger]]
end
```

Note, the lack of `:applications` key. Then, you just need to add the following
dependencies:
Add the following to your mix file:

```elixir
def deps do
[{:mssql_ecto, "~> 1.2.0"},
{:mssqlex, "~> 1.1.0"}]
end
```

#### Without [Application Inference](https://elixir-lang.org/blog/2017/01/05/elixir-v1-4-0-released/#application-inference)

If you are explicitly calling out all running applications under `application`
in your `mix.exs`, i.e. it looks something like this:

```elixir
def application do
[applications: [:logger, :plug, :postgrex]]
end
```

Then, you need to add `mssql_ecto` and `mssqlex` to both your `deps` and list of
running applications:

```elixir
def application do
[applications: [:logger, :plug, :mssqlex, :mssql_ecto]]
end

def deps do
[{:mssql_ecto, "~> 1.2.0"},
{:mssqlex, "~> 1.1.0"}]
[{:mssql_ecto, "~> 2.0.0-beta.0"}]
end
```

Expand All @@ -97,30 +58,32 @@ config :my_app, MyApp.Repo,

An example project using mssql_ecto with Docker has kindly been created by
[Chase Pursłey](https://github.com/cpursley). It can be viewed
[here](https://github.com/cpursley/mssql_ecto_friends).
[here](https://github.com/whossname/mssql_ecto_friends).

## Type Mappings

| Ecto Type | SQL Server Type | Caveats |
| :-------------: | :------------------: | :--------------------------------------------------------------------------------------------------------------------------------------------------: |
| :id | int | |
| :serial | int identity(1, 1) | |
| :bigserial | bigint identity(1,1) | When a query is returning this value with the `returning` syntax and no schema is used, it will be returned as a string rather than an integer value |
| :binary_id | char(36) | |
| :uuid | char(36) | |
| :string | nvarchar | |
| :binary | nvarchar(4000) | Limited size, not fully implemented |
| :integer | int | |
| :boolean | bit | |
| {:array, type} | list of type | Not Supported |
| :map | nvarchar(4000) | Not Supported |
| {:map, \_} | nvarchar(4000) | Not Supported |
| :date | date | |
| :time | time | Can write but can't read |
| :utc_datetime | datetime2 | |
| :naive_datetime | datetime2 | |
| :float | float | |
| :decimal | decimal | |
### Needs testing/validation

| Ecto Type | SQL Server Type | Caveats |
| :-------------: | :------------------: | :---------------------------------: |
| :id | int | |
| :serial | int identity(1, 1) | |
| :bigserial | bigint identity(1,1) | |
| :binary_id | char(36) | |
| :uuid | char(36) | |
| :string | nvarchar | |
| :binary | nvarchar(4000) | Limited size, not fully implemented |
| :integer | int | |
| :boolean | bit | |
| {:array, type} | list of type | Not Supported |
| :map | nvarchar(4000) | Not Supported |
| {:map, \_} | nvarchar(4000) | Not Supported |
| :date | date | |
| :time | time | Can write but can't read |
| :utc_datetime | datetime2 | |
| :naive_datetime | datetime2 | |
| :float | float | |
| :decimal | decimal | |

## Features not yet implemented

Expand All @@ -129,11 +92,15 @@ An example project using mssql_ecto with Docker has kindly been created by
- On conflict
- Upserts

## Known Issues

See the the list of [known issues](https://github.com/findmypast-oss/mssqlex#known-issues).

## Contributing

### Integration Test Setup
### Test Setup

Running the integration tests requires an instance of SQL Server running on
Running the tests requires an instance of SQL Server running on
`localhost` and certain configuration variables set as environment variables:

- MSSQL_DVR should be set to the ODBC driver to be used. Usually
Expand All @@ -145,8 +112,11 @@ Running the integration tests requires an instance of SQL Server running on

The tests will create a database named `mssql_ecto_integration_test`

The script `/bash_scripts/setup_test_db.sh` starts a docker image that holds
the test database.

### Code of Conduct

This project had a
[Code of Conduct](https://github.com/findmypast-oss/mssql_ecto/blob/master/CODE_OF_CONDUCT.md)
[Code of Conduct](https://github.com/findmypast-oss/mssql_ecto/blob/master/docs/CODE_OF_CONDUCT.md)
if you wish to contribute to this project, please abide by its rules.
6 changes: 6 additions & 0 deletions bash_scripts/setup_test_db.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export MSSQL_UID=sa
export MSSQL_PWD='ThePa$$word'
docker stop test_mssql_server
docker rm test_mssql_server
docker run --name test_mssql_server -e 'ACCEPT_EULA=Y' -e SA_PASSWORD=$MSSQL_PWD -p 1433:1433 -d microsoft/mssql-server-linux
echo 'Created docker container test_mssql_server'
1 change: 1 addition & 0 deletions bash_scripts/test_db_cli.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sudo docker exec -it test_mssql_server /opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P 'ThePa$$word'
File renamed without changes.
13 changes: 7 additions & 6 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,25 @@ services:
image: microsoft/mssql-server-linux
environment:
- ACCEPT_EULA=Y
- SA_PASSWORD=TestPa$$word123
- MSSQL_TCP_PORT=9204
- SA_PASSWORD=ThePa$$word
- MSSQL_TCP_PORT=1433

mssql_ecto:
build: .
environment:
- MIX_ENV=test
- MSSQL_UID=sa
- MSSQL_PWD=TestPa$$word123
- MSSQL_PWD=ThePa$$word
- MSSQL_HST=sql_server
- MSSQL_IN=MSSQLSERVER
- MSSQL_PRT=9204
- MSSQL_PRT=1433
- MSSQL_DVR={ODBC Driver 17 for SQL Server}
- TRAVIS_JOB_ID=$TRAVIS_JOB_ID
depends_on:
- sql_server
volumes:
- .:/usr/src/app/
- /usr/src/app/deps
- /usr/src/app/_build
entrypoint: ./wait-for-it.sh sql_server:9204 --
entrypoint: ./bash_scripts/wait-for-it.sh sql_server:1433 --
command: mix test

File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading