Liking cljdoc? Tell your friends :D

patcho.patch

A simple version migration system for Clojure applications.

Patcho provides a declarative way to define version-based patches that can be applied to migrate between different versions of your application or modules.

Key features:

  • Automatic patch sequencing based on semantic versioning
  • Support for both upgrades and downgrades
  • Topic-based organization for modular systems
  • Simple macro-based API

Basic usage: (require '[patcho.patch :as patch])

; Define current version (patch/current-version ::my-app "2.0.0")

; Define upgrade patches (patch/upgrade ::my-app "1.0.0" (println "Initial setup"))

(patch/upgrade ::my-app "2.0.0" (println "Major upgrade"))

; Apply patches (patch/apply ::my-app "1.0.0") ; Runs 2.0.0 upgrade (patch/apply ::my-app nil) ; Runs all upgrades

A simple version migration system for Clojure applications.

Patcho provides a declarative way to define version-based patches that can be
applied to migrate between different versions of your application or modules.

Key features:
- Automatic patch sequencing based on semantic versioning
- Support for both upgrades and downgrades
- Topic-based organization for modular systems
- Simple macro-based API

Basic usage:
  (require '[patcho.patch :as patch])
  
  ; Define current version
  (patch/current-version ::my-app "2.0.0")
  
  ; Define upgrade patches
  (patch/upgrade ::my-app "1.0.0"
    (println "Initial setup"))
  
  (patch/upgrade ::my-app "2.0.0"
    (println "Major upgrade"))
  
  ; Apply patches
  (patch/apply ::my-app "1.0.0")  ; Runs 2.0.0 upgrade
  (patch/apply ::my-app nil)        ; Runs all upgrades
raw docstring

_downgradecljmultimethod


_upgradecljmultimethod


applyclj

(apply topic)
(apply topic current)
(apply topic current target)

Applies version patches to migrate from one version to another.

With 1 args: Migrates from 'last-deployed-version' to the topic's defined current version. With 2 args: Migrates from 'current' to the topic's defined current version. With 3 args: Migrates from 'current' to 'target' version.

Arguments: topic - Keyword identifying the module/component to patch current - Current version string (nil or "0" means start from beginning)
target - Target version string (optional, defaults to topic's current version)

The function automatically:

  • Determines upgrade vs downgrade direction
  • Finds applicable patches between versions
  • Executes patches in correct order (oldest-first for upgrades, newest-first for downgrades)

Example: (apply ::my-app "1.0.0" "2.0.0") ; Upgrade from 1.0.0 to 2.0.0 (apply ::my-app "2.0.0" "1.0.0") ; Downgrade from 2.0.0 to 1.0.0 (apply ::my-app nil) ; Upgrade from beginning to current

Applies version patches to migrate from one version to another.

With 1 args: Migrates from 'last-deployed-version' to the topic's defined current version.
With 2 args: Migrates from 'current' to the topic's defined current version.
With 3 args: Migrates from 'current' to 'target' version.

Arguments:
  topic   - Keyword identifying the module/component to patch
  current - Current version string (nil or "0" means start from beginning)  
  target  - Target version string (optional, defaults to topic's current version)
  
The function automatically:
  - Determines upgrade vs downgrade direction
  - Finds applicable patches between versions
  - Executes patches in correct order (oldest-first for upgrades, newest-first for downgrades)
  
Example:
  (apply ::my-app "1.0.0" "2.0.0")  ; Upgrade from 1.0.0 to 2.0.0
  (apply ::my-app "2.0.0" "1.0.0")  ; Downgrade from 2.0.0 to 1.0.0
  (apply ::my-app nil)                ; Upgrade from beginning to current
raw docstring

available-versionsclj

(available-versions & topics)

Returns a map of topics to their current versions.

With no args: Returns all registered topic versions. With args: Returns versions only for specified topics.

Arguments: topics - Zero or more topic keywords to query

Returns: Map of {topic version-string} for registered topics

Example: (available-versions) ; => {:app "2.0.0" :db "1.5.0"} (available-versions :app) ; => {:app "2.0.0"} (available-versions :app :db :unknown) ; => {:app "2.0.0" :db "1.5.0"}

Returns a map of topics to their current versions.

With no args: Returns all registered topic versions.
With args: Returns versions only for specified topics.

Arguments:
  topics - Zero or more topic keywords to query
  
Returns:
  Map of {topic version-string} for registered topics
  
Example:
  (available-versions)                    ; => {:app "2.0.0" :db "1.5.0"}
  (available-versions :app)               ; => {:app "2.0.0"}
  (available-versions :app :db :unknown)  ; => {:app "2.0.0" :db "1.5.0"}
raw docstring

current-versioncljmacro

(current-version topic & body)

Defines the current/target version for a topic.

This version is used as the default target when calling apply with only 2 arguments.

Arguments: topic - Keyword identifying the module/component body - Should return a version string

Example: (current-version ::my-app "2.5.0")

; Can also compute version dynamically (current-version ::my-app (read-version-from-file))

Defines the current/target version for a topic.

This version is used as the default target when calling apply
with only 2 arguments.

Arguments:
  topic   - Keyword identifying the module/component
  body    - Should return a version string
  
Example:
  (current-version ::my-app "2.5.0")
  
  ; Can also compute version dynamically
  (current-version ::my-app 
    (read-version-from-file))
raw docstring

deployed-versioncljmultimethod


downgradecljmacro

(downgrade topic to & body)

Defines code to execute when downgrading FROM the specified version.

The body will be executed when applying patches that include this version in the downgrade path. Note: downgrade happens FROM this version to a lower version.

Arguments: topic - Keyword identifying the module/component to - Version string this downgrade migrates FROM body - Code to execute for the downgrade

Example: (downgrade ::database "2.0.0" (drop-column :users :preferences) (restore-legacy-settings))

Defines code to execute when downgrading FROM the specified version.

The body will be executed when applying patches that include this version
in the downgrade path. Note: downgrade happens FROM this version to a 
lower version.

Arguments:
  topic   - Keyword identifying the module/component
  to      - Version string this downgrade migrates FROM
  body    - Code to execute for the downgrade
  
Example:
  (downgrade ::database "2.0.0"
    (drop-column :users :preferences)
    (restore-legacy-settings))
raw docstring

previous-versioncljmacro

(previous-version topic & body)

Defines the last installed version for a topic.

This version is used when calling apply with only 1 arguments.

Arguments: topic - Keyword identifying the module/component body - Should return a version string

Example: (previous-version ::my-app "2.5.0")

; Can also compute version dynamically (current-version ::my-app (read-version-from-file))

Defines the last installed version for a topic.

This version is used when calling apply
with only 1 arguments.

Arguments:
  topic   - Keyword identifying the module/component
  body    - Should return a version string
  
Example:
  (previous-version ::my-app "2.5.0")
  
  ; Can also compute version dynamically
  (current-version ::my-app 
    (read-version-from-file))
raw docstring

upgradecljmacro

(upgrade topic to & body)

Defines code to execute when upgrading TO the specified version.

The body will be executed when applying patches that include this version in the upgrade path.

Arguments: topic - Keyword identifying the module/component to - Version string this upgrade migrates TO body - Code to execute for the upgrade

Example: (upgrade ::database "2.0.0" (add-column :users :preferences :jsonb) (migrate-user-settings))

Defines code to execute when upgrading TO the specified version.

The body will be executed when applying patches that include this version
in the upgrade path.

Arguments:
  topic   - Keyword identifying the module/component
  to      - Version string this upgrade migrates TO
  body    - Code to execute for the upgrade
  
Example:
  (upgrade ::database "2.0.0"
    (add-column :users :preferences :jsonb)
    (migrate-user-settings))
raw docstring

versioncljmultimethod

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close