[英]Can I use different versions of a package for different environments?
I have a project where I need to use SQLite in a local environment but Postgres on a normal server.我有一个项目,我需要在本地环境中使用 SQLite,但在普通服务器上使用 Postgres。
Unfortunately, there is no SQLite adapter for Ecto 3 yet, forcing me to keep the Ecto and some related packages at 2.x
, which caused some problems such as this one: Ecto 2.0 SQL Sandbox Error on tests不幸的是,目前还没有用于 Ecto 3 的 SQLite 适配器,迫使我将 Ecto 和一些相关包保留在2.x
,这导致了一些问题,例如: Ecto 2.0 SQL Sandbox Error on testing
I wonder if it would be possible to specify two different versions of Ecto and thus dependencies for the environments :local
and :prod
.我想知道是否可以指定两个不同版本的 Ecto 以及环境的依赖关系:local
和:prod
。 Currently it seems impossible since there is only one lockfile per project.目前这似乎是不可能的,因为每个项目只有一个锁文件。 The only way to achieve it seems to be to store two different lockfiles in the project directory?实现它的唯一方法似乎是在项目目录中存储两个不同的锁文件? eg https://elixirforum.com/t/only-fetch-deps-compatible-for-a-specific-version-of-elixir/16213例如https://elixirforum.com/t/only-fetch-deps-compatible-for-a-specific-version-of-elixir/16213
I haven't tried it in depth, but maybe changing the mix.exs file like this would help:我还没有深入尝试过,但也许像这样更改 mix.exs 文件会有所帮助:
defmodule YourProject.MixProject do
use Mix.Project
def project do
[
app: :your_project,
version: "0.1.0",
elixir: "~> 1.7",
start_permanent: Mix.env() == :prod,
deps: deps(Mix.env()),
lockfile: lockfile(Mix.env())
]
end
# Run "mix help compile.app" to learn about applications.
def application do
[
extra_applications: [:logger]
]
end
defp lockfile(:local), do: "mix-local.lock"
defp lockfile(_), do: "mix.lock"
# Run "mix help deps" to learn about dependencies.
defp deps(:local) do
[{:ecto, "~> 2.0"}]
end
defp deps(_) do
[{:ecto, "~> 3.0"}]
end
end
Both the lockfile and deps are different for the :local
environment. :local
环境的 lockfile 和 deps 是不同的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.