1

Every time a run rake db:migrate it generate as a result a useless db/schema.rb file which can't be loaded with rake db:schema:load simply because my views are being dumped incorrectly.

I noticed the dump is coming with my views and a table with the same name. This cause to raise an error due to a table name which already exists.

I'm currently using rails 4.2.11 and the Scenic version in my gemfile is 1.4.1.

This is a few of my tables and a view which uses them, I tried to remove all the definition for table foo_bar (same name of the view) manually and after that the rake db:schema:load worked. But the next time I ran a db:migration those useless table will come again.


ActiveRecord::Schema.define(version: 2) do

  create_table "foo_bar", id: false, force: :cascade do |t|
    t.integer  "id",                  limit: 4,                           default: 0,    null: false
    t.string   "uuid",                limit: 36
    t.decimal  "quantity",                       precision: 20, scale: 4, default: 0.0
    t.integer  "bar_id", limit: 4,                           default: 0
    t.decimal  "price",               precision: 20, scale: 4,  default: 0.0
  end

  create_table "foo", force: :cascade do |t|
    t.string   "uuid",            limit: 36
    t.decimal  "quantity",        precision: 20, scale: 4, default: 0.0
  end

  create_table "bar", force: :cascade do |t|
    t.decimal  "price",               precision: 20, scale: 4,  default: 0.0
    t.integer  "foo_id",            limit: 4
    t.decimal  "quantity",            precision: 20, scale: 4,  default: 0.0
  end

  add_index "bar", ["foo_id"], name: "index_bars_on_foo_id", using: :btree

  add_foreign_key "bar", "foo"

  create_view "foo_bar",  sql_definition: <<-SQL
      select `s`.`id` AS `id`,`s`.`uuid` AS `uuid`,`s`.`quantity` AS `quantity`,`t`.`id` AS `bar_id`,`t`.`price` AS `price` from (`foo` `s` left join `bar` `t` on(((`t`.`foo_id` = `s`.`id`))))
  SQL

end

My database is much bigger than this, and now every time I need to initiate a new app I have to run all the migrations from scratch and it takes much time and the schema:load does not

intmarinoreturn0
  • 300
  • 1
  • 16
  • 1
    https://stackoverflow.com/questions/44378123/rails-rake-dbstructureload-vs-rake-dbschemaload/44378434#44378434 Take a look here, you can have Rails dump the sql instead of the `schema.rb` file – Eyeslandic Jun 30 '19 at 17:03
  • 1
    @Eyeslandic I think I understand now. It seems not possible to have a full functional schema as I wanted initially. What is the next step here? close the question since there is no answer? – intmarinoreturn0 Jul 01 '19 at 19:16
  • You can accept it as a duplicate – Eyeslandic Jul 01 '19 at 19:18

0 Answers0