View Source Handling Multiple Databases
This guide assumes that you're familiar with The Uniform System and have gone through the Getting Started guide.
If you're using The Uniform System it's likely that you have multiple Repos for multiple databases, but you only want to give access for a given database to some of your apps.
In this scenario, we recommend creating separate Lib
Dependencies (each in its own
lib/some_data_source
directory) which each encapsulate all of the code for
interacting with a single database. This implies that each Lib Dependency would
house all of the Ecto Schemas and
Context modules related to its
database.
Structuring the code this way allows you to easily include or exclude the code for a data source in uniform.exs.
an-example
An Example
For example, given apps with these uniform.exs
manifests
# lib/some_app/uniform.exs
[
lib_deps: [:my_data_source]
]
# lib/another_app/uniform.exs
[
lib_deps: [:my_data_source, :other_data_source]
]
# lib/third_app/uniform.exs
[
lib_deps: [:other_data_source]
]
SomeApp
would be ejected with all of the code related to interacting withmy_data_source
AnotherApp
would be ejected with the code for bothmy_data_source
andother_data_source
ThirdApp
would only be ejected with the code forother_data_source
configuring-lib-dependencies
Configuring Lib Dependencies
If you take this approach, make sure to configure your Blueprint module to include any Lib or Mix Dependencies of each data source's library. Also, be sure to include migrations and seeds related to the library.
lib :my_data_source do
lib_deps [:some_library]
mix_deps [:faker, ...]
# `match_dot: true` below to include priv/my_data_source_repo/.formatter.exs
file Path.wildcard("priv/my_data_source_repo/**", match_dot: true)
end