Custom schema_migrations table name

Visto 216 veces
Saltar al primer mensaje no leído

Tommaso Visconti

no leída,
21 abr 2014, 4:53:2121/4/14
a rubyonra...@googlegroups.com
Hi all,
I have more rails apps sharing the same database and this creates problems with schema_migrations table.
Do you know haw to customize that table name (so every app uses a different one)? Or there's a better approach to this situation?

Thanks!
Tommaso

sandip ransing

no leída,
21 abr 2014, 6:28:5921/4/14
a rubyonra...@googlegroups.com
Hi Tommaso, 

You can set table_name inside rails model. 

Example:

class A < ActiveRecord::Base
  set_table_name "aa"
end

- Sandip

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-ta...@googlegroups.com.
To post to this group, send email to rubyonra...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAK4fz2pUaznaK_P-rz%3DgKfWhww28nDZHaj5gY5oXodm7Gih_dQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.



--
www.funonrails.com

Mobile +91-9975773744
Twitter, Github @sandipransing
Skype sandip.ransing

Tommaso Visconti

no leída,
21 abr 2014, 17:37:5321/4/14
a rubyonra...@googlegroups.com
hi sandip, thanks for the answer, but the problem isn't using different tables, but avoid using the same schema_migrations table automatically generated by rails. I need to use the same database to share most tables, but different apps have some tables which should be shared so every app has its migrations, which causes a lot of problems because all the apps use the schema_migrations table


Jordon Bedwell

no leída,
21 abr 2014, 17:47:5721/4/14
a rubyonra...@googlegroups.com
On Mon, Apr 21, 2014 at 4:37 PM, Tommaso Visconti
<tommaso....@gmail.com> wrote:
> hi sandip, thanks for the answer, but the problem isn't using different
> tables, but avoid using the same schema_migrations table automatically
> generated by rails. I need to use the same database to share most tables,
> but different apps have some tables which should be shared so every app has
> its migrations, which causes a lot of problems because all the apps use the
> schema_migrations table

If you have to do things in such a chaotic and unorganized way with
multiple apps then get clever and just include all migrations from all
other apps in the other apps and flag them with comments at the top
that state they are there to keep schema_migrations happy, you don't
need the models at all and rails will detect the tables already exist
and the migrations have already ran and not run them.

Pratap Patil

no leída,
8 may 2014, 23:48:348/5/14
a rubyonra...@googlegroups.com

If you just want to share models, you can add the other project models folder into your autoload paths:

  rails new test1
 
  rails new test2

 cd test1

rails g model User

cd test2

mkdir 

mkdir db/migrate

cp ../test1/db/migrate/*_create_users.rb db/ mv db/*_create_users.rb db/migrate/

rake db:migrate

i hope help to us..

Frederick Cheung

no leída,
9 may 2014, 8:18:199/5/14
a rubyonra...@googlegroups.com
It looks like that table name is controlled by ActiveRecord::Base.schema_migrations_table_name. You might also be interested in the table_name_prefix setting which adds a prefix to all table names (including schema migrations) so that you can't have any clashes

Fred 
Responder a todos
Responder al autor
Reenviar
0 mensajes nuevos