From 2101587102e1158ef389e7de05a52126b0c35a14 Mon Sep 17 00:00:00 2001 From: Alpha Chen Date: Sun, 12 Nov 2023 15:33:44 -0800 Subject: [PATCH] create urls --- db/migrations/005_create_urls.rb | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 db/migrations/005_create_urls.rb diff --git a/db/migrations/005_create_urls.rb b/db/migrations/005_create_urls.rb new file mode 100644 index 0000000..17b71b6 --- /dev/null +++ b/db/migrations/005_create_urls.rb @@ -0,0 +1,31 @@ +Sequel.migration do + up do + create_table(:urls) do + primary_key :id + foreign_key :entity_id, :entities, unique: true + + String :url, unique: true, null: false + + DateTime :created_at, null: false + DateTime :modified_at, null: false + end + + json = Sequel.sqlite_json_op(:json) + href = json.extract("$.href") + + DB[:pinboard] + .select_append(href.as(:href)) + .each do |pin| + entity_id = pin.fetch(:entity_id) + url = pin.fetch(:href) + created_at = modified_at = DateTime.now + + DB[:urls].insert(entity_id:, url:, created_at:, modified_at:) + end + end + + down do + drop_table(:tags) + drop_table(:entities_tags) + end +end