Skip to content

Commit 76d2c0f

Browse files
committed
Split processes' name migration into two
As it won't be possible to start new processes after the column is made NOT NULL and before deploying the code that uses that column.
1 parent 9fb89f1 commit 76d2c0f

File tree

4 files changed

+28
-21
lines changed

4 files changed

+28
-21
lines changed

UPGRADING.md

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
# Upgrading to version 0.6.x
22

33
## New migration in 3 steps
4-
This version adds a new migration to the `solid_queue_processes` table. This migration adds a new column that needs to be `NOT NULL`. It will run in three steps:
5-
1. Add the new column, nullable
6-
2. Backfill existing rows that would have the column as NULL
7-
3. Make the column not nullable and add a new index
4+
This version adds two new migrations to modify the `solid_queue_processes` table. The goal of that migration is to add a new column that needs to be `NOT NULL`. This needs to be done with two migrations and the following steps to ensure it happens without downtime and with new processes being able to register just fine:
5+
1. Run the first migration that adds the new column, nullable
6+
2. Deploy the updated Solid Queue code that uses this column
7+
2. Run the second migration. This migration does two things:
8+
- Backfill existing rows that would have the column as NULL
9+
- Make the column not nullable and add a new index
810

9-
To install it:
11+
Besides, it adds another migration with no effects to the `solid_queue_recurring_tasks` table. This one can be run just fine whenever, as the column affected is not used.
12+
13+
To install the migrations:
1014
```bash
1115
$ bin/rails solid_queue:install:migrations
1216
```
@@ -17,7 +21,7 @@ Or, if you're using a different database for Solid Queue:
1721
$ bin/rails solid_queue:install:migrations DATABASE=<the_name_of_your_solid_queue_db>
1822
```
1923

20-
And then just run it.
24+
And then follow the steps above, running first one, then deploying the code, then running the second one.
2125

2226
## New behaviour when workers are killed
2327
From this version onwards, when a worker is killed and the supervisor can detect that, it'll fail in-progress jobs claimed by that worker. For this to work correctly, you need to run the above migration and ensure you restart any supervisors you'd have.
Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,5 @@
11
class AddNameToProcesses < ActiveRecord::Migration[7.1]
2-
def up
2+
def change
33
add_column :solid_queue_processes, :name, :string
4-
5-
SolidQueue::Process.find_each do |process|
6-
process.name ||= [ process.kind.downcase, SecureRandom.hex(10) ].join("-")
7-
process.save!
8-
end
9-
10-
add_index :solid_queue_processes, [ :name, :supervisor_id ], unique: true
11-
change_column :solid_queue_processes, :name, :string, null: false
12-
end
13-
14-
def down
15-
remove_index :solid_queue_processes, [ :name, :supervisor_id ]
16-
remove_column :solid_queue_processes, :name
174
end
185
end
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
class MakeNameNotNull < ActiveRecord::Migration[7.1]
2+
def up
3+
SolidQueue::Process.where(name: nil).find_each do |process|
4+
process.name ||= [ process.kind.downcase, SecureRandom.hex(10) ].join("-")
5+
process.save!
6+
end
7+
8+
change_column :solid_queue_processes, :name, :string, null: false
9+
add_index :solid_queue_processes, [ :name, :supervisor_id ], unique: true
10+
end
11+
12+
def down
13+
remove_index :solid_queue_processes, [ :name, :supervisor_id ]
14+
change_column :solid_queue_processes, :name, :string, null: false
15+
end
16+
end

test/integration/forked_processes_lifecycle_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ class ForkedProcessesLifecycleTest < ActiveSupport::TestCase
104104
no_pause = enqueue_store_result_job("no pause")
105105
pause = enqueue_store_result_job("pause", pause: 0.2.seconds)
106106

107-
signal_process(@pid, :INT, wait: 0.1.second)
107+
signal_process(@pid, :INT, wait: 0.3.second)
108108
wait_for_jobs_to_finish_for(2.second)
109109

110110
assert_completed_job_results("no pause")

0 commit comments

Comments
 (0)