You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
alphadex/db/migrations/006_extract_pinboard_title_...

33 lines
838 B

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