Rails: Integer Column Missed in Production Migration

This bug is killing me. I have a migration in my rails app like so:

class CreateRepeatingSessions < ActiveRecord::Migration[7.0]
  def change
    create_table :repeating_sessions do |t|
      t.references :user, null: false, foreign_key: true
      t.references :list, null: false, foreign_key: true
      t.boolean :email_notify, default: true
      # Times
      t.datetime :start_time
      t.datetime :end_time
      t.integer :utc_offset
      t.string :time_zone
      # Repeating Basics
      t.integer :interval, default: 0
      t.integer :frequency, default: 1
      # Weekly Specifics
      t.boolean :sunday, default: false
      t.boolean :monday, default: false
      t.boolean :tuesday, default: false
      t.boolean :wednesday, default: false
      t.boolean :thursday, default: false
      t.boolean :friday, default: false
      t.boolean :saturday, default: false
      # Monthly Specifics
      t.integer :month_schedule_method, default: 0 # enum for week_num or day_num
      t.integer :week_number, default: 1 # Week of month to repeat
      t.integer :day_number, default: 1 # Day of month to repeat.

      t.timestamps
    end
  end
end

This works perfectly well in development. However, when I pushed this commit to Github and Render deployed it (to a Rails web server and Postgres db) the frequency column was not created, despite the rest of the table being created. Here’s the error Rails throws on production:

ActionView::Template::Error (undefined method `frequency' for #<RepeatingSession id: 5, user_id: 1, list_id: 13, email_notify: true, start_time: "2023-06-03 17:00:00.000000000 -0700", end_time: nil, utc_offset: -28800, time_zone: "Pacific Time (US & Canada)", rules: nil, created_at: "2023-06-02 17:38:37.727616000 -0700", updated_at: "2023-06-02 17:38:41.693348000 -0700", interval: nil, month_schedule_method: nil, form_steps: nil>)

Logging into rails c via the shell and creating a new RepeatingSession object yields an object without a frequency parameter. Everything else is there though.

I’ve rebooted, run bundle exec rails db:migrate in the shell, pushed a new commit, and tried debugging this several ways. No alert or error is logged during build. I have no idea what’s going on. Any thoughts?

Thanks in advance.

Hey Drew,

This smells like the migration hasn’t run or perhaps the migration has been modified since it was first created and if it’s already been run Rails doesn’t run it again - if you use psql $DATABASE_URL from a service in your account and then use \d repeating_sessions what does the Postgres schema look like?

John B
Render Support, UTC+1 :uk:

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.