-
Notifications
You must be signed in to change notification settings - Fork 695
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
feat: EXPOSED-552 Include DROP statements for unmapped columns for migration #2249
Conversation
e2bf0c3
to
b518b76
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just left some comments to consider.
statements.add( | ||
"ALTER TABLE ${tr.identity(table)} DROP COLUMN ${tr.db.identifierManager.quoteIdentifierWhenWrongCaseOrNecessary(it.name)}" | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From what I'm seeing, this is what using Column.dropStatement().single()
directly returns, no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes
...d-tests/src/test/kotlin/org/jetbrains/exposed/sql/tests/shared/ddl/DatabaseMigrationTests.kt
Outdated
Show resolved
Hide resolved
val existingTablesColumns = logTimeSpent("Extracting table columns", withLogs) { | ||
currentDialect.tableColumns(*tables) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is also always called in addMissingColumnsStatements()
directly before with the same arguments, right? It may be inefficient to do this twice given the potential queries involved. I get that it must be possible in isolation because you've made this method public, so the metadata needs to be retrieved if this is invoked alone.
But maybe you could log an issue for us to later restructure the calls inside statementsRequiredForDatabaseMigration()
? As in maybe we could have a single invokation to retrieve and store existingTablesColumns
there. Then we could either have private overloads for addMissingColumnsStatements
and dropUnmappedColumnsStatements
or just default parameters that allow us to pass in the column data results & avoid duplicate queries.
b518b76
to
a2c2bc2
Compare
Description
MigrationUtils.statementsRequiredForDatabaseMigration
now includes DROP statements for unmapped columns (those that exist in the database but not in the Exposed Kotlin code).Detailed description:
Necessary for migration.
A new function
dropUnmappedColumnsStatements
was added toMigrationUtils
. This function returns the SQL statements that drop any columns that exist in the database but are not defined in the Exposed tables. This function is then invoked instatementsRequiredForDatabaseMigration
.Type of Change
Please mark the relevant options with an "X":
Updates/remove existing public API methods:
Affected databases:
Checklist
Related Issues