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

Migrations not namespaced by database in Rails 6 #36205

Closed
ionut998 opened this issue May 7, 2019 · 8 comments
Closed

Migrations not namespaced by database in Rails 6 #36205

ionut998 opened this issue May 7, 2019 · 8 comments
Assignees
Milestone

Comments

@ionut998
Copy link

ionut998 commented May 7, 2019

Steps to reproduce

Expected behavior

The migration file gets created under db/migrate/animals

Actual behavior

The migration file gets created under db/migrate

System configuration

Rails version: 6.0.0.rc1
Ruby version: 2.5.0p0

I am trying to understand if I am doing something wrong or the migrations don't get created in the right folder.
I am trying to create an app with 2 databases that have different structures.

  • database primary that contains users table
  • database animals that contains dogs table

Here is the config that I have in config/database.yml file

default: &default
  adapter: mysql2
  encoding: utf8mb4
  pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
  username: root
  password:
  socket: /tmp/mysql.sock

development:
  primary:
    <<: *default
    database: my_primary_db
    user: root
  animals:
    <<: *default
    database: my_animals_db
    user: root

When I run bin/rails g migration create_users the 2019..._create_users.rb migration get's created under db/migrate folder. I expect this to get created under db/migrate/primary.
The same happens when I run bin/rails g migration create_dogs --database=animals. The file 2019..._create_dogs.rb gets created under db/migrate and I expect this to get created under db/migrate/animals

If I then go ahead and migrate the database then Rails does create 2 schemas under the db folder (schema.rb and animals_schema.rb), however they both have the same content.

Project to reproduce: https://github.com/ionut998/project5

@joseluistorres
Copy link
Contributor

I'm not 100% sure, have you tried defining the path?:

# database.yml
migrations_paths: "db/another_db_migrate"

@ionut998
Copy link
Author

ionut998 commented May 8, 2019

Specifying the migration path works

development:
  primary:
    migrations_paths: "db/migrate/primary"
  animals:
    migrations_paths: "db/migrate/animals"

now if I run bin/rails g migration create_dogs --database=animals the file gets created in db/migrate/animals.
For the primary database, the file get's created in db/migrate/primary only if I specify --database=primary
The documentation for bin/rails g migration seem to suggest that primary is default
--db, [--database=DATABASE] # The database for your migration. By default, the current environment's primary database is used.
but if I run bin/rails g migration create_admins the file get's created under db/migrate/ even if I specified migrations_paths: "db/migrate/primary"
Is that expected?

@joseluistorres

@joseluistorres
Copy link
Contributor

I have no idea, this is a really new feature. I think there's definitely room for improvement, having multi DB in Rails it's a big accomplishment!

but if I run bin/rails g migration create_admins the file get's created under db/migrate/ even if I specified migrations_paths: "db/migrate/primary"

I think it could be to make apps with a single DB behave in the same way than before these changes.

@joseluistorres
Copy link
Contributor

I'm not sure where is the documentation for multi DB (because lazy bones) but I can read the first PR related to this https://github.com/rails/rails/pull/32274/files

@eileencodes
Copy link
Member

Hey - this is definitely a documentation issue. We haven't gotten around to writing docs yet but will get them done for the final release. The database stuff has been influx throughout the last year. Sorry for the confusion!

migrations_paths is required in the database config. We may eventually be able to remove it and have Rails guess where to put the file for the generator but haven't gotten around to looking at that. I'll mark this as a docs issue.

@eileencodes eileencodes self-assigned this May 10, 2019
@eileencodes eileencodes added this to the 6.0.0 milestone May 10, 2019
@joseluistorres
Copy link
Contributor

@eileencodes I don't know if I can help in anyway with the documentation since a very new feature but if you think I can let me know 🙌 .

@eileencodes
Copy link
Member

Fixed in #36389

@ionut998
Copy link
Author

ionut998 commented Jul 9, 2019

That looks great
Thanks @eileencodes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants
@rafaelfranca @joseluistorres @eileencodes @ionut998 and others