-
Notifications
You must be signed in to change notification settings - Fork 695
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: EXPOSED-498 Handle auto-increment status change on a column (#2216
) The function `MigrationUtils.statementsRequiredForDatabaseMigration` now includes the proper statements to change the type of a column when it detects that the auto-increment status has changed for PostgreSQL and SQL Server, and statements to create/drop the necessary sequences. - **Why**: **PostgreSQL**: The generated ALTER COLUMN statement was setting SERIAL as the target column type and that was throwing an error because it is not recognised as a type. **SQL Server**: The generated ALTER COLUMN statement was setting IDENTITY as the target column type and that was throwing an error because it is not possible to add it to an existing column later on and must be defined that way from the start. - **How**: Two functions, `checkMissingSequences` and `checkUnmappedSequences` were added to `MigrationUtils`. For `checkUnmappedSequences`, H2_V1 is excluded because its system sequences do not have predictable naming patterns and it’s impossible to know if an existing sequence in the database is mapped in the Exposed code, so we would get false DROP statements that should not be there. **PostgreSQL**: The SQL equivalent to setting a column type as SERIAL was used. Check PostgreSQL documentation [here](https://www.postgresql.org/docs/current/datatype-numeric.html#DATATYPE-SERIAL). This means that when changing a column to be auto-incrementing in PostgreSQL, Exposed will generate three SQL statements: 1. One to create a sequence 2. One to set the column's default values to be assigned from a sequence generator 3. One to set the column as the owner of the sequence created in Step 1 **SQL Server**: The simplest way to solve it is to create a new IDENTITY column and drop the old one. This means that when changing a column to be auto-incrementing in SQL Server, Exposed will generate three SQL statements: 1. One to add a new IDENTITY column named "NEW_columnName" 2. One to drop the old column 3. One to rename the new column to the same name as the old dropped column
- Loading branch information
Showing
9 changed files
with
609 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.