Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't find schema file /schema/ #143

Open
Citrullin opened this issue Jul 3, 2017 · 2 comments
Open

Can't find schema file /schema/ #143

Citrullin opened this issue Jul 3, 2017 · 2 comments
Labels

Comments

@Citrullin
Copy link

Citrullin commented Jul 3, 2017

I get the following error:

[error] /home/citrullin/git/scala-troy/src/main/scala/model/PageImpressionByYearMonth.scala:19: Can't find schema file /schema/
[error]   val getByYearMonth = withSchema {

Let's take a look into the code.

package model

import com.datastax.driver.core.{Cluster, Session}
import connection.ConnectionProvider
import entity.PageImpression
import troy.dsl._
import troy.driver.DSL._

import scala.concurrent.Future

class PageImpressionByYearMonth(connection: ConnectionProvider) {
  import scala.concurrent.ExecutionContext.Implicits.global
  val cluster = connection.cluster
  implicit val session: Session = connection.session

  val keyspace = "analytics"
  val tableName = "pageimpressionbyyearmonth"

  val getByYearMonth = withSchema {
    (year: Int, month: Int) =>
    cql"""
          SELECT * FROM analytics.pageimpressionbyyearmonth WHERE year = $year AND month = $month
      """.prepared.executeAsync.as(PageImpression)
  }

  def get(year: Int, month: Int): Future[Seq[PageImpression]] = getByYearMonth(year, month)
}

The schema file is in probject/src/main/resources/schema.cql and project/src/test/resources/schema.cql. I also checked probject/src/main/resources/schmea/schema.cql and probject/src/test/resources/schema.cql. I think there is something wrong with the relative path. Instead of a relative path it seems like it uses a absolute path.

@tabdulradi
Copy link
Member

Troy has two modes to load the schema:

  • the single-file mode, it looks for single file resources/schema.cql
  • the versioned mode, it looks for multiple files resources/schema/01.cql, resources/schema/02.cql, etc ..

It should attempt first to try the versioned mode, if it can't find the folder, it attempts to load the single-file mode.
I am not sure what exactly went wrong in your case, but it seems to get stuck at the versioned mode, I'll mark it as a bug to check later.
For now, I'd suggest to rename your schema file to be "resources/schema/01.cql", this will probably fix the issue. If not, please update me in a reply.

@tabdulradi tabdulradi added the bug label Aug 29, 2017
@tabdulradi
Copy link
Member

Ok, I've figured it out. It is a documentation issue.
You need this line in your build.sbt to allow the macro to read the resources folder at compile time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants