Skip to content

Commit

Permalink
Add roswell script for automatic installation
Browse files Browse the repository at this point in the history
Use define-package instead of defpackage.
This avoids compile errors when recompiling using
sbcl. It essentially also happens the the ros script
binary is installed.

Add installation instructions to README.
  • Loading branch information
justjoheinz authored and dnaeon committed Dec 7, 2023
1 parent 769cea0 commit 938278e
Show file tree
Hide file tree
Showing 15 changed files with 108 additions and 83 deletions.
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,13 @@ The following systems are available as part of this repo.

## Installation

Latest development version can be installed from the Git repo.
Installation is possible via [roswell](https://github.com/roswell/roswell). This will also build the `migratum` binary (see section CLI):

``` shell
ros install cl-migratum
```

The latest development version can be installed from the Git repo.

Clone the [cl-migratum](https://github.com/dnaeon/cl-migratum) repo in your
[Quicklisp local-projects directory](https://www.quicklisp.org/beta/faq.html).
Expand Down
1 change: 1 addition & 0 deletions cl-migratum.asd
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
:depends-on (:local-time
:cl-ascii-table
:cl-reexport
:uiop
:log4cl)
:components ((:module "util"
:pathname #P"src/"
Expand Down
19 changes: 19 additions & 0 deletions roswell/migratum.ros
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/sh
#|-*- mode:lisp -*-|#
#|
exec ros -Q -- $0 "$@"
|#
(progn ;;init forms
(ros:ensure-asdf)
#+quicklisp(ql:quickload '(:cl-migratum.cli) :silent t)
)

(defpackage :ros.script.migratum.3910874952
(:use :cl))

(in-package :ros.script.migratum.3910874952)

(defun main (&rest argv)
(declare (ignorable argv))
(cl-migratum.cli:main argv))
;;; vim: set ft=lisp lisp:
4 changes: 2 additions & 2 deletions src/cli/main.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@
:handler #'top-level/handler
:pre-hook #'top-level/pre-hook))

(defun main ()
(defun main (&optional argv)
"Main CLI entrypoint"
(let ((app (top-level/command)))
(clingon:run app)))
(clingon:run app argv)))
2 changes: 1 addition & 1 deletion src/cli/package.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
;; THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

(in-package :cl-user)
(defpackage :cl-migratum.cli
(uiop:define-package :cl-migratum.cli
(:use :cl)
(:nicknames :migratum.cli)
(:import-from :clingon)
Expand Down
2 changes: 1 addition & 1 deletion src/core.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
;; THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

(in-package :cl-user)
(defpackage :cl-migratum.core
(uiop:define-package :cl-migratum.core
(:use :cl)
(:nicknames :migratum.core)
(:import-from :ascii-table)
Expand Down
2 changes: 1 addition & 1 deletion src/driver/dbi.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
;; THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

(in-package :cl-user)
(defpackage :cl-migratum.driver.dbi
(uiop:define-package :cl-migratum.driver.dbi
(:use :cl)
(:nicknames :migratum.driver.dbi)
(:import-from
Expand Down
2 changes: 1 addition & 1 deletion src/driver/mixins/mixins.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
;; THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

(in-package :cl-user)
(defpackage :cl-migratum.driver.mixins
(uiop:define-package :cl-migratum.driver.mixins
(:nicknames :migratum.driver.mixins)
(:use :cl)
(:import-from
Expand Down
22 changes: 11 additions & 11 deletions src/driver/postmodern-postgresql.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
;; THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

(in-package :cl-user)
(defpackage :cl-migratum.driver.postmodern-postgresql
(uiop:define-package :cl-migratum.driver.postmodern-postgresql
(:use :cl)
(:nicknames :migratum.driver.postmodern-postgresql)
(:import-from
Expand Down Expand Up @@ -90,7 +90,7 @@ CREATE TABLE IF NOT EXISTS migration (
(defmethod driver-init ((driver postmodern-postgresql-driver) &key)
(log:debug "[POSTMODERN-PGSQL] Initializing ~A driver" (driver-name driver))
(pomo:with-transaction ()
(pomo:query *sql-init-schema*))
(pomo:query *sql-init-schema*))
(setf (driver-initialized driver) t))

(defmethod driver-shutdown ((driver postmodern-postgresql-driver) &key)
Expand Down Expand Up @@ -126,16 +126,16 @@ CREATE TABLE IF NOT EXISTS migration (
(let ((query (format nil "INSERT INTO migration (id, description, kind) ~
VALUES (~A, '~A', '~A')" id description kind)))
(pomo:with-transaction ()
(pomo:query query)))))
(pomo:query query)))))

(defmethod driver-register-migration ((direction (eql :down)) (driver postmodern-postgresql-driver)
migration &key)
(log:debug "[POSTMODERN-PGSQL] Unregistering migration: ~A" (migration-id migration))
(with-accessors ((id migration-id))
migration
(let ((query (format nil "DELETE FROM migration WHERE id = ~A" id)))
(pomo:with-transaction ()
(pomo:query query)))))
(with-accessors ((id migration-id))
migration
(let ((query (format nil "DELETE FROM migration WHERE id = ~A" id)))
(pomo:with-transaction ()
(pomo:query query)))))

(defmethod driver-apply-migration ((direction (eql :up)) (kind (eql :sql))
(driver postmodern-postgresql-driver) migration &key)
Expand Down Expand Up @@ -169,6 +169,6 @@ Arguments:
(log:debug "[POSTMODERN-PGSQL] Applying ~A migration: ~A - ~A (~A)"
direction id description kind)
(pomo:with-transaction ()
(dolist (statement statements)
(let ((stmt (string-trim #(#\Newline) statement)))
(pomo:query stmt)))))))
(dolist (statement statements)
(let ((stmt (string-trim #(#\Newline) statement)))
(pomo:query stmt)))))))
16 changes: 8 additions & 8 deletions src/driver/rdbms-postgresql.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
;; THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

(in-package :cl-user)
(defpackage :cl-migratum.driver.rdbms-postgresql
(uiop:define-package :cl-migratum.driver.rdbms-postgresql
(:use :cl)
(:nicknames :migratum.driver.rdbms-postgresql)
(:import-from
Expand All @@ -47,7 +47,7 @@
(:import-from :log)
(:import-from :hu.dwim.logger
:+warn+
:set-log-level)
:set-log-level)
(:import-from :hu.dwim.rdbms.postgresql)
(:import-from :cl-ppcre)
(:export
Expand Down Expand Up @@ -96,7 +96,7 @@ CREATE TABLE IF NOT EXISTS migration (
(query *sql-init-schema*))
(hu.dwim.rdbms:with-database database
(hu.dwim.rdbms:with-transaction
(hu.dwim.rdbms:execute query)))
(hu.dwim.rdbms:execute query)))
(setf (driver-initialized driver) t)))

(defmethod driver-shutdown ((driver rdbms-postgresql-driver) &key)
Expand Down Expand Up @@ -126,7 +126,7 @@ CREATE TABLE IF NOT EXISTS migration (
(query (format nil "INSERT INTO migration (id, description, kind) VALUES (~A, '~A', '~A')" id description kind)))
(hu.dwim.rdbms:with-database db
(hu.dwim.rdbms:with-transaction
(hu.dwim.rdbms:execute query)))))
(hu.dwim.rdbms:execute query)))))

(defmethod driver-register-migration ((direction (eql :down)) (driver rdbms-postgresql-driver)
migration &key)
Expand All @@ -136,7 +136,7 @@ CREATE TABLE IF NOT EXISTS migration (
(query (format nil "DELETE FROM migration WHERE id = ~A" id)))
(hu.dwim.rdbms:with-database db
(hu.dwim.rdbms:with-transaction
(hu.dwim.rdbms:execute query)))))
(hu.dwim.rdbms:execute query)))))

(defmethod driver-apply-migration ((direction (eql :up)) (kind (eql :sql))
(driver rdbms-postgresql-driver) migration &key)
Expand Down Expand Up @@ -170,6 +170,6 @@ Arguments:
(log:debug "[RDBMS-PGSQL] Applying ~A migration: ~A - ~A (~A)" direction id description kind)
(hu.dwim.rdbms:with-database db
(hu.dwim.rdbms:with-transaction
(dolist (statement statements)
(let ((stmt (string-trim #(#\Newline) statement)))
(hu.dwim.rdbms:execute stmt)))))))
(dolist (statement statements)
(let ((stmt (string-trim #(#\Newline) statement)))
(hu.dwim.rdbms:execute stmt)))))))
2 changes: 1 addition & 1 deletion src/package.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
;; THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

(in-package :cl-user)
(defpackage :cl-migratum
(uiop:define-package :cl-migratum
(:nicknames :migratum)
(:use :cl))
(in-package :cl-migratum)
Expand Down
22 changes: 11 additions & 11 deletions src/provider/local-path.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
;; THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

(in-package :cl-user)
(defpackage :cl-migratum.provider.local-path
(uiop:define-package :cl-migratum.provider.local-path
(:use :cl)
(:nicknames :migratum.provider.local-path)
(:import-from :log)
Expand Down Expand Up @@ -188,16 +188,16 @@ discovered from the given PATHS."
"Groups migration files by id. Each group consists of the upgrade and downgrade scripts."
(reduce (lambda (acc file)
(cl-ppcre:register-groups-bind (id description direction extension)
(scanner (namestring file))
(let* ((id (parse-integer id))
(group (gethash id acc nil)))
(setf (gethash id acc)
(push (list :id id
:direction direction
:description description
:path file
:extension extension)
group))))
(scanner (namestring file))
(let* ((id (parse-integer id))
(group (gethash id acc nil)))
(setf (gethash id acc)
(push (list :id id
:direction direction
:description description
:path file
:extension extension)
group))))
acc)
files
:initial-value (make-hash-table :test #'equal)))
Expand Down
2 changes: 1 addition & 1 deletion src/util.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
;; THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

(in-package :cl-user)
(defpackage :cl-migratum.util
(uiop:define-package :cl-migratum.util
(:use :cl)
(:nicknames :migratum.util)
(:export
Expand Down
25 changes: 12 additions & 13 deletions t/20220327224455-migration.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
;; THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

(in-package :cl-user)
(defpackage :cl-migratum.test.20220327224455
(uiop:define-package :cl-migratum.test.20220327224455
(:use :cl)
(:import-from :cl-dbi)
(:import-from :cl-migratum.driver.dbi)
Expand Down Expand Up @@ -91,7 +91,7 @@
(hu.dwim.rdbms:with-database db
;; Create the schema and populate it with some data
(hu.dwim.rdbms:with-transaction
(hu.dwim.rdbms:execute schema)
(hu.dwim.rdbms:execute schema)
(loop :for i :from 1 :to 42
:for name = (format nil "name-~A" i)
:for value = (+ i 42) :do
Expand All @@ -103,25 +103,24 @@
(query "DROP TABLE lisp_code_table"))
(hu.dwim.rdbms:with-database db
(hu.dwim.rdbms:with-transaction
(hu.dwim.rdbms:execute query)))))
(hu.dwim.rdbms:execute query)))))

(defun %pomo-pgsql-apply-up (driver)
"POMO-POSTGRESQL upgrade handler for migration id 20220327224455"
(declare (ignore driver))
(let ((schema *table-schema*)
(populate-stmt "INSERT INTO lisp_code_table (id, name, value) VALUES (~A, '~A', ~A)"))
;; Create the schema and populate it with some data
(pomo:with-transaction ()
(pomo:query schema)
(loop :for i :from 1 :to 42
:for name = (format nil "name-~A" i)
:for value = (+ i 42) :do
(pomo:query (format nil populate-stmt i name value))))))
;; Create the schema and populate it with some data
(pomo:with-transaction ()
(pomo:query schema)
(loop :for i :from 1 :to 42
:for name = (format nil "name-~A" i)
:for value = (+ i 42) :do
(pomo:query (format nil populate-stmt i name value))))))

(defun %pomo-pgsql-apply-down (driver)
"POMO-POSTGRESQL downgrade handler for migration id 20220327224455"
(declare (ignore driver))
(let ((query "DROP TABLE lisp_code_table"))
(pomo:with-transaction ()
(pomo:query query))))

(pomo:with-transaction ()
(pomo:query query))))
62 changes: 31 additions & 31 deletions t/test-suite.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
;; THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

(in-package :cl-user)
(defpackage :cl-migratum.test
(uiop:define-package :cl-migratum.test
(:use :cl :rove)
(:nicknames :migratum.test)
(:import-from :tmpdir)
Expand Down Expand Up @@ -101,35 +101,35 @@
default)))

(setup
(setf *tmpdir* (tmpdir:mkdtemp))
(setf *sqlite-conn*
(cl-dbi:connect :sqlite3
:database-name (merge-pathnames
(make-pathname :name "cl-migratum" :type "db")
*tmpdir*)))
(setf *provider* (cl-migratum.provider.local-path:make-provider (list *migrations-path*)))
(setf *dbi-driver*
(migratum.driver.dbi:make-driver *provider* *sqlite-conn*))
(let ((rdbms-auth
(list :host (getenv "PGHOST" "localhost")
:port (getenv-int "PGPORT" 5432)
:database (getenv "RDBMS_DB" "rdbms")
:user-name (getenv "RDBMS_USER" "rdbms_user")
:password (getenv "RDMBS_PASS" "rdbms_p4ss")))
(postmodern-auth
(list :host (getenv "PGHOST" "localhost")
:port (getenv-int "PGPORT" 5432)
:database (getenv "POSTMODERN_DB" "postmodern")
:user-name (getenv "POSTMODERN_USER" "postmodern_user")
:password (getenv "POSTMODERN_PASS" "postmodern_p4ss"))))
(setf *postmodern-postgresql-driver*
(migratum.driver.postmodern-postgresql:make-driver *provider* postmodern-auth)
*rdbms-postgresql-driver*
(migratum.driver.rdbms-postgresql:make-driver *provider* rdbms-auth))))
(setf *tmpdir* (tmpdir:mkdtemp))
(setf *sqlite-conn*
(cl-dbi:connect :sqlite3
:database-name (merge-pathnames
(make-pathname :name "cl-migratum" :type "db")
*tmpdir*)))
(setf *provider* (cl-migratum.provider.local-path:make-provider (list *migrations-path*)))
(setf *dbi-driver*
(migratum.driver.dbi:make-driver *provider* *sqlite-conn*))
(let ((rdbms-auth
(list :host (getenv "PGHOST" "localhost")
:port (getenv-int "PGPORT" 5432)
:database (getenv "RDBMS_DB" "rdbms")
:user-name (getenv "RDBMS_USER" "rdbms_user")
:password (getenv "RDMBS_PASS" "rdbms_p4ss")))
(postmodern-auth
(list :host (getenv "PGHOST" "localhost")
:port (getenv-int "PGPORT" 5432)
:database (getenv "POSTMODERN_DB" "postmodern")
:user-name (getenv "POSTMODERN_USER" "postmodern_user")
:password (getenv "POSTMODERN_PASS" "postmodern_p4ss"))))
(setf *postmodern-postgresql-driver*
(migratum.driver.postmodern-postgresql:make-driver *provider* postmodern-auth)
*rdbms-postgresql-driver*
(migratum.driver.rdbms-postgresql:make-driver *provider* rdbms-auth))))

(teardown
(provider-shutdown *provider*)
(driver-shutdown *dbi-driver*)
(driver-shutdown *postmodern-postgresql-driver*)
(when *tmpdir*
(uiop:delete-directory-tree *tmpdir* :validate t)))
(provider-shutdown *provider*)
(driver-shutdown *dbi-driver*)
(driver-shutdown *postmodern-postgresql-driver*)
(when *tmpdir*
(uiop:delete-directory-tree *tmpdir* :validate t)))

0 comments on commit 938278e

Please sign in to comment.