Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    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.. :)
    Is it possible to use a class that extends Entity outside transactional
    Flavio W. Brasil
    @fwbrasil
    @rinmalavi it is possible only to read outside of transactional
    but it won’t provide any consistency guarantees
    Marin Vila
    @rinmalavi
    Guess that is actually good, but will introduce some code duplication,
    thanks!
    Marin Vila
    @rinmalavi
    do I need any special import in order to use .col method?
    Marin Vila
    @rinmalavi
    I am trying to make https://github.com/fwbrasil/activate/blob/master/activate-docs/query.md#slick-queries work. Get 'col is not member of String' Error.
    I see its in SlickQueryContext trait and i have it imported with ActivateContext, but i can't call it on id property.
    Ryan Proud
    @spry-rproud
    import context.driver.simple_
    Marin Vila
    @rinmalavi
    thanks, that worked :+1:, tho idea is complaining about execute
    now, however, I have RequiredTransactionException
    this is what i am trying to do:
    case class A(a: String, b: String)extends  Entity
    case class B(a: A, c: String) extends  Entity
    
    val a =(for {
      a <- SlickQuery[A]
      b <- SlickQuery[B] if b.a.col === a.col
    } yield (b.col)).execute
    Ryan Proud
    @spry-rproud
    wrap in transactional {}
    Marin Vila
    @rinmalavi
    oh, ofc, thought they dont need those
    Marin Vila
    @rinmalavi
    java.lang.InternalError: Malformed class name :sparkles:
    works nicely tho, except the part the idea doesn't compile
    Marin Vila
    @rinmalavi

    I have one more, hope i am not disturbing too much :-)
    I need to find an average over field for a certain detail
    Basically i want to do this

      case class A(a: String, b: String)extends  Entity
      case class B(a: A, c: String, f: Int) extends  Entity
    
      val a = (for {
        a <- SlickQuery[A].rightJoin(SlickQuery[B]).on(_.col === _.a.col)
      } yield a).groupBy(_._2.a.col).map { case (n, g) => (n, g.map {_._2.f}.avg) }.execute

    Tried several combinations usually get:
    Trying to reassign node type -- nodeTyped() may only be called on freshly constructed nodes

    ....
    (SlickQueryContext.scala:137)
    [error] net.fwbrasil.activate.slick.SlickQueryContext$QueryRun
    KaTeX parse error: Unexpected character: '$' at position 7: anonfun̲$execute$1.app: anonfun$execute$1.apply(SlickQueryContext.scala:137)
    [error] net.fwbrasil.activate.slick.SlickQueryContext$QueryRun
    anonfun$execute$1.apply(SlickQueryContext.scala:136)
    [error] net.fwbrasil.activate.slick.SlickQueryContext$$anon$1.withSession(SlickQueryContext.scala:89)
    [error] net.fwbrasil.activate.slick.SlickQueryContext$QueryRun.execute(SlickQueryContext.scala:135)
    Ryan Proud
    @spry-rproud

    @fwbrasil Is there any way to provide hints to ensure that statements generated in the transaction are executed in a specific order? We're running into an issue, where our entity design looks cyclical, but the actual data itself is not. It appears that this is causing FK constraint errors. ie.

    class Foo(var name: String, var bar1: Bar, var bar2: Bar) extends Entity
    class Bar(var name: String, var foo: Foo) extends Entity
    
    transactional {
        val bar1 = new Bar("bar1", null)
        val bar2 = new Bar("bar2", null)
    
        val foo = new Foo("foo", bar1, bar2)
    }

    This transaction is occasionally (it does appear to be random) failing because the ids for bar1 and bar2 do not exist yet in the database. Any of instance of Bar that is referenced by Foo should always have a null foo reference.