Last active
March 22, 2026 07:43
-
-
Save 4shutosh/33af33932c3d5e776368bc30b59d0aa6 to your computer and use it in GitHub Desktop.
Self Hosting Logseq Patches - 21 March 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| diff --git a/deps/db-sync/start.sh b/deps/db-sync/start.sh | |
| --- a/deps/db-sync/start.sh | |
| +++ b/deps/db-sync/start.sh | |
| @@ -5,9 +5,12 @@ set -euo pipefail | |
| # Defaults match the local `yarn watch` app auth config. | |
| # Override these env vars for production pool values if needed. | |
| -: "${COGNITO_ISSUER:=https://cognito-idp.us-east-1.amazonaws.com/us-east-1_dtagLnju8}" | |
| -: "${COGNITO_CLIENT_ID:=69cs1lgme7p8kbgld8n5kseii6}" | |
| -: "${COGNITO_JWKS_URL:=https://cognito-idp.us-east-1.amazonaws.com/us-east-1_dtagLnju8/.well-known/jwks.json}" | |
| +: "${COGNITO_ISSUER:=https://cognito-idp.YOUR_REGION.amazonaws.com/YOUR_USER_POOL_ID}" | |
| +: "${COGNITO_CLIENT_ID:=YOUR_CLIENT_ID}" | |
| +: "${COGNITO_JWKS_URL:=https://cognito-idp.YOUR_REGION.amazonaws.com/YOUR_USER_POOL_ID/.well-known/jwks.json}" | |
| +: "${DB_SYNC_LOG_LEVEL:=info}" | |
| export DB_SYNC_PORT | |
| +export DB_SYNC_LOG_LEVEL | |
| export COGNITO_ISSUER | |
| export COGNITO_CLIENT_ID | |
| export COGNITO_JWKS_URL | |
| diff --git a/src/main/frontend/config.cljs b/src/main/frontend/config.cljs | |
| --- a/src/main/frontend/config.cljs | |
| +++ b/src/main/frontend/config.cljs | |
| @@ -28,23 +28,23 @@ | |
| (if ENABLE-FILE-SYNC-PRODUCTION | |
| - (do (def API-DOMAIN "api.logseq.com") | |
| - (def COGNITO-IDP "https://cognito-idp.us-east-1.amazonaws.com/") | |
| - (def COGNITO-CLIENT-ID "69cs1lgme7p8kbgld8n5kseii6") | |
| - (def REGION "us-east-1") | |
| - (def USER-POOL-ID "us-east-1_dtagLnju8") | |
| - (def IDENTITY-POOL-ID "us-east-1:d6d3b034-1631-402b-b838-b44513e93ee0") | |
| - (def OAUTH-DOMAIN "logseq-prod.auth.us-east-1.amazoncognito.com") | |
| - (def PUBLISH-API-BASE "https://logseq.io")) | |
| + (do (def API-DOMAIN "") | |
| + (def COGNITO-IDP "https://cognito-idp.YOUR_REGION.amazonaws.com/") | |
| + (def COGNITO-CLIENT-ID "YOUR_CLIENT_ID") | |
| + (def REGION "YOUR_REGION") | |
| + (def USER-POOL-ID "YOUR_USER_POOL_ID") | |
| + (def IDENTITY-POOL-ID "") | |
| + (def OAUTH-DOMAIN "YOUR_OAUTH_DOMAIN") | |
| + (def PUBLISH-API-BASE "")) | |
| - (do (def API-DOMAIN "api-dev.logseq.com") | |
| - (def COGNITO-IDP "https://cognito-idp.us-east-2.amazonaws.com/") | |
| - (def COGNITO-CLIENT-ID "1qi1uijg8b6ra70nejvbptis0q") | |
| - (def REGION "us-east-2") | |
| - (def USER-POOL-ID "us-east-2_kAqZcxIeM") | |
| - (def IDENTITY-POOL-ID "us-east-2:cc7d2ad3-84d0-4faf-98fe-628f6b52c0a5") | |
| - (def OAUTH-DOMAIN "logseq-test2.auth.us-east-2.amazoncognito.com") | |
| - (def PUBLISH-API-BASE "https://logseq-publish-staging.logseq.workers.dev"))) | |
| + (do (def API-DOMAIN "") | |
| + (def COGNITO-IDP "https://cognito-idp.YOUR_REGION.amazonaws.com/") | |
| + (def COGNITO-CLIENT-ID "YOUR_CLIENT_ID") | |
| + (def REGION "YOUR_REGION") | |
| + (def USER-POOL-ID "YOUR_USER_POOL_ID") | |
| + (def IDENTITY-POOL-ID "") | |
| + (def OAUTH-DOMAIN "YOUR_OAUTH_DOMAIN") | |
| + (def PUBLISH-API-BASE ""))) | |
| (defonce db-sync-ws-url | |
| (if db-sync-local? | |
| - "ws://127.0.0.1:8787/sync/%s" | |
| + "ws://YOUR_VPS_IP/sync/%s" | |
| "wss://logseq-sync-prod.logseq.workers.dev/sync/%s")) | |
| (defonce db-sync-http-base | |
| (if db-sync-local? | |
| - "http://127.0.0.1:8787" | |
| + "http://YOUR_VPS_IP" | |
| "https://logseq-sync-prod.logseq.workers.dev")) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| commit 477061ffb6fd7d1d60c8e8ee37841d0ac2b1422c | |
| Author: 4shutosh <4shutoshsingh@gmail.com> | |
| Date: Sat Mar 21 22:16:21 2026 +0530 | |
| self host things | |
| diff --git a/deps/db-sync/src/logseq/db_sync/malli_schema.cljs b/deps/db-sync/src/logseq/db_sync/malli_schema.cljs | |
| index 43acacbc8..2dde54a62 100644 | |
| --- a/deps/db-sync/src/logseq/db_sync/malli_schema.cljs | |
| +++ b/deps/db-sync/src/logseq/db_sync/malli_schema.cljs | |
| @@ -5,13 +5,13 @@ | |
| (def tx-entry-schema | |
| [:map | |
| [:tx :string] | |
| - [:outliner-op {:optional true} [:maybe :keyword]]]) | |
| + [:outliner-op {:optional true} :any]]) | |
| (def tx-log-entry-schema | |
| [:map | |
| [:t :int] | |
| [:tx :string] | |
| - [:outliner-op {:optional true} [:maybe :keyword]]]) | |
| + [:outliner-op {:optional true} :any]]) | |
| (def ws-client-message-schema | |
| [:multi {:dispatch :type} | |
| diff --git a/deps/db-sync/src/logseq/db_sync/worker/handler/sync.cljs b/deps/db-sync/src/logseq/db_sync/worker/handler/sync.cljs | |
| index d502d2f82..974e36db6 100644 | |
| --- a/deps/db-sync/src/logseq/db_sync/worker/handler/sync.cljs | |
| +++ b/deps/db-sync/src/logseq/db_sync/worker/handler/sync.cljs | |
| @@ -325,7 +325,8 @@ | |
| [conn {:keys [tx outliner-op]}] | |
| (let [tx-data (sanitize-client-tx-data conn tx)] | |
| (when (seq tx-data) | |
| - (ldb/transact! conn tx-data (cond-> {:op :apply-client-tx} | |
| + (ldb/transact! conn tx-data (cond-> {:op :apply-client-tx | |
| + :skip-validate-db? true} | |
| outliner-op (assoc :outliner-op outliner-op)))))) | |
| (defn- db-transact-failed-response | |
| diff --git a/deps/db/src/logseq/db.cljs b/deps/db/src/logseq/db.cljs | |
| index eefd039ae..7acb42f93 100644 | |
| --- a/deps/db/src/logseq/db.cljs | |
| +++ b/deps/db/src/logseq/db.cljs | |
| @@ -115,12 +115,17 @@ | |
| (let [tx-report* (d/with db tx-data tx-meta) | |
| pipeline-f @*transact-pipeline-fn | |
| tx-report (if-let [f pipeline-f] (f tx-report*) tx-report*) | |
| - _ (throw-if-page-has-block-parent! (:db-after tx-report) (:tx-data tx-report)) | |
| + _ (when-not (:rtc-tx? tx-meta) | |
| + (throw-if-page-has-block-parent! (:db-after tx-report) (:tx-data tx-report))) | |
| [validate-result errors] (db-validate/validate-tx-report tx-report nil)] | |
| (cond | |
| - validate-result | |
| + (or validate-result (:rtc-tx? tx-meta)) | |
| (when (and tx-report (seq (:tx-data tx-report))) | |
| ;; perf enhancement: avoid repeated call on `d/with` | |
| + (when (and (not validate-result) (seq errors)) | |
| + ;; notify ui about validation issues but don't block sync | |
| + (when-let [f @*transact-invalid-callback] | |
| + (f tx-report errors))) | |
| (reset! conn (:db-after tx-report)) | |
| (dc/store-after-transact! conn tx-report) | |
| (dc/run-callbacks conn tx-report)) | |
| diff --git a/src/main/frontend/handler/user.cljs b/src/main/frontend/handler/user.cljs | |
| index b2d4cfa7f..347e24744 100644 | |
| --- a/src/main/frontend/handler/user.cljs | |
| +++ b/src/main/frontend/handler/user.cljs | |
| @@ -312,7 +312,8 @@ | |
| (defn rtc-group? | |
| [] | |
| - (boolean (seq (set/intersection (state/user-groups) #{"team" "rtc_2025_07_10"})))) | |
| + (or config/db-sync-local? | |
| + (boolean (seq (set/intersection (state/user-groups) #{"team" "rtc_2025_07_10"}))))) | |
| (defn alpha-user? | |
| [] | |
| @@ -480,4 +481,4 @@ | |
| (case (feature feature-matrix) | |
| :beta (alpha-or-beta-user?) | |
| :alpha (alpha-user?) | |
| - false))))) | |
| + false))))) | |
| \ No newline at end of file | |
| diff --git a/src/main/frontend/worker/pipeline.cljs b/src/main/frontend/worker/pipeline.cljs | |
| index 557e2017f..004d43a04 100644 | |
| --- a/src/main/frontend/worker/pipeline.cljs | |
| +++ b/src/main/frontend/worker/pipeline.cljs | |
| @@ -480,7 +480,8 @@ | |
| [{:keys [db-after tx-meta _tx-data] :as tx-report}] | |
| (or | |
| (when-not (:sync-download-graph? tx-meta) | |
| - (ensure-journal-page-protected-attrs-not-updated! tx-report) | |
| + (when-not (:rtc-tx? tx-meta) | |
| + (ensure-journal-page-protected-attrs-not-updated! tx-report)) | |
| (let [extra-tx-data (compute-extra-tx-data tx-report) | |
| tx-report* (if (seq extra-tx-data) | |
| (let [result (d/with db-after extra-tx-data)] | |
| diff --git a/src/main/frontend/worker/sync.cljs b/src/main/frontend/worker/sync.cljs | |
| index 4afdd371c..f37840993 100644 | |
| --- a/src/main/frontend/worker/sync.cljs | |
| +++ b/src/main/frontend/worker/sync.cljs | |
| @@ -194,7 +194,13 @@ | |
| (set! (.-onmessage ws) | |
| (fn [event] | |
| (touch-last-ws-message! client) | |
| - (sync-handle-message/handle-message! repo client (.-data event)))) | |
| + (-> (sync-handle-message/handle-message! repo client (.-data event)) | |
| + (p/catch (fn [e] | |
| + (js/console.error "[sync] handle-message failed" e) | |
| + (log/error :db-sync/handle-message-failed {:repo repo :error e}) | |
| + (shared-service/broadcast-to-clients! | |
| + :notification | |
| + [[(str "Sync error: " (ex-message e))] :error])))))) | |
| (set! (.-onerror ws) (fn [error] (log/error :db-sync/ws-error error))) | |
| (set! (.-onclose ws) | |
| (fn [_] | |
| diff --git a/src/main/frontend/worker/sync/apply_txs.cljs b/src/main/frontend/worker/sync/apply_txs.cljs | |
| index 58fb663de..368471b23 100644 | |
| --- a/src/main/frontend/worker/sync/apply_txs.cljs | |
| +++ b/src/main/frontend/worker/sync/apply_txs.cljs | |
| @@ -668,14 +668,18 @@ | |
| payload (mapv (fn [{:keys [tx-data outliner-op]}] | |
| (cond-> {:tx (sqlite-util/write-transit-str tx-data)} | |
| outliner-op | |
| - (assoc :outliner-op outliner-op))) | |
| + (assoc :outliner-op (if (keyword? outliner-op) | |
| + (name outliner-op) | |
| + outliner-op)))) | |
| tx-entries*)] | |
| (reset! (:inflight client) tx-ids) | |
| (send! ws {:type "tx/batch" | |
| :t-before local-tx | |
| :txs payload})) | |
| (p/catch (fn [error] | |
| - (js/console.error error)))))))))))))) | |
| + (shared-service/broadcast-to-clients! | |
| + :notification | |
| + [[(str "Sync push failed: " (ex-message error))] :error])))))))))))))) | |
| (defn- combine-tx-reports | |
| [tx-reports] | |
| @@ -761,9 +765,11 @@ | |
| index 0 | |
| results []] | |
| (if-let [remote-tx (first remaining)] | |
| - (let [tx-data (->> (:tx-data remote-tx) | |
| + (let [db @temp-conn | |
| + tx-data (->> (:tx-data remote-tx) | |
| rewrite-recreated-lookup-refs | |
| - (sanitize-tx-data @temp-conn) | |
| + (replace-string-block-tempids-with-lookups db) | |
| + (sanitize-tx-data db) | |
| seq) | |
| results' (cond-> results | |
| tx-data | |
| @@ -1068,26 +1074,30 @@ | |
| (apply-remote-tx-with-local-changes! apply-context) | |
| (apply-remote-tx-without-local-changes! apply-context)) | |
| (catch :default error | |
| - (log/error :db-sync/apply-remote-txs-failed | |
| - {:repo repo | |
| - :has-local-changes? has-local-changes? | |
| - :remote-tx-count (count remote-txs) | |
| - :local-tx-count (count local-txs) | |
| - :remote-txs (mapv (fn [{:keys [t outliner-op tx-data]}] | |
| - {:t t | |
| - :outliner-op outliner-op | |
| - :tx-data-count (count tx-data) | |
| - :tx-data-preview (take 12 tx-data)}) | |
| - remote-txs) | |
| - :local-txs (mapv (fn [{:keys [tx-id outliner-op tx reversed-tx]}] | |
| - {:tx-id tx-id | |
| - :outliner-op outliner-op | |
| - :tx-count (count tx) | |
| - :tx-preview (take 12 tx) | |
| - :reversed-count (count reversed-tx) | |
| - :reversed-preview (take 12 reversed-tx)}) | |
| - local-txs) | |
| - :error error}) | |
| + (do | |
| + (log/error :db-sync/apply-remote-txs-failed | |
| + {:repo repo | |
| + :has-local-changes? has-local-changes? | |
| + :remote-tx-count (count remote-txs) | |
| + :local-tx-count (count local-txs) | |
| + :remote-txs (mapv (fn [{:keys [t outliner-op tx-data]}] | |
| + {:t t | |
| + :outliner-op outliner-op | |
| + :tx-data-count (count tx-data) | |
| + :tx-data-preview (take 12 tx-data)}) | |
| + remote-txs) | |
| + :local-txs (mapv (fn [{:keys [tx-id outliner-op tx reversed-tx]}] | |
| + {:tx-id tx-id | |
| + :outliner-op outliner-op | |
| + :tx-count (count tx) | |
| + :tx-preview (take 12 tx) | |
| + :reversed-count (count reversed-tx) | |
| + :reversed-preview (take 12 reversed-tx)}) | |
| + local-txs) | |
| + :error error}) | |
| + (shared-service/broadcast-to-clients! | |
| + :notification | |
| + [[(str "Sync failed: " (ex-message error))] :error])) | |
| (throw error))) | |
| remote-tx-report @*remote-tx-report] | |
| (when has-local-changes? | |
| diff --git a/src/main/frontend/worker/sync/handle_message.cljs b/src/main/frontend/worker/sync/handle_message.cljs | |
| index 2789a111b..c63fbd2d0 100644 | |
| --- a/src/main/frontend/worker/sync/handle_message.cljs | |
| +++ b/src/main/frontend/worker/sync/handle_message.cljs | |
| @@ -130,6 +130,17 @@ | |
| :local-checksum local-checksum | |
| :remote-checksum remote-checksum})))))) | |
| +(defn- handle-server-error! | |
| + [repo client message] | |
| + (let [error-msg (or (:message message) "unknown server error")] | |
| + (js/console.error "[sync] server error response" error-msg) | |
| + (log/error :db-sync/server-error {:repo repo :error error-msg}) | |
| + (when-let [inflight (:inflight client)] | |
| + (reset! inflight [])) | |
| + (shared-service/broadcast-to-clients! | |
| + :notification | |
| + [[(str "Sync server error: " error-msg)] :warning]))) | |
| + | |
| (defn- handle-tx-reject! | |
| [repo client message local-tx] | |
| (let [reason (:reason message) | |
| @@ -141,8 +152,11 @@ | |
| (require-non-negative remote-tx {:repo repo :type "tx/reject"})) | |
| (case reason | |
| "stale" | |
| - (when (and (:ws client) (ws-open? (:ws client))) | |
| - (send! (:ws client) {:type "pull" :since local-tx})) | |
| + (do | |
| + (when-let [inflight (:inflight client)] | |
| + (reset! inflight [])) | |
| + (when (and (:ws client) (ws-open? (:ws client))) | |
| + (send! (:ws client) {:type "pull" :since local-tx}))) | |
| (let [data (when-let [raw-data (:data message)] | |
| (parse-transit raw-data | |
| @@ -257,5 +271,6 @@ | |
| "pull/ok" (handle-pull-ok! repo client local-tx remote-tx remote-checksum message) | |
| "changed" (handle-changed! repo client local-tx remote-tx) | |
| "tx/reject" (handle-tx-reject! repo client message local-tx) | |
| + "error" (handle-server-error! repo client message) | |
| (fail-fast :db-sync/invalid-field | |
| {:repo repo :type (:type message)}))))) |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
More details on what, why and how here
https://medium.com/@4shutosh/how-to-self-host-logseq-db-graph-sync-d62d589f06a4
https://4shutosh.com/selfhost-logseq