-
Notifications
You must be signed in to change notification settings - Fork 112
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
Flav/int to bigint migration #9065
base: main
Are you sure you want to change the base?
Conversation
// prevents silent precision loss when handling large integers from the database. | ||
// Throws an assertion error if a BIGINT value exceeds JavaScript's safe integer | ||
// limits. | ||
types.setTypeParser(builtins.INT8, function (val) { |
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.
Will extract to a dedicated PR.
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.
Shipped here.
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.
LGTM. Very nice \o/
I presume final clean-up is still missing.
Let's start with connectors 👍
return progress; | ||
} | ||
|
||
private async checkTableProgress( |
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.
Does this fly on a very big table?
} | ||
} | ||
|
||
private async dropTriggers( |
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.
nit: Should be moved below the main functions
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.
Looks very solid 🔥
trigger: `${tableName}_pk_sync_${direction}` as const, | ||
function: `${tableName}_pk_sync_${direction}_trigger` as const, |
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.
Shouldn't this be?
trigger: `${tableName}_pk_sync_${direction}` as const, | |
function: `${tableName}_pk_sync_${direction}_trigger` as const, | |
trigger: `${tableName}_pk_sync_${direction}_trigger` as const, | |
function: `${tableName}_pk_sync_${direction}` as const, |
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.
It's to surface that the function is only used by a trigger.
currentColumn: MAIN_ID_COLUMN, | ||
newColumn: createColumnName.new(MAIN_ID_COLUMN), | ||
legacyColumn: createColumnName.legacy(MAIN_ID_COLUMN), | ||
sequenceName: `${this.config.tableName}_id_seq`, |
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.
sequenceName: `${this.config.tableName}_id_seq`, | |
sequenceName: createSequenceName(this.config.tableName), |
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.
Good catch!
currentColumn: MAIN_ID_COLUMN, | ||
newColumn: createColumnName.new(MAIN_ID_COLUMN), | ||
legacyColumn: createColumnName.legacy(MAIN_ID_COLUMN), | ||
sequenceName: `${this.config.tableName}_id_seq`, |
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.
sequenceName: `${this.config.tableName}_id_seq`, | |
sequenceName: createSequenceName(this.config.tableName), |
…ions for update and delete - Added fields to track delete and update actions on foreign key constraints in migration script - The migration script now includes additional SQL JOIN to fetch action information from the pg_constraint table
…igration - Change foreign key `ON UPDATE` and `ON DELETE` actions to dynamic based on reference settings - Set actions to `SET NULL` when reference actions are marked with "r", otherwise keep as `RESTRICT`
…aints - Fixed an issue where the update and delete actions for foreign key constraints were incorrectly set to RESTRICT when they should be SET NULL - Updated the conditional logic to match 'n' values to SET NULL action instead of 'r' in the migration script
Integer to BigInt Migration Tool
See migration details here.
This PR introduces a PostgreSQL migration tool designed to safely convert
integer
primary/foreign keys toBigInt
while maintaining zero-downtime capability and full rollback support.Key Features
Key Implementation Details
Constraint Handling
Standardized Constraint Behavior
ON UPDATE RESTRICT ON DELETE RESTRICT
Primary Key Dependencies
rollback
stepRollback Considerations
Constraint Behavior Changes
CASCADE
effect.Data Integrity During Rollback
BigInt
columnsMigration Steps
1. Setup
BigInt
columns (_new
suffix)id
->id_new
)2. Backfill
integer
toBigInt
columns3. Pre-cutover
4. Cutover
BigInt
column5. Rollback (if needed)
Usage Example