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

Fix postgresql alter table alter column #4868

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ internal abstract class AlterTableAlterColumnMixin(
AlterTableApplier {

override fun getColumnConstraintList(): MutableList<SqlColumnConstraint> {
return alterStmt.tablesAvailable(this).first()
.query.columns.firstOrNull { it.element.textMatches(columnName) }?.element?.let {
return alterStmt.tablesAvailable(this).first { it.tableName.textMatches(alterStmt.tableName) }
.query.columns.first { it.element.textMatches(columnName) }.element.let {
(it.parent as SqlColumnDef).columnConstraintList
} ?: mutableListOf()
}
}

override fun getColumnName(): SqlColumnName {
Expand All @@ -37,7 +37,8 @@ internal abstract class AlterTableAlterColumnMixin(
if (sqlColumnType != null) return sqlColumnType

val columnName = columnName
val element = tablesAvailable(this).first().query.columns.first { it.element.textMatches(columnName) }.element
val element = tablesAvailable(this).first { it.tableName.textMatches(alterStmt.tableName) }
.query.columns.first { it.element.textMatches(columnName) }.element
return (element.parent as ColumnDefMixin).columnType
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
CREATE TABLE test (
CREATE TABLE test_1 (
first INTEGER
);

CREATE TABLE test_2 (
first TEXT NOT NULL,
second INTEGER,
third TEXT NOT NULL,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
ALTER TABLE test ALTER COLUMN first DROP NOT NULL;
ALTER TABLE test ALTER COLUMN second SET NOT NULL;
ALTER TABLE test ALTER COLUMN fifth DROP NOT NULL;
ALTER TABLE test_1 ALTER COLUMN first SET NOT NULL;
ALTER TABLE test_2 ALTER COLUMN first DROP NOT NULL;
ALTER TABLE test_2 ALTER COLUMN second SET NOT NULL;
ALTER TABLE test_2 ALTER COLUMN fifth DROP NOT NULL;
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
ALTER TABLE test ALTER COLUMN fifth TYPE BIGINT;
ALTER TABLE test_1 ALTER COLUMN first TYPE BIGINT;
ALTER TABLE test_2 ALTER COLUMN fifth TYPE BIGINT;
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
insertFirst:
INSERT INTO test (first, second, third, fourth, fifth) VALUES (?, ?, ?, ?, ?);
INSERT INTO test_1 (first) VALUES (?);

insertSecond:
INSERT INTO test_2 (first, second, third, fourth, fifth) VALUES (?, ?, ?, ?, ?);
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,34 @@ import kotlin.String
public class DataQueries(
driver: SqlDriver,
) : TransacterImpl(driver) {
public fun insertFirst(
public fun insertFirst(first: Long) {
driver.execute(-2_134_278_654, """INSERT INTO test_1 (first) VALUES (?)""", 1) {
check(this is JdbcPreparedStatement)
bindLong(0, first)
}
notifyQueries(-2_134_278_654) { emit ->
emit("test_1")
}
}

public fun insertSecond(
first: String?,
second: Int,
third: String,
fourth: Int?,
fifth: Long?,
) {
driver.execute(-2_134_278_654,
"""INSERT INTO test (first, second, third, fourth, fifth) VALUES (?, ?, ?, ?, ?)""", 5) {
driver.execute(-1_370_094_750,
"""INSERT INTO test_2 (first, second, third, fourth, fifth) VALUES (?, ?, ?, ?, ?)""", 5) {
check(this is JdbcPreparedStatement)
bindString(0, first)
bindInt(1, second)
bindString(2, third)
bindInt(3, fourth)
bindLong(4, fifth)
}
notifyQueries(-2_134_278_654) { emit ->
emit("test")
notifyQueries(-1_370_094_750) { emit ->
emit("test_2")
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.example

import kotlin.Long

public data class Test_1(
public val first: Long,
)
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import kotlin.Int
import kotlin.Long
import kotlin.String

public data class Test(
public data class Test_2(
public val first: String?,
public val second: Int,
public val third: String,
Expand Down