简体   繁体   中英

random changes in schema.rb

I've noticed this for months and I just didn't have the time to deal with it until now. Whenever my CI server does an automatic git pull and restarts the rails servers, the schema.rb gets randomly modified. As the example shows below, the api_name column of a certain table got dropped. I dropped this column about 3 months ago. Same with transportation_charges . And very often, the spacing in this file changes: see created_at and updated_at .

It's especially annoying since on the next run, when my CI does an initial git pull , it complains about changes to schema.rb and stops execution until they get pushed or reverted. And it's not just the CI server. I've seen this on other developer machines as well. Did anyone run into this before?

diff --git a/db/schema.rb b/db/schema.rb
index 470d3bf..166e3ee 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -883,7 +883,6 @@ ActiveRecord::Schema.define(version: 20170720211740) do

   create_table "ups_package_service_options", force: :cascade do |t|
     t.string   "name"
-    t.string   "api_name"
     t.string   "type"
     t.datetime "created_at", null: false
     t.datetime "updated_at", null: false
@@ -910,9 +909,8 @@ ActiveRecord::Schema.define(version: 20170720211740) do
     t.string   "code"
     t.string   "name"
     t.string   "api_name"
-    t.decimal  "transportation_charges"
-    t.datetime "created_at",             null: false
-    t.datetime "updated_at",             null: false
+    t.datetime "created_at", null: false
+    t.datetime "updated_at", null: false
     t.boolean  "domestic"
   end

When you run a migration, the schema gets updated not just by the migration, but also the current database. I'm guessing some of your developers are using databases inconsistent with the schema. Then you'll get unexpected changes every time they run a migration.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM