Assuming I have 2 databases, main and temp, I have an ActiveRecord class Entry that corresponds to an entries table in main, how can I create a similar table in temp.
The first stab is use Entry.connection.execute('show create table #{Entry.table_name}') and invoke that against another table. (works if main and temp are same kind of database).
Is there a nicer way to do it? Preferably one that doesn’t involve reading & invoking “create table” expressions.
For example, something with ActiveRecord::Schema.define seems to be best. But I’m not sure exactly what to do.
Thanks.
After quick googling I didn’t find ready-made method of achieving this without raw SQL. You can, however, make your own solution by mimicking what
annotate_modelsdoes.A piece from https://github.com/ctran/annotate_models/blob/master/lib/annotate/annotate_models.rb
Also, you might want to read what ActiveRecord Migrations Guide has to offer.