Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simple Table with schema fails when using SchemaUtils.createMissingTablesAndColumns #1661

Closed
BlackHornet opened this issue Dec 29, 2022 · 4 comments · Fixed by #1678
Closed
Assignees

Comments

@BlackHornet
Copy link

Whenever I try to use a schema it fails with a schema table, when I am going to initialize with SchemaUtils.createMissingTablesAndColumns

object Tests: LongIdTable("auth.test")

SchemaUtils.createSchema(Schema("auth"))

SchemaUtils.createMissingTablesAndColumns(
    listOf(Tests),
    inBatch = true,
    withLogs = true
)

DEBUG Exposed - CREATE TABLE IF NOT EXISTS auth.test (id BIGSERIAL PRIMARY KEY)
DEBUG Exposed - ALTER TABLE auth.test ADD id BIGSERIAL PRIMARY KEY
WARN Exposed - Transaction attempt #0 failed: java.sql.BatchUpdateException: Batch entry 0 ALTER TABLE auth.test ADD id BIGSERIAL PRIMARY KEY was aborted: ERROR: column "id" of relation "test" already exists Call getNextException to see other errors in the batch.. Statement(s): ALTER TABLE auth.test ADD id BIGSERIAL PRIMARY KEY

With that I am not able to use any database schema

@AlexeySoshin
Copy link
Contributor

Hi @BlackHornet,
Could you please specify which Exposed version and what database are you using?

@AlexeySoshin
Copy link
Contributor

AlexeySoshin commented Jan 31, 2023

I think I managed to reproduce that with 0.41.1

    @Test
    fun `createMissingTablesAndColumns should work on schema prefixed tables`() {
        val schemaName = "my_schema"
        val testTable = object : LongIdTable("$schemaName.test_table") {
        }

        withTables(excludeSettings = listOf(TestDB.H2_MYSQL)) {
            SchemaUtils.createSchema(Schema(schemaName))
            SchemaUtils.create(testTable)
            SchemaUtils.createMissingTablesAndColumns(testTable)
            assertTrue(testTable.exists())
            SchemaUtils.drop(testTable)
        }
    }

Getting

org.jetbrains.exposed.exceptions.ExposedSQLException: org.postgresql.util.PSQLException: ERROR: column "id" of relation "test_table" already exists

Will see if I'm able to fix that.

@albert361
Copy link

Any estimated time that fix could be released :D ?

@bog-walk bog-walk self-assigned this Apr 28, 2023
@BlackHornet
Copy link
Author

@AlexeySoshin
Oh sorry, it was 0.40.1 with a remote postgres (cockroachDB) database

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants