parent
04d3000a79
commit
d7dc025af6
@ -1,13 +1,23 @@
|
|||||||
|
pinboard_export = File.expand_path(ENV.fetch("PINBOARD_EXPORT"))
|
||||||
|
|
||||||
Sequel.migration do
|
Sequel.migration do
|
||||||
change do
|
up do
|
||||||
create_table(:pinboard) do
|
create_table(:pinboard) do
|
||||||
primary_key :id
|
primary_key :id
|
||||||
foreign_key :entity_id, :entities
|
foreign_key :entity_id, :entities, null: false, unique: true
|
||||||
|
|
||||||
String :json, text: true, null: false
|
String :json, text: true, null: false
|
||||||
|
|
||||||
DateTime :created_at, null: false
|
DateTime :created_at, null: false
|
||||||
DateTime :modified_at, null: false
|
DateTime :modified_at, null: false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
File.foreach(pinboard_export).with_index do |line, i|
|
||||||
|
created_at = modified_at = DateTime.now
|
||||||
|
json = line.chomp
|
||||||
|
|
||||||
|
entity_id = DB[:entities].insert(created_at:, modified_at:)
|
||||||
|
DB[:pinboard].insert(entity_id:, json: , created_at:, modified_at:)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,7 +0,0 @@
|
|||||||
Sequel.migration do
|
|
||||||
change do
|
|
||||||
alter_table(:pinboard) do
|
|
||||||
add_unique_constraint(:entity_id)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
@ -0,0 +1,32 @@
|
|||||||
|
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 :modified_at, null: false
|
||||||
|
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 = modified_at = DateTime.now
|
||||||
|
|
||||||
|
DB[:titles].insert(entity_id:, title:, created_at:, modified_at:)
|
||||||
|
DB[:notes].insert(entity_id:, text:, created_at:, modified_at:)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
down do
|
||||||
|
drop_table(:titles)
|
||||||
|
end
|
||||||
|
end
|
@ -1,15 +0,0 @@
|
|||||||
require "json"
|
|
||||||
|
|
||||||
require_relative "../db"
|
|
||||||
|
|
||||||
entities = DB[:entities]
|
|
||||||
pinboard = DB[:pinboard]
|
|
||||||
|
|
||||||
path = File.expand_path("~/Downloads/pinboard_export.2023.11.11_23.05.json_nd")
|
|
||||||
File.foreach(path).with_index do |line, i|
|
|
||||||
created_at = modified_at = DateTime.now
|
|
||||||
json = line.chomp
|
|
||||||
|
|
||||||
entity_id = entities.insert(created_at:, modified_at:)
|
|
||||||
pinboard.insert(entity_id:, json: , created_at:, modified_at:)
|
|
||||||
end
|
|
Loading…
Reference in new issue