juxt / joplin

Flexible datastore migration and seeding for Clojure projects
Eclipse Public License 1.0
316 stars 48 forks source link

Keyspace does not exist? #111

Closed Freid001 closed 5 years ago

Freid001 commented 5 years ago

I am trying to create some cassandra migrations. But when I run the migrations I get a Keyspace 'test' does not exist exception.

Does joplin require the keyspace to already exist? Is it not possible to create the keyspace from the migration it's self?

migration

(ns migrators.20181107120605-project
  (:require [qbits.alia :as alia]))

(defn up [conn]
  (alia/execute conn "CREATE KEYSPACE IF NOT EXISTS test WITH REPLICATION = {'class' : 'SimpleStrategy', 'replication_factor' : 1};")
  (alia/execute conn "USE test;")
  (alia/execute conn "CREATE TABLE IF NOT EXISTS person (uuid uuid, name varchar, PRIMARY KEY (uuid));"))

(defn down [conn]
  (alia/execute conn "USE test;")
  (alia/execute conn "DROP TABLE IF EXISTS person;")
  (alia/execute conn "DROP KEYSPACE IF EXISTS test;"))

config.edn

{:migrators    {:cass-mig "resources/migrators"}
 :seeds        {:cass-seed "seeds.cass/run"}
 :databases    {:cass-dev {:type :cass, :hosts ["::1"], :keyspace "test"}}
 :environments {:dev [{:db :cass-dev, :migrator :cass-mig, :seed :cass-seed}]}}

project.clj

(defproject app "0.1.0-SNAPSHOT"

            :dependencies [
                           [org.clojure/clojure "1.8.0"]
                           [joplin.core "0.3.11"]
                           [joplin.cassandra "0.3.11"]
                           ]

            :resource-paths ["resources"]

            :profiles {:default [:user]
                       :user {:plugins [
                                        [lein-sub "0.3.0"]
                                        ]
                              }}

            :aliases {"migrate"  ["run" "-m" "joplin.alias/migrate" "config.edn"]
                      "seed"     ["run" "-m" "joplin.alias/seed" "config.edn"]
                      "rollback" ["run" "-m" "joplin.alias/rollback" "config.edn"]
                      "reset"    ["run" "-m" "joplin.alias/reset" "config.edn"]
                      "pending"  ["run" "-m" "joplin.alias/pending" "config.edn"]
                      "create"   ["run" "-m" "joplin.alias/create" "config.edn"]}
            )

Exception:

Exception in thread "main" com.datastax.driver.core.exceptions.InvalidQueryException: Keyspace 'test' does not exist, compiling: (/private/var/folders/w_/yt926bqs21g44f257yz05ctsjbv948/T/form-init5453081474670989587.clj:1:125)
at clojure.lang.Compiler.load(Compiler.java:7391)
at clojure.lang.Compiler.loadFile(Compiler.java:7317)
at clojure.main$load_script.invokeStatic(main.clj:275)
at clojure.main$init_opt.invokeStatic(main.clj:277)
at clojure.main$init_opt.invoke(main.clj:277)
at clojure.main$initialize.invokeStatic(main.clj:308)
at clojure.main$null_opt.invokeStatic(main.clj:342)
at clojure.main$null_opt.invoke(main.clj:339)
at clojure.main$main.invokeStatic(main.clj:421)
at clojure.main$main.doInvoke(main.clj:384)
at clojure.lang.RestFn.invoke(RestFn.java:421)
at clojure.lang.Var.invoke(Var.java:383)
at clojure.lang.AFn.applyToHelper(AFn.java:156)
at clojure.lang.Var.applyTo(Var.java:700)
at clojure.main.main(main.java:37)
Caused by: com.datastax.driver.core.exceptions.InvalidQueryException: Keyspace 'test' does not exist
at com.datastax.driver.core.exceptions.InvalidQueryException.copy(InvalidQueryException.java:50)
at com.datastax.driver.core.DriverThrowables.propagateCause(DriverThrowables.java:37)
at com.datastax.driver.core.Cluster.connect(Cluster.java:286)
at qbits.alia$connect.invokeStatic(alia.clj:183)
at qbits.alia$connect.invoke(alia.clj:178)
at joplin.cassandra.database$get_connection.invokeStatic(database.clj:26)
at joplin.cassandra.database$get_connection.invoke(database.clj:25)
at joplin.cassandra.database$eval3099$fn__3100.doInvoke(database.clj:55)
at clojure.lang.RestFn.invoke(RestFn.java:410)
at clojure.lang.MultiFn.invoke(MultiFn.java:229)
at clojure.lang.AFn.applyToHelper(AFn.java:154)
at clojure.lang.AFn.applyTo(AFn.java:144)
at clojure.core$apply.invokeStatic(core.clj:648)
at clojure.core$apply.invoke(core.clj:641)
at joplin.repl$run_op.invokeStatic(repl.clj:43)
at joplin.repl$run_op.invoke(repl.clj:43)
at joplin.repl$migrate.invokeStatic(repl.clj:55)
at joplin.repl$migrate.doInvoke(repl.clj:52)
at clojure.lang.RestFn.invoke(RestFn.java:425)
at joplin.alias$migrate.invokeStatic(alias.clj:21)
at joplin.alias$migrate.doInvoke(alias.clj:17)
at clojure.lang.RestFn.invoke(RestFn.java:425)
at clojure.lang.Var.invoke(Var.java:383)
at user$eval5.invokeStatic(form-init5453081474670989587.clj:1)
at user$eval5.invoke(form-init5453081474670989587.clj:1)
at clojure.lang.Compiler.eval(Compiler.java:6927)
at clojure.lang.Compiler.eval(Compiler.java:6917)
at clojure.lang.Compiler.load(Compiler.java:7379)
... 14 more
Caused by: com.datastax.driver.core.exceptions.InvalidQueryException: Keyspace 'test' does not exist
at com.datastax.driver.core.Responses$Error.asException(Responses.java:136)
at com.datastax.driver.core.DefaultResultSetFuture.onSet(DefaultResultSetFuture.java:179)
at com.datastax.driver.core.RequestHandler.setFinalResult(RequestHandler.java:174)
at com.datastax.driver.core.RequestHandler.access$2600(RequestHandler.java:43)
at com.datastax.driver.core.RequestHandler$SpeculativeExecution.setFinalResult(RequestHandler.java:793)
at com.datastax.driver.core.RequestHandler$SpeculativeExecution.onSet(RequestHandler.java:627)
at com.datastax.driver.core.Connection$Dispatcher.channelRead0(Connection.java:1012)
at com.datastax.driver.core.Connection$Dispatcher.channelRead0(Connection.java:935)
at com.datastax.shaded.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:105)
at com.datastax.shaded.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:342)
at com.datastax.shaded.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:328)
at com.datastax.shaded.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:321)
at com.datastax.shaded.netty.handler.timeout.IdleStateHandler.channelRead(IdleStateHandler.java:266)
at com.datastax.shaded.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:342)
at com.datastax.shaded.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:328)
at com.datastax.shaded.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:321)
at com.datastax.shaded.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:102)
at com.datastax.shaded.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:342)
at com.datastax.shaded.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:328)
at com.datastax.shaded.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:321)
at com.datastax.shaded.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:293)
at com.datastax.shaded.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:267)
at com.datastax.shaded.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:342)
at com.datastax.shaded.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:328)
at com.datastax.shaded.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:321)
at com.datastax.shaded.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1280)
at com.datastax.shaded.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:342)
at com.datastax.shaded.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:328)
at com.datastax.shaded.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:890)
at com.datastax.shaded.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:131)
at com.datastax.shaded.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:564)
at com.datastax.shaded.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:505)
at com.datastax.shaded.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:419)
at com.datastax.shaded.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:391)
at com.datastax.shaded.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:112)
at java.lang.Thread.run(Thread.java:748)