Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    James Phillips
    @jdrphillips
    We currently have ZonedDateTime scala types, mapped to java.sql.Timestamp. Slick takes it from there. Our database type is timestamp with time zone
    With the update, this mapping is ignored, and everything is broken
    Production environment is postgres, test environment is H2. H2 works out of the box with the upgrade (but I suspect this is a misdirection and it's broken in an insidious way)

    I've tried many variations on this:

      // Customise the types...
      class JdbcTypes extends super.JdbcTypes {
    
        override val zonedDateType = new ZonedDateTimeJdbcType {
    
          override def sqlType = java.sql.Types.TIMESTAMP_WITH_TIMEZONE
          override def setValue(v: ZonedDateTime, p: PreparedStatement, idx: Int) = {
            p.setObject(idx, v.toInstant(), sqlType)
          }
          override def getValue(r: ResultSet, idx: Int): ZonedDateTime = {
            ZonedDateTime.ofInstant(r.getObject(idx, classOf[java.sql.Timestamp]).toInstant, Utc)
          }
          override def updateValue(v: ZonedDateTime, r: ResultSet, idx: Int) = {
            r.updateObject(idx, v.toInstant())
          }
          override def valueToSQLLiteral(value: ZonedDateTime) = "{ts '"+value.format(sqlDateTimeFormatter)+"'}"
        }
      }

    but I get errors no matter what I do. I can't get the combination of TIMESTAMP_WITH_TIMEZONE, Timestamp, Instant and ZonedDateTime right

    Any help greatly appreciated
    (there might be inconsistencies in the above code due to me just trying anything to get it work - first task is to read data, then focus on writing later)
    Richard Dallaway
    @d6y
    @jdrphillips let me check the following: you have imported your own custom profile (one for H2 and one for PG), you're using those in place of the standard H2 and PG profile imports, and the custom profiles have the above JdbcTypes in them in them? And on your table you have used ZonedDateTime as a column type? I'd also add some logging (temporarily) to these methods so you can get some clarity on when they are in scope, and worry about them having the right behavior after that.
    James Phillips
    @jdrphillips
    They're definitely in scope correctly as I get different errors when I change the above implementations
    Sometimes null error, sometimes "type 93" errors
    But you're correct. It is a column[ZonedDateTime] with a SQL type of timestamp with time zone in postgres. H2 doesn't matter so much as long as it works as we have no persisted data in h2
    (but I think the new "out of the box" behaviour won't work as the default type is varchar, so our comparisons will be broken due to inconsistently timezoned strings being inserted)
    Michaล‚ Pawlicki
    @MichalPawlicki
    @jdrphillips Have you tried https://github.com/tminglei/slick-pg ? It supports the ZonedDateTime -> timestamptz mapping, so you won't have to define your own one.
    Roberto Leibman
    @rleibman
    So.... I'm trying to get my stack of projects into scala 3.... the migration tools are complaining because slick uses macros. Is there any ETA for a scala 3 version?
    nafg
    @nafg
    @rleibman no, follow slick/slick#2187
    Or get involved with it
    Meanwhile you can of course have some modules on 2.13 and some on 3 in your application
    James Phillips
    @jdrphillips
    @MichalPawlicki I'll give it a look - thanks
    nafg
    @nafg
    If anyone wants to video chat about Slick, or possibly watch me do some slick-related coding, I'm on https://meet.google.com/umj-wvqv-xxs now
    Matt Oliver
    @halfmatthalfcat
    Hey everybody, question about migrations. So what is the best practice around changing column types which map to case class types and rolling those back?
    I'm basically looking for a way to fallback to the previous type in some ergonomic way without having to either (1) duplicate a lot of code or (2) somehow leverage the current model implicitly through the app depending on what "version" of the model is currently applied
    Matt Oliver
    @halfmatthalfcat

    For example I have a Table and associated mapped class

    case class MyModel(
      myPk: Int,
      someText: String
    )
    
    class MyTable(tag: Tag) extends Table[MyModel](tag, "my_table") {
      def myPk: Rep[Int] = column("my_pk")
      def someText: Rep[String] = column("some_text")
    
      def * = (myPk, someText) <> ((MyModel.apply _).tupled, MyModel.unapply)
    
      def pk = primaryKey("my_pk_pk", myPk)
    }

    I have a migration that changes the myPk column from an integer to a varchar, so I now need to somehow represent that change within my table and case class with the option to roll back. The actual DB rollback is handled (rolled my own migration framework based off of Forklift) but it's handling the code rollback that is alluding me.

    I could duplicate MyTable with myPk as an integer and then also duplicate MyModel using myPk as an int still but then I'm having to potentially weave these two competing tables and models through the code depending on whether we've migrated or rolled back...

    I almost need someway to version MyModel with myPk as a String as well as MyTable with myPk as a String/varchar
    Matt Oliver
    @halfmatthalfcat
    Something like https://github.com/alexarchambault/data-class 's @since might work if anybody has experience implementing that with Slick
    nafg
    @nafg
    Anyone want to watch me do some maintenance of Slick?
    Rohan Sircar
    @rohan-sircar
    @nafg I'd watch, but do you post on youtube? I'm asleep at that time.
    nafg
    @nafg
    @rohan-sircar I'm not looking to entertain, ;) I'm looking to be more motivated and one thing that helps is if I have someone to discuss what I'm doing with. So I'm thinking more of a small zoom or google meet call than broadcast on twitch / upload for posterity
    If you're interested let me know what time(s) are good for you
    Antoine Doeraene
    @sherpal
    I'd be interested yes. What is your time zone? ๐Ÿ™‚
    Rohan Sircar
    @rohan-sircar
    @nafg oh ok. I'm interested too..
    Dheeraj Karande ๐Ÿ‡ฎ๐Ÿ‡ณ
    @dheerajkarande_twitter
    @nafg me too! :)
    nafg
    @nafg
    @sherpal @rohan-sircar @dheerajkarande_twitter when is the next time you would be interested?
    1 reply
    nafg
    @nafg
    I'm in EST but not on a typical workday schedule
    Andy Czerwonka
    @andyczerwonka

    I have a use case where I have an optional column, and I want to write a filter that checks for a value when it's present or check for null it it's null.
    I initially wrote:

    table.filter(_.name === name)

    In this case, when None, the query generates name = null, which is not correct, I was expecting name is null, so I had to change my filter to:

    table
      .filterOpt(name) { case (t, n) => t.name === n }
      .filterIf(name.isEmpty)(_.name.isEmpty)

    That produces the right query, but it seems like I should get that behaviour for free when using an optional column. Those two filter are mutually exclusive.
    Is there a primitive I should be using instead?

    Antoine Doeraene
    @sherpal
    I think what you want is
    table.filter(elem => elem.name.isEmpty || elem.name === name)
    Andy Czerwonka
    @andyczerwonka
    No, that's not the same, because there is no check if name is empty
    Antoine Doeraene
    @sherpal

    Ah sorry I did not understand properly. Would it be

    table.filter(name match {
      case None => _.name.isEmpty
      case Some(actualName) => _.name === actualName
    })

    ? I'm unsure whether Scala will correctly infer the type of that filtering function, so you might have to help it a bit.

    nafg
    @nafg
    @sherpal @rohan-sircar @dheerajkarande_twitter I can start in a few minutes
    Rohan Sircar
    @rohan-sircar
    @nafg cool, I am up
    Although not for very long, it's late here
    nafg
    @nafg
    Ok, google meet good?
    Rohan Sircar
    @rohan-sircar
    sure
    @rohan-sircar you joining?
    @sherpal ?
    1 reply
    Andy Czerwonka
    @andyczerwonka
    @sherpal yeah, that was my first attempt, but the typechecker get's in the way, but I'm sure I could coerce it
    Dheeraj Karande ๐Ÿ‡ฎ๐Ÿ‡ณ
    @dheerajkarande_twitter
    @nafg i totally missed your msg. Uhh!
    I would really like to join in, can we schedule it in advance next time. Please.
    nafg
    @nafg
    Sorry I don't know my schedule in advance, but hopefully Sunday
    nafg
    @nafg
    @sherpal @rohan-sircar @dheerajkarande_twitter anyone interested soon?
    1 reply
    Rohan Sircar
    @rohan-sircar
    Kinda tired, I probably wouldn't be able to do much other than just watch quietly. I could join if I'm not gonna be the only one.
    Could you maybe also post in the main gitter channel/ typelevel discord channel?