Best way to mass import links?
-
I have exported all my Bitly links and was curious what the best way to import ~2k records would be. There's an API call for creating one URL at a time... so I could loop through them with some pacing in between, but was curious if it's possible to access Kutt's database directly and import them that way... or if that's more trouble then it's worth.
Any thoughts would be appreciated!
-
@ajtatum From my quick testing, there is just a table called
links
. Might be easy to script this.id | address | description | banned | banned_by_id | domain_id | password | expire_in | target | user_id | visit_count | created_at | updated_at | uuid ----+---------+-------------+--------+--------------+-----------+----------+-----------+---------------------+---------+-------------+-------------------------------+-------------------------------+-------------------------------------- 1 | iL6uu0 | | f | | | | | https://cloudron.io | 2 | 0 | 2022-12-12 12:06:41.689773+00 | 2022-12-12 12:06:41.689773+00 | 65320acc-e34e-4341-8c35-2bdfd898c9d9
-
Further....
db81c034f66d9c4cc29c7811bb89b95f24=> \d links Table "public.links" Column | Type | Collation | Nullable | Default --------------+--------------------------+-----------+----------+----------------------------------- id | integer | | not null | nextval('links_id_seq'::regclass) address | character varying(255) | | not null | description | character varying(255) | | | banned | boolean | | not null | false banned_by_id | integer | | | domain_id | integer | | | password | character varying(255) | | | expire_in | timestamp with time zone | | | target | character varying(2040) | | not null | user_id | integer | | | visit_count | integer | | not null | 0 created_at | timestamp with time zone | | not null | CURRENT_TIMESTAMP updated_at | timestamp with time zone | | not null | CURRENT_TIMESTAMP uuid | uuid | | not null | uuid_generate_v4() Indexes: "links_pkey" PRIMARY KEY, btree (id) Foreign-key constraints: "links_banned_by_id_foreign" FOREIGN KEY (banned_by_id) REFERENCES users(id) "links_domain_id_foreign" FOREIGN KEY (domain_id) REFERENCES domains(id) "links_user_id_foreign" FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE Referenced by: TABLE "visits" CONSTRAINT "visits_link_id_foreign" FOREIGN KEY (link_id) REFERENCES links(id) ON DELETE CASCADE
So, then, I tried
db81c034f66d9c4cc29c7811bb89b95f24=> INSERT INTO links (address, target, user_id) VALUES ('x1234', 'https://blog.cloudron.io', 2); INSERT 0 1
Visiting
x1234
redirects properly. So, quite easy to script this. Note that 2 is the user id, might have to check the db what the user id is in your case.