Module: Plutonium::Positioning::MigrationHelpers
- Defined in:
- lib/plutonium/positioning.rb
Overview
Migration helper that adds a position column pre-tuned for fractional ordering. Mixed into ActiveRecord's table-definition classes by the railtie, so it is available in both create_table and change_table:
create_table :tasks do |t|
t.position # decimal :position, precision: 16, scale: 8
t.position :sort_order # custom column name
t.position index: true # also add a single-column index
end
change_table :tasks do |t|
t.position
end
The precision/scale give midpoints ample headroom over the rebalance threshold (EPSILON = 1e-6) — a too-small scale lets the last subdivision round to a neighbor. Pass precision:/scale: to override.
Constant Summary collapse
- DEFAULT_PRECISION =
16- DEFAULT_SCALE =
8
Instance Method Summary collapse
Instance Method Details
#position(name = :position, **options) ⇒ Object
141 142 143 |
# File 'lib/plutonium/positioning.rb', line 141 def position(name = :position, **) column name, :decimal, precision: DEFAULT_PRECISION, scale: DEFAULT_SCALE, ** end |