import pinboard archive

main
Alpha Chen 1 year ago
parent 6a5c734ff1
commit 9d5d6dd057
Signed by: alpha
SSH Key Fingerprint: SHA256:3fOT8fiYQG/aK9ntivV3Bqtg8AYQ7q4nV6ZgihOA20g

@ -0,0 +1,5 @@
require "logger"
require "sequel"
DB = Sequel.connect(ENV.fetch("DATABASE_URL"), loggers: [Logger.new($stdout)])

@ -3,8 +3,8 @@ Sequel.migration do
create_table(:entities) do
primary_key :id
DateTime :created_at
DateTime :modified_at
DateTime :created_at, null: false
DateTime :modified_at, null: false
end
end
end

@ -0,0 +1,13 @@
Sequel.migration do
change do
create_table(:pinboard) do
primary_key :id
foreign_key :entity_id, :entities
String :json, text: true, null: false
DateTime :created_at, null: false
DateTime :modified_at, null: false
end
end
end

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

@ -0,0 +1,15 @@
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