1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
Sequel.migration do
  # The many_to_many association's add_upload inserts into the join table
  # without setting created_at. Give the column a default so the bare insert
  # still populates it and the NOT NULL constraint holds. The timestamp orders
  # an asset's photos (oldest first); upload_id breaks ties within the
  # one-second resolution of CURRENT_TIMESTAMP.
  #
  # set_column_default is irreversible under `change`, so up/down are explicit.
  up do
    alter_table(:asset_attachments) do
      set_column_default :created_at, Sequel::CURRENT_TIMESTAMP
    end
  end

  down do
    alter_table(:asset_attachments) do
      set_column_default :created_at, nil
    end
  end
end