diff options
| author | eltrac <hi@eltr.ac> | 2026-10-23 10:21:17 +0800 |
|---|---|---|
| committer | eltrac <hi@eltr.ac> | 2026-10-23 10:21:27 +0800 |
| commit | c7ddb958d7f1630a273006898f83e1d6dc54c83b (patch) | |
| tree | 932c27c622cb1276abb6922ad5946625cdd3d067 | |
| parent | 6000bfb084d17dd4f4e6243d4dc6c5dbfc3af77d (diff) | |
migration: catch Exceptions while migrating database #76
| -rw-r--r-- | src/weepinbell/migration.clj | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/src/weepinbell/migration.clj b/src/weepinbell/migration.clj index 0667bc3..4883b99 100644 --- a/src/weepinbell/migration.clj +++ b/src/weepinbell/migration.clj @@ -1,8 +1,13 @@ (ns weepinbell.migration
(:require [weepinbell.storage.sqlite :as sqlite]
- [weepinbell.storage.edn-storage :as edns]))
+ [weepinbell.storage.edn-storage :as edns])
+ (:import [org.sqlite SQLiteException]))
-(defn edn->sqlite [edn-file sqlite-db]
+(defn edn->sqlite
+ "Given a EDN file and a SQLite DB path, migrate data from that
+ edn file to SQLite DB. It appends data to DB so the destination
+ db can be empty or it can has some data."
+ [edn-file sqlite-db]
{:pre [(some? edn-file) (some? sqlite-db)]}
(let [ds (sqlite/make-datasource sqlite-db)]
(sqlite/create-tables ds)
@@ -11,5 +16,12 @@ (doseq [wm wms]
(let [id (get-in wm [:webmention :id])]
(println "Appending webmention" id "to database")
- (sqlite/insert-webmention ds wm)))))
+ (try
+ (sqlite/insert-webmention ds wm)
+ (catch SQLiteException e
+ (println "Something wrong with data or database")
+ (println (.getMessage e)))
+ (catch Exception e
+ (println "Something unexpected happened.")
+ (println (.getMessage e))))))))
(println "Done")))
|
