dogweather

dogweather

Coexisting with a Rails database

I’m making a simple Phoenix app to manage links to news. The articles relate to data in a Rails app. I’d like for the Phoenix tables to live alongside Rails tables in the same Postgres database and schema. The Phoenix app would get read-only access to the Rails tables, and vice-versa.

I’ve run into a couple of roadbumps:

  • Both Rails and Phoenix use a table, schema_migrations. But the tables’ structures as created by the frameworks are different.
  • Keeping everything in the same schema seems less problematic: both frameworks don’t work so well with multi-schema queries.

So, I wonder:

  • Is it possible to customize the name of schema_migrations that Phoenix maintains?
  • Or, if Phoenix needs its own Postrgres schema so that it can have its own schema_migrations, then how does the multi-schema story look currently?

Is there another solution I don’t know about?

EDIT: I found that Rails allows the table name to be changed. This is probably all I need:

3.8.5 config.active_record.schema_migrations_table_name

Lets you set a string to be used as the name of the schema migrations table.

EDIT 2: I found how to configure this in Phoenix:

:migration_source - Version numbers of migrations will be saved in a table named schema_migrations by default. You can configure the name of the table via:

config :app, App.Repo, migration_source: "my_migrations"

First Post!

cschmatzler

cschmatzler

Not sure about Rails, but what’s the issue you’ve run in with Ecto?

Most Liked

LostKobrakai

LostKobrakai

Seems like there are already a few paths:

  • Renaming the migrations table
  • Ecto afaik supports custom schemas quite well

Though I’d also argue that you shouldn’t really have two migration systems run against the same db. Keep things either in rails (or in phoenix I guess) or move to an external to both migration system. Even more as the phoenix one should run with a read only user, which won’t be allowed to migrate anything on that db.

trisolaran

trisolaran

Ecto.Migrator.up accepts a prefix option with which you can specify a schema. The schema_migrations table will be created in that schema. From the CLI: mix ecto.migrate --prefix prefix_name.

In the past 2 years I’ve been working on a Phoenix app that needed to live alongside a legacy application and share its database. In order to improve separation I decided to put my app’s “private” tables in a separate schema, with their own migrations.

I don’t recall what it was like with Rails, but with Ecto I had no issues or roadblocks with the multi-schema setup :slight_smile:

Where Next?

Popular in Questions Top

New
skosch
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New
mcarvalho
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
New
aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
belgoros
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
freewebwithme
Using vs code and installed ElixirLS: support and debugger. And I got an error popped up on start up says Failed to run ‘elixir’ comma...
New

Other popular topics Top

lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
dokuzbir
I want to highlight html closing tags when i click a html tag. That works in .html files but doesnt work for html.eex templates. How can...
New
joeerl
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New
dogweather
I wrote this comment on r/haskell, and it’s not popular there. :wink: But I think I’m on to something… Haskell reminds me of Java, and e...
New
jason.o
In the code below, if the create action is not set to accept “extra_key” as an input, it errors out with a message shown above. Is there ...
New

We're in Beta

About us Mission Statement