Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    Flavio W. Brasil
    @fwbrasil
    let me check
    how do you create your persistence context?
    I think you can override lazy val driver = MyPostgresDriver
    Ryan Proud
    @spry-rproud
    object myContext extends ActivateContext with SlickQueryContext {
        val storage = new PooledJdbcRelationalStorage {
                val jdbcDriver = "org.postgresql.Driver"
                val user = Some("postgres")
                val password = None
                val url = "jdbc:postgresql://127.0.0.1/json-test"
                val dialect = postgresqlDialect
            }
    }
    Flavio W. Brasil
    @fwbrasil
    object myContext extends ActivateContext with SlickQueryContext {
        override lazy val driver = MyPostgresDriver
        val storage = new PooledJdbcRelationalStorage {
                val jdbcDriver = "org.postgresql.Driver"
                val user = Some("postgres")
                val password = None
                val url = "jdbc:postgresql://127.0.0.1/json-test"
                val dialect = postgresqlDialect
            }
    }
    Ryan Proud
    @spry-rproud
    Ok, that may work. I'll keep looking into it. Thanks.
    Flavio W. Brasil
    @fwbrasil
    np :)
    Ryan Proud
    @spry-rproud
    Is it possible to override the default DateStorageValue for postgresql? (ie. "timestamptz")
    Flavio W. Brasil
    @fwbrasil
    you can override the toSqlDdl method
    new postgresqlDialect(string => "\"" + string + "\””, string => string) {
       override def toSqlDdl(storageValue: StorageValue): String =
            storageValue match {
                case value: DateStorageValue =>
                      “timestamptz”
                case other => super.toSqlDdl(other)
           }
    }
    @spry-rproud ^
    Ryan Proud
    @spry-rproud
    Thanks. That seems to work great.
    Flavio W. Brasil
    @fwbrasil
    :clap:
    Ryan Proud
    @spry-rproud
    Is it possible to have a context ignore certain migrations? I'm having some issues where H2 is having issues with a customScript migration which isn't entirely necessary for tests.
    Flavio W. Brasil
    @fwbrasil
    maybe check the context storage type in the custom script?
    if(context.storage.dialect != h2)
    Ryan Proud
    @spry-rproud
    Does TransientMemoryStorage not maintain StorageVersion?
    Flavio W. Brasil
    @fwbrasil
    it should maintain, I think
    let me check
    yeah, it should maintain the StorageVersion and run the migations
    but it looses the data when restarting, since it is transient
    Ryan Proud
    @spry-rproud
    We're having an issue with the cleanDatabaseStrategy for testing. It doesn't appear to be cleaning all our tables. I'm only seeing a delete against a single table when monitoring the postgres log. Any ideas on what could cause this?
    @fwbrasil
    Ryan Proud
    @spry-rproud
    @fwbrasil It looks like it's because most of our entities extend EntityWithGeneratedId.
    Ryan Proud
    @spry-rproud
    I've created a custom strategy for now to get around it. Is this a bug or am I missing something?
    Flavio W. Brasil
    @fwbrasil
    it looks to be a bug
    what is the workaround?
    Ryan Proud
    @spry-rproud
    I just created another test strategy which also deletes all EntityWithGeneratedId[AnyVal].
    object customCleanDatabaseStrategy extends ActivateTestStrategy {
    
      def runTest[R](f: => R)(implicit ctx: ActivateContext) = {
        prepareDatabase
        ctx.transactional(f)
      }
    
      def runTestAsync[R](f: => R)(implicit ctx: ActivateContext): R = {
        prepareDatabase
        await(ctx.asyncTransactional(f))
      }
      def runTestAsyncChain[R](f: TransactionalExecutionContext => Future[R])(implicit ctx: ActivateContext): R = {
        prepareDatabase
        await(ctx.asyncTransactionalChain(f(_)))
      }
    
      private def prepareDatabase(implicit ctx: ActivateContext) = {
        cleanDatabase
        ctx.reinitializeContext
      }
    
      private def cleanDatabase(implicit ctx: ActivateContext) = {
        import ctx._
        storage match {
          case storage: TransientMemoryStorage =>
            storage.directAccess.clear()
          case other =>
            transactional {
              delete {
                (e: Entity) => where()
              }
              delete {
                (e: EntityWithGeneratedID[AnyVal]) => where()
              }
    //          delete {
    //            (e: EntityWithCustomID[AnyVal]) => where()
    //          }
            }
        }
      }
    }
    Flavio W. Brasil
    @fwbrasil
    does this query return the entityes with custom id as well?
              query {
                (e: Entity) => where()
              }
    Ryan Proud
    @spry-rproud
    I don't have any currently. I can try and run some tests, but I was getting an error with the commented portion. I think because the context wasn't managing any EntityWithCustomID classes.
    Also when I tried (e: BaseEntity) => where() I was getting some odd behaviour. It was only picking up a few of our entities.
    Flavio W. Brasil
    @fwbrasil
    yeah, that’s the problem
    Ryan Proud
    @spry-rproud
    @fwbrasil I'm also seeing the issue again where I'm seeing FK constraint errors because entities aren't getting persisted to the database in time. Is there any guarantee that distinct transactions should be persisted in order?
    Ryan Proud
    @spry-rproud
    @fwbrasil It seems like deleteCascade may also be broken.
    Flavio W. Brasil
    @fwbrasil
    yeah, same bug
    about the tests x transactions, the transactions should be persisted in the same order that they happen
    Ryan Proud
    @spry-rproud
    Yeah, I think that was an issue with my code. Or just a misunderstanding on the test strategies.
    Flavio W. Brasil
    @fwbrasil
    could you open a github issue?
    with both problems (same root cause)
    Ryan Proud
    @spry-rproud
    Sure. Any ideas on what might be a work around because I've realized mine doesn't work because of constraint issues which I was trying to get around with deleteCascade?
    Flavio W. Brasil
    @fwbrasil
    humm, i’m not sure there is a workaround
    Ryan Proud
    @spry-rproud
    For entity lifecycle is there any context that information can be stashed in (ie. user information), so beforeInsert/Update can be used for auditing purposes?
    Ryan Proud
    @spry-rproud
    @fwbrasil Also is it possible to disable lifecycle methods while migrations are running?
    Flavio W. Brasil
    @fwbrasil
    @spry-rproud are you using async persistence? If not, you could use a ThreadLocal
    to hold the user information
    Ryan Proud
    @spry-rproud
    Ok, thanks
    Flavio W. Brasil
    @fwbrasil
    @spry-rproud about the lifecycle methods, there isn’t a built-in way to disable it
    Ryan Proud
    @spry-rproud
    Ok thanks. I just had a migration inserting data and it was causing a bit of havoc on startup. I just re-ordered it to get around the issue.
    Flavio W. Brasil
    @fwbrasil
    cool
    Marin Vila
    @rinmalavi
    Hi, I have a simple question.. :)