Sequel.migration do up do create_table(:titles) do foreign_key :entity_id, :entities, null: false, unique: true String :title DateTime :created_at, null: false DateTime :updated_at end json = Sequel.sqlite_json_op(:json) description = json.extract("$.description") extended = json.extract("$.extended") DB[:pinboard] .select_append(description.as(:description), extended.as(:extended)) .each do |pin| entity_id = pin.fetch(:entity_id) title = pin.fetch(:description) text = pin.fetch(:extended) created_at = updated_at = DateTime.now DB[:titles].insert(entity_id:, title:, created_at:, updated_at:) DB[:notes].insert(entity_id:, text:, created_at:, updated_at:) end end down do drop_table(:titles) end end