Closed cshclm closed 5 years ago
I've got the same problem. Any suggestions on how to resolve this?
I worked around it by rebinding the problem function.
(let [pattern (re-pattern (str "([^\\/]*)\\/?$"))]
(defn- -resource-basename
[file]
(second (re-find pattern (str file)))))
(intern 'ragtime.jdbc 'basename #'-resource-basename)
Patches for this issue are welcome.
The rebinding by @cshclm works fine, but only when present in the first version of a program; It still fails when you have an existing database on Windows that you need to migrate because the absolute paths are already stored as migration IDs.
I solved it by rebinding one more function, migrate-all
, to strip away the paths from the existing/stored migration IDs. Here's my complete patch:
(let [pattern (re-pattern (str "([^\\/]*)\\/?$"))]
(defn- -resource-basename
[file]
(second (re-find pattern (str file)))))
(intern 'ragtime.jdbc 'basename #'-resource-basename)
(defn- -migrate-without-file-names
([store index migrations]
(-migrate-without-file-names store index migrations ragtime.strategy/raise-error))
([store index migrations strategy]
(let [index (ragtime.core/into-index index migrations)
stored-applied (ragtime.protocols/applied-migration-ids store)
applied (map -resource-basename stored-applied)] ; strip the JAR file name on Windows
(doseq [[action migration-id] (strategy applied (map ragtime.protocols/id migrations))]
(case action
:migrate (ragtime.core/migrate store (index migration-id))
:rollback (ragtime.core/rollback store (index migration-id)))))))
(intern 'ragtime.core 'migrate-all #'-migrate-without-file-names)
I just hit this issue too. Rather than patch the library's code (at runtime) for Windows, would it be possible to simply re-implement the Migration protocol's (id) method for Windows?
As I said before, I'm happy to accept a PR that solves this issue. I don't use Clojure under Windows, so this isn't something I can easily test myself.
My pleasure. Ring has been very very good to me, BTW. Your work is much appreciated.
I think this pull request will do it.
For migration files provided by Java resources under MS Windows, the absolute pathname to the migration file is stored as the migration ID.
The path basename is used as the migration ID for .sql files, where the basename is determined using a regexp using OS-specific separators.
However Java resources always use forward-slash ("/") as the path separator, making the basename regexp invalid for resources under Windows.
The result is an ID of the form
jar:file:/path/to/file.jar!/migrations/001-mymigration
, instead of001-mymigration
as expected. This introduces two problems: