zio-quill icon indicating copy to clipboard operation
zio-quill copied to clipboard

Create DSL for schema and database/keyspace creation

Open kbielefe opened this issue 10 years ago • 5 comments

Would like the ability to create a keyspace and schema directly from Quill.

Keyspace creation possibly to be accomplished by adding some new config properties:

db.createKeyspace=true
db.keyspaceStrategy=simple
db.replicationFactor=3

Schema creation possibly looking something like:

val q = quote {
  query[Table].create.primaryKey(p => (p.field1, p.field2))
                     .partitionKey(_.field3)
                     .clusteringOrder(p => (p.field2, p.field3))(Ord(Ord.asc, Ord.desc))
}

@getquill/maintainers

kbielefe avatar Mar 03 '16 17:03 kbielefe

I think schema creation would be an interesting feature. Could you give more details on why a DSL as opposed to raw CQL strings? A DSL doesn't seem to provide much benefit as DDL statements aren't composable.

fwbrasil avatar Mar 09 '16 06:03 fwbrasil

I guess the main point is automatically mapping case classes into DB fields. This way we keep model and DB to be strictly consistent during whole dev/testing phase. +1

zhijun avatar Aug 18 '17 20:08 zhijun

This is a essential feature.can we get some info from quill ast? BTW,is this related? https://github.com/getquill/quill/pull/226

doofin avatar Sep 14 '20 11:09 doofin

I'm upvoting this because it's the only thing preventing me from using Quill (both hibernate and slick has this feature).

If this feature is implemented, could we maybe also add annotation support so we can do something like the following?

case class SomeEntity(
  @Id
  @GeneratedValue(strategy = GenerationType.IDENTITY)
  identifier: Int,

  @Length(32)
  shortString: String,

  // ...
)

Daniel-Khodabakhsh avatar Sep 23 '21 16:09 Daniel-Khodabakhsh

I'm also upvoting this feature.

My use case is to create tables in test with H2, but the production code is using Postgres. Unlike the full-feature table creation support, we have some tolerance on the difference between test database and production DB scheme.

With this feature, we could simply create table before each test case:

// instead of this
  override def beforeEach(): Unit = {
    super.beforeEach()
    ctx.run(quote(
      infix"""CREATE TABLE the_schema.file_info (
                id         UUID NOT NULL,
                file_name       TEXT,
                file_extension  TEXT,
                size_bytes      BIGINT NOT NULL
              )
           """.as[Action[Nothing]]
    ))
  }

// we could run something like
  override def beforeEach(): Unit = {
    super.beforeEach()
    ctx.run(quote(fileInfoTable.createTableAction))
  }

shuo avatar Jun 10 '22 06:06 shuo

I'd advise people to use something like flyway or liquibase for such needs

guizmaii avatar Sep 29 '23 07:09 guizmaii