You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Issue
Currently for Rails 5.2.6 and ar-octopus (0.10.2) and mysql2 (0.5.5) , the migration process runs multiple times on a given shard due to how shards are fetched and processed. This occurs because the list of shards is obtained using the expression migrations.map(&:shards).flatten.map(&:to_s), resulting in an array of shard names. As a consequence, if a shard has 'n' associated migrations, the migration process will be executed 'n' times on that shard.
Proposed Solution
To address this issue and ensure that migrations are not duplicated on the same shard, we can modify the process as follows:
Instead of directly flattening the migrations.map(&:shards) array, we get unique elements migrations.map(&:shards).uniq.
This approach guarantees that each shard will only appear once in the resulting array, preventing duplicate migrations on the same shard.
Benefits
Improves the efficiency of the migration process by preventing unnecessary repeated migrations on the same shard.
prathamesh000777
changed the title
Preventing Duplicate Migrations on the Same Shard
Preventing Duplicate Migrations on the Same Shard for Rails > 5.2
Aug 19, 2023
prathamesh000777
changed the title
Preventing Duplicate Migrations on the Same Shard for Rails > 5.2
Preventing Duplicate Migrations on the Same Shard for Rails > 5.2 and ar-octopus (0.10.2)
Aug 19, 2023
Issue
Currently for Rails 5.2.6 and ar-octopus (0.10.2) and mysql2 (0.5.5) , the migration process runs multiple times on a given shard due to how shards are fetched and processed. This occurs because the list of shards is obtained using the expression
migrations.map(&:shards).flatten.map(&:to_s)
, resulting in an array of shard names. As a consequence, if a shard has 'n' associated migrations, the migration process will be executed 'n' times on that shard.Proposed Solution
To address this issue and ensure that migrations are not duplicated on the same shard, we can modify the process as follows:
Instead of directly flattening the
migrations.map(&:shards)
array, we get unique elementsmigrations.map(&:shards).uniq
.This approach guarantees that each shard will only appear once in the resulting array, preventing duplicate migrations on the same shard.
Benefits
Improves the efficiency of the migration process by preventing unnecessary repeated migrations on the same shard.
Pull Request with fix: #580
The text was updated successfully, but these errors were encountered: