rebuild pinboard data

main
Alpha Chen 1 year ago
parent 04d3000a79
commit d7dc025af6
Signed by: alpha
SSH Key Fingerprint: SHA256:3fOT8fiYQG/aK9ntivV3Bqtg8AYQ7q4nV6ZgihOA20g

@ -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

@ -10,8 +10,8 @@ Sequel.migration do
end end
create_table(:entities_tags) do create_table(:entities_tags) do
foreign_key :entity_id, :entities foreign_key :entity_id, :entities, null: false
foreign_key :tag_id, :tags foreign_key :tag_id, :tags, null: false
DateTime :created_at, null: false DateTime :created_at, null: false
DateTime :modified_at, null: false DateTime :modified_at, null: false

@ -1,7 +0,0 @@
Sequel.migration do
change do
alter_table(:pinboard) do
add_unique_constraint(:entity_id)
end
end
end

@ -2,7 +2,7 @@ Sequel.migration do
up do up do
create_table(:urls) do create_table(:urls) do
primary_key :id primary_key :id
foreign_key :entity_id, :entities, unique: true foreign_key :entity_id, :entities, null: false, unique: true
String :url, unique: true, null: false String :url, unique: true, null: false

@ -1,8 +1,8 @@
Sequel.migration do Sequel.migration do
change do change do
create_table(:sources) do create_table(:sources) do
foreign_key :entity_id, :entities foreign_key :entity_id, :entities, null: false
foreign_key :source_id, :entities foreign_key :source_id, :entities, null: false
DateTime :created_at, null: false DateTime :created_at, null: false
DateTime :modified_at, null: false DateTime :modified_at, null: false
@ -11,7 +11,7 @@ Sequel.migration do
end end
create_table(:notes) do create_table(:notes) do
foreign_key :entity_id, :entities foreign_key :entity_id, :entities, null: false
String :text, text: true String :text, text: true

@ -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…
Cancel
Save