fix(migrations): use INTEGER for sessions.user_id to match users.id FK type#311
Merged
fix(migrations): use INTEGER for sessions.user_id to match users.id FK type#311
Conversation
…K type The MySQL/MariaDB sessions migration declared user_id as INT, but users.id is created as INTEGER (which can map to BIGINT on MariaDB), causing FK errno 150 on deployments where users.id was promoted to BIGINT. Align with the pattern used elsewhere (labels, tasks): use INTEGER for the FK column, name the constraint, and create indexes as separate statements (matching the working app_tokens migration). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
Contributor
There was a problem hiding this comment.
Pull request overview
Updates migration 007 (sessions table) to improve MySQL/MariaDB compatibility by aligning column declarations and DDL structure with the patterns used elsewhere in the migration set.
Changes:
- Refactors the MySQL
sessionsmigration to executeCREATE TABLEplus index creation as separate statements. - Adjusts MySQL column types for
sessions.id/sessions.user_idand names theusersFK constraint (fk_users_sessions).
Show a summary per file
| File | Description |
|---|---|
| apiserver/internal/migrations/007_sessions.go | Refactors MySQL sessions table creation, adds explicit FK constraint name, and creates indexes via separate statements. |
Copilot's findings
- Files reviewed: 1/1 changed files
- Comments generated: 1
INTEGER and INT are synonyms in MySQL/MariaDB, so they don't resolve a mismatch with users.id when it's actually BIGINT (e.g. on deployments where users was originally created by GORM AutoMigrate). Query information_schema.COLUMNS to derive the exact column type of users.id and reuse it for sessions.id and sessions.user_id, ensuring the FK is accepted on both fresh installs and legacy schemas. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Migration 7 (sessions) fails on MySQL/MariaDB with:
```nError 1005 (HY000): Can't create table
tasks.`sessions` (errno: 150 "Foreign key constraint is incorrectly formed")