Sequel.migration do up do create_table(:urls) do primary_key :id foreign_key :entity_id, :entities, null: false, unique: true String :url, unique: true, null: false DateTime :created_at, null: false DateTime :updated_at end json = Sequel.sqlite_json_op(:json) href = json.extract("$.href") DB[:pinboard] .select_append(href.as(:href)) .each do |pin| entity_id = pin.fetch(:entity_id) url = pin.fetch(:href) created_at = updated_at = DateTime.now DB[:urls].insert(entity_id:, url:, created_at:, updated_at:) end end down do drop_table(:urls) end end