Method: TimeRangeUniqueness::MigrationAdditions#add_time_range_uniqueness
- Defined in:
- lib/time_range_uniqueness/migration_additions.rb
#add_time_range_uniqueness(table, options = {}) ⇒ Object
Adds a time range column and an exclusion constraint to the specified table.
This method creates or modifies a column to store time ranges and ensures that no two time ranges overlap for records with the same scoped columns.
45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/time_range_uniqueness/migration_additions.rb', line 45 def add_time_range_uniqueness(table, = {}) time_range_column = [:with] || :time_range scope_columns = Array([:scope]) column_type = :tstzrange constraint_name = [:name] || generate_constraint_name(table, scope_columns, time_range_column) reversible do |dir| dir.up { apply_up_migration(table, time_range_column, column_type, , constraint_name, scope_columns) } dir.down { apply_down_migration(table, time_range_column, constraint_name) } end end |