Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change tick columns to bigints #663

Merged
merged 2 commits into from
Jul 11, 2022
Merged

Conversation

sj26
Copy link
Contributor

@sj26 sj26 commented Jul 6, 2022

We're using maintenance tasks on some tables with a very large number of rows and noticed that the tick_total on a batched activerecord enumerator has overflown the integer column, preventing the task from running. This is a migration to change the tick columns to bigints.

@ghost ghost added the cla-needed label Jul 6, 2022
@ghost ghost removed the cla-needed label Jul 6, 2022
@@ -46,7 +46,7 @@
t.datetime "ended_at"
t.float "time_running", default: 0.0, null: false
t.integer "tick_count", default: 0, null: false
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one wasn't changed somehow

Copy link

@JuanitoFatas JuanitoFatas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry wrong approval, please ignore.

@sj26
Copy link
Contributor Author

sj26 commented Jul 8, 2022

Sorry, I'm not sure how I missed that column being wrong, or forgetting to bump the schema version. Perhaps because I staged the schema in hunks.

When I run the test suite and migrations in the dummy app I see unrelated diffs like:

diff --git a/test/dummy/db/schema.rb b/test/dummy/db/schema.rb
index d95da48..04f08dd 100644
--- a/test/dummy/db/schema.rb
+++ b/test/dummy/db/schema.rb
@@ -10,13 +10,12 @@
 #
 # It's strongly recommended that you check this file into your version control system.

-ActiveRecord::Schema.define(version: 2022_07_06_101937) do
-
+ActiveRecord::Schema[7.0].define(version: 2022_07_06_101937) do
   create_table "active_storage_attachments", force: :cascade do |t|
     t.string "name", null: false
     t.string "record_type", null: false
     t.integer "record_id", null: false
-    t.bigint "blob_id", null: false
+    t.integer "blob_id", null: false
     t.datetime "created_at", null: false
     t.index ["blob_id"], name: "index_active_storage_attachments_on_blob_id"
     t.index ["record_type", "record_id", "name", "blob_id"], name: "index_active_storage_attachments_uniqueness", unique: true
@@ -35,7 +34,7 @@ ActiveRecord::Schema.define(version: 2021_12_10_152329) do
   end

   create_table "active_storage_variant_records", force: :cascade do |t|
-    t.bigint "blob_id", null: false
+    t.integer "blob_id", null: false
     t.string "variation_digest", null: false
     t.index ["blob_id", "variation_digest"], name: "index_active_storage_variant_records_uniqueness", unique: true
   end
@@ -53,18 +52,18 @@ ActiveRecord::Schema.define(version: 2021_12_10_152329) do
     t.string "error_class"
     t.string "error_message"
     t.text "backtrace"
-    t.datetime "created_at", precision: 6, null: false
-    t.datetime "updated_at", precision: 6, null: false
+    t.datetime "created_at", null: false
+    t.datetime "updated_at", null: false
     t.text "arguments"
-    t.index ["task_name", "created_at"], name: "index_maintenance_tasks_runs_on_task_name_and_created_at"
     t.integer "lock_version", default: 0, null: false
+    t.index ["task_name", "created_at"], name: "index_maintenance_tasks_runs_on_task_name_and_created_at"
   end

   create_table "posts", force: :cascade do |t|
     t.string "title"
     t.string "content"
-    t.datetime "created_at", precision: 6, null: false
-    t.datetime "updated_at", precision: 6, null: false
+    t.datetime "created_at", null: false
+    t.datetime "updated_at", null: false
   end

   add_foreign_key "active_storage_attachments", "active_storage_blobs", column: "blob_id"

so I'm not sure the schema/migrations are stable.

I've amended the commit to include the correct columns and schema version.

Copy link
Member

@etiennebarrie etiennebarrie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for your contribution!

I think we'll want to ship a 1.x version with this instead of pushing it to a 2.x.

@etiennebarrie etiennebarrie merged commit 16afa1f into Shopify:main Jul 11, 2022
@sj26
Copy link
Contributor Author

sj26 commented Jul 12, 2022

Thanks folks!

@sj26 sj26 deleted the make-ticks-bigints branch July 12, 2022 06:05
etiennebarrie added a commit that referenced this pull request Jul 12, 2022
Change tick columns to bigints
@shopify-shipit shopify-shipit bot temporarily deployed to rubygems September 26, 2022 13:57 Inactive
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants