Permalink
Browse files

Fix AutoInc for H2.

IDENTITY in H2 implies PRIMARY KEY, which is not only not what is
wanted when just AutoInc is specified, but also breaks when used in
conjunction with PrimaryKey.  Use AUTO_INCREMENT instead.

Fixes issue #763.
  • Loading branch information...
1 parent 3a50a33 commit 50528fffc0f64abb1a10455430ae9374a750167d @dangerousben dangerousben committed Jun 17, 2015
@@ -51,7 +51,7 @@ class Tables(val profile: JdbcProfile){
/** Tests table with self-referring foreign key */
class SelfRef(tag: Tag) extends Table[(Int,Option[Int])](tag, "SELF_REF") {
- def id = column[Int]("id",O.AutoInc)
+ def id = column[Int]("id",O.PrimaryKey,O.AutoInc)
def parent = column[Option[Int]]("parent")
def parentFK = foreignKey("parent_fk", parent, SelfRef)(_.id.?)
def * = (id,parent)
@@ -76,6 +76,7 @@ trait H2Profile extends JdbcProfile {
override protected def computeQueryCompiler = super.computeQueryCompiler.replace(Phase.resolveZipJoinsRownumStyle) - Phase.fixRowNumberOrdering
override def createQueryBuilder(n: Node, state: CompilerState): QueryBuilder = new QueryBuilder(n, state)
override def createUpsertBuilder(node: Insert): InsertBuilder = new UpsertBuilder(node)
+ override def createColumnDDLBuilder(column: FieldSymbol, table: Table[_]): ColumnDDLBuilder = new ColumnDDLBuilder(column)
override def createInsertActionExtensionMethods[T](compiled: CompiledInsert): InsertActionExtensionMethods[T] =
new CountingInsertActionComposerImpl[T](compiled)
@@ -107,6 +108,15 @@ trait H2Profile extends JdbcProfile {
}
}
+ class ColumnDDLBuilder(column: FieldSymbol) extends super.ColumnDDLBuilder(column) {
+ override protected def appendOptions(sb: StringBuilder) {
+ if(defaultLiteral ne null) sb append " DEFAULT " append defaultLiteral
+ if(notNull) sb append " NOT NULL"
+ if(primaryKey) sb append " PRIMARY KEY"
+ if(autoIncrement) sb append " AUTO_INCREMENT"
+ }
+ }
+
class JdbcTypes extends super.JdbcTypes {
override val uuidJdbcType = new UUIDJdbcType {
override def sqlTypeName(sym: Option[FieldSymbol]) = "UUID"

0 comments on commit 50528ff

Please sign in to comment.