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

A table column with .autoIncrement() and NO .primaryKey() does create primary key with SchemaUtils.createMissingTablesAndColumns() #649

Closed
sobvan opened this issue Oct 3, 2019 · 2 comments
Labels

Comments

@sobvan
Copy link

sobvan commented Oct 3, 2019

Given the following code:

object NoPrimaryKey: Table() {
    val autoIncrementValue: Column<Long> = long("auto_increment_value").autoIncrement()
    val someOtherValue: Column<String> = varchar("some_other_value", 20)
}

object StringPrimaryKey: Table() {
    val autoIncrementValue: Column<Long> = long("auto_increment_value").autoIncrement()
    val someOtherValue: Column<String> = varchar("some_other_value", 20).primaryKey()
}

fun main() {
    val db = Database.connect(
            "jdbc:postgresql://localhost:5432/postgres",
            "org.postgresql.Driver",
            "postgres",
            "lUosBQd2Sq")
    transaction(db) {
        SchemaUtils.createMissingTablesAndColumns(NoPrimaryKey, StringPrimaryKey)
    }
}

produces the following CREATE TABLE sql statements:

CREATE TABLE IF NOT EXISTS noprimarykey (auto_increment_value BIGSERIAL NOT NULL, some_other_value VARCHAR(20) NOT NULL, CONSTRAINT pk_NoPrimaryKey PRIMARY KEY (auto_increment_value))
CREATE TABLE IF NOT EXISTS stringprimarykey (auto_increment_value BIGSERIAL NOT NULL, some_other_value VARCHAR(20) PRIMARY KEY)

I do not get why the table noprimarykey will be created with the PRIMARY KEY constraint.

Is there an explanation, or is this a bug?

@Tapac Tapac added the bug label Oct 30, 2019
Tapac added a commit that referenced this issue Nov 1, 2019
… primary key with SchemaUtils.createMissingTablesAndColumns() #649
@Tapac Tapac closed this as completed Nov 1, 2019
Tapac added a commit that referenced this issue Nov 1, 2019
… primary key with SchemaUtils.createMissingTablesAndColumns() #649
@sobvan
Copy link
Author

sobvan commented Nov 1, 2019

Thanks a lot for fixing this.

@Tapac
Copy link
Contributor

Tapac commented Nov 1, 2019

@istvanszoboszlai , hope to release it soon (on the next week)

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

No branches or pull requests

2 participants