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

feat: EXPOSED-552 Include DROP statements for unmapped columns for migration #2249

Merged
merged 1 commit into from
Sep 24, 2024

Conversation

joc-a
Copy link
Collaborator

@joc-a joc-a commented Sep 23, 2024

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:

  • Why:
    Necessary for migration.
  • How:
    A new function dropUnmappedColumnsStatements was added to MigrationUtils. 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 in statementsRequiredForDatabaseMigration.

Type of Change

Please mark the relevant options with an "X":

  • Bug fix
  • New feature
  • Documentation update

Updates/remove existing public API methods:

  • Is breaking change

Affected databases:

  • MariaDB
  • Mysql5
  • Mysql8
  • Oracle
  • Postgres
  • SqlServer
  • H2
  • SQLite

Checklist

  • Unit tests are in place
  • The build is green (including the Detekt check)
  • All public methods affected by my PR has up to date API docs
  • Documentation for my change is up to date

Related Issues

@joc-a joc-a marked this pull request as ready for review September 23, 2024 15:14
@joc-a joc-a requested a review from bog-walk September 23, 2024 15:19
Copy link
Member

@bog-walk bog-walk left a 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.

Comment on lines +126 to +128
statements.add(
"ALTER TABLE ${tr.identity(table)} DROP COLUMN ${tr.db.identifierManager.quoteIdentifierWhenWrongCaseOrNecessary(it.name)}"
)
Copy link
Member

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?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes

Comment on lines +111 to +113
val existingTablesColumns = logTimeSpent("Extracting table columns", withLogs) {
currentDialect.tableColumns(*tables)
}
Copy link
Member

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.

@joc-a joc-a merged commit 0e6acbd into main Sep 24, 2024
5 checks passed
@joc-a joc-a deleted the joc/exposed-552 branch September 24, 2024 13:27
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 this pull request may close these issues.

2 participants