pinboard_export = File.expand_path(ENV.fetch("PINBOARD_EXPORT")) Sequel.migration do up do create_table(:pinboard) do primary_key :id foreign_key :entity_id, :entities, null: false, unique: true String :json, text: true, null: false DateTime :created_at, null: false DateTime :updated_at end File.foreach(pinboard_export).with_index do |line, i| created_at = updated_at = DateTime.now json = line.chomp entity_id = DB[:entities].insert(created_at:, updated_at:) DB[:pinboard].insert(entity_id:, json: , created_at:, updated_at:) end # Remove duplicate entry DB[:pinboard].where(id: 5001).delete end end