Skip to content

Commit

Permalink
Add default value for RepublishingEvents
Browse files Browse the repository at this point in the history
When we added the `bulk` field in
[`578590b27`](578590b) it seemed to default to `false` when creating new `RepublishingEvent`s without us needing to set a default value.

It appears that before merging this PR, a rubocop update was merged and
the PR branch not rebased with `main` after this. This caused Rubocop to
fail on `main` due to this rubocop issue.

Here we add an explicit `false` default value for `RepublishingEvent`s
and ignore the Rubocop violation on the previous migration.

I've had to use `up` rather than `change` here as `change_column` is not
reversible. According to a comment on the accepted answer on [this Stack
Overflow
post](578590b),

```
If you need reversible migrations, put this in an up block rather
than a change block. You can leave the down block empty. It won't revert
the table to the original condition but the migration can be rolled
back.
```
  • Loading branch information
Gweaton committed May 29, 2024
1 parent 4918ceb commit a2f5eb7
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class AddBulkAndBulkContentTypeToRepublishingEvents < ActiveRecord::Migration[7.1]
def change
change_table :republishing_events, bulk: true do |t|
t.boolean :bulk, null: false
t.boolean :bulk, null: false # rubocop:disable Rails/NotNullColumn
t.integer :bulk_content_type
end
end
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class MakeRepublishingEventsBulkFalseByDefault < ActiveRecord::Migration[7.1]
def up
change_column :republishing_events, :bulk, :boolean, default: false
end

def down; end
end
4 changes: 2 additions & 2 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema[7.1].define(version: 2024_05_21_150403) do
ActiveRecord::Schema[7.1].define(version: 2024_05_29_093425) do
create_table "assets", charset: "utf8mb3", force: :cascade do |t|
t.string "asset_manager_id", null: false
t.string "variant", null: false
Expand Down Expand Up @@ -865,7 +865,7 @@
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "content_id"
t.boolean "bulk", null: false
t.boolean "bulk", default: false, null: false
t.integer "bulk_content_type"
t.index ["user_id"], name: "index_republishing_events_on_user_id"
end
Expand Down

0 comments on commit a2f5eb7

Please sign in to comment.