diff --git a/exposed-tests/src/test/kotlin/org/jetbrains/exposed/sql/tests/h2/H2Tests.kt b/exposed-tests/src/test/kotlin/org/jetbrains/exposed/sql/tests/h2/H2Tests.kt index 766e7ab017..35e868a4c0 100644 --- a/exposed-tests/src/test/kotlin/org/jetbrains/exposed/sql/tests/h2/H2Tests.kt +++ b/exposed-tests/src/test/kotlin/org/jetbrains/exposed/sql/tests/h2/H2Tests.kt @@ -1,8 +1,11 @@ package org.jetbrains.exposed.sql.tests.h2 +import org.jetbrains.exposed.dao.id.IntIdTable import org.jetbrains.exposed.sql.* import org.jetbrains.exposed.sql.tests.DatabaseTestsBase import org.jetbrains.exposed.sql.tests.TestDB +import org.jetbrains.exposed.sql.tests.currentDialectTest +import org.jetbrains.exposed.sql.tests.inProperCase import org.jetbrains.exposed.sql.tests.shared.assertEquals import org.jetbrains.exposed.sql.transactions.TransactionManager import org.jetbrains.exposed.sql.transactions.transactionManager @@ -93,6 +96,28 @@ class H2Tests : DatabaseTestsBase() { } } + @Test + fun addAutoPrimaryKey() { + val tableName = "Foo" + val initialTable = object : Table(tableName) { + val bar = text("bar") + } + val t = IntIdTable(tableName) + + withDb(listOf(TestDB.H2, TestDB.H2_MYSQL)) { + try { + SchemaUtils.createMissingTablesAndColumns(initialTable) + assertEquals("ALTER TABLE ${tableName.inProperCase()} ADD ${"id".inProperCase()} ${t.id.columnType.sqlType()}", t.id.ddl.first()) + assertEquals("ALTER TABLE ${tableName.inProperCase()} ADD CONSTRAINT pk_$tableName PRIMARY KEY (${"id".inProperCase()})", t.id.ddl[1]) + assertEquals(1, currentDialectTest.tableColumns(t)[t]!!.size) + SchemaUtils.createMissingTablesAndColumns(t) + assertEquals(2, currentDialectTest.tableColumns(t)[t]!!.size) + } finally { + SchemaUtils.drop(t) + } + } + } + class WrappedTransactionManager(val transactionManager: TransactionManager) : TransactionManager by transactionManager diff --git a/exposed-tests/src/test/kotlin/org/jetbrains/exposed/sql/tests/shared/ddl/CreateMissingTablesAndColumnsTests.kt b/exposed-tests/src/test/kotlin/org/jetbrains/exposed/sql/tests/shared/ddl/CreateMissingTablesAndColumnsTests.kt index 3536402b06..de07bb558f 100644 --- a/exposed-tests/src/test/kotlin/org/jetbrains/exposed/sql/tests/shared/ddl/CreateMissingTablesAndColumnsTests.kt +++ b/exposed-tests/src/test/kotlin/org/jetbrains/exposed/sql/tests/shared/ddl/CreateMissingTablesAndColumnsTests.kt @@ -248,27 +248,6 @@ class CreateMissingTablesAndColumnsTests : DatabaseTestsBase() { } val t = IntIdTable(tableName) - withDb(TestDB.H2) { - SchemaUtils.createMissingTablesAndColumns(initialTable) - assertEquals("ALTER TABLE ${tableName.inProperCase()} ADD ${"id".inProperCase()} ${t.id.columnType.sqlType()}", t.id.ddl.first()) - assertEquals("ALTER TABLE ${tableName.inProperCase()} ADD CONSTRAINT pk_$tableName PRIMARY KEY (${"id".inProperCase()})", t.id.ddl[1]) - assertEquals(1, currentDialectTest.tableColumns(t)[t]!!.size) - SchemaUtils.createMissingTablesAndColumns(t) - assertEquals(2, currentDialectTest.tableColumns(t)[t]!!.size) - SchemaUtils.drop(t) - } - - withDb(TestDB.SQLITE) { - try { - SchemaUtils.createMissingTablesAndColumns(t) - assertFalse(db.supportsAlterTableWithAddColumn) - } catch (e: SQLException) { - // SQLite doesn't support - } finally { - SchemaUtils.drop(t) - } - } - withTables(excludeSettings = listOf(TestDB.H2, TestDB.H2_MYSQL, TestDB.SQLITE), tables = arrayOf(initialTable)) { assertEquals("ALTER TABLE ${tableName.inProperCase()} ADD ${"id".inProperCase()} ${t.id.columnType.sqlType()} PRIMARY KEY", t.id.ddl) assertEquals(1, currentDialectTest.tableColumns(t)[t]!!.size)