-
Notifications
You must be signed in to change notification settings - Fork 873
DB Manager alter table #7486
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
DB Manager alter table #7486
Conversation
Deploying windmill with
|
| Latest commit: |
dd0b4e3
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://5c6f908b.windmill.pages.dev |
| Branch Preview URL: | https://di-db-manager-update-table.windmill.pages.dev |
|
/ai review this pr |
|
Claude finished @diegoimbert's task in 1m 34s —— View job PR Review: DB Manager Alter Table
SummaryThis PR adds ALTER TABLE functionality to the DB Manager, enabling users to modify existing database tables (add/drop/alter columns, manage foreign keys, manage primary keys, and rename tables). The implementation supports multiple database types (PostgreSQL, MySQL, MS SQL Server, Snowflake, BigQuery, DuckDB). Overall Assessment✅ Well-structured implementation with good separation of concerns Code Review Findings🟢 Positives
🟡 Suggestions for Improvement1. MS SQL Server Default Constraint Naming (
|
|
Claude finished @diegoimbert's task in 2m 25s —— View job PR Review: DB Manager Alter Table
SummaryThis PR adds ALTER TABLE functionality to the DB Manager, enabling users to modify existing database tables including:
The implementation supports multiple database types: PostgreSQL, MySQL, MS SQL Server, Snowflake, BigQuery, and DuckDB. Overall Assessment✅ Well-structured implementation with good separation of concerns between SQL generation, diffing logic, and UI Code Quality HighlightsPositives
Issues FoundSee inline comments for specific code locations. Summary: 🟡 Medium Priority
🟢 Minor/Suggestions
Architecture NotesThe PR follows good patterns from the existing codebase:
Security Considerations
Testing InstructionsTo test the ALTER TABLE functionality: Navigate to the DB Manager page (accessible from the sidebar in workspaces with database resources configured). Select a database resource (PostgreSQL or Data Tables work best for testing). In the table list on the left sidebar, click the three-dot menu on any existing table and select "Alter table". A drawer will open showing the current table structure with the table name field (editable to rename), columns table with type/primary key/settings, and foreign keys section. Try renaming columns (note the "Old name" hint), changing types, toggling nullable/primary key, adding/deleting columns, and managing foreign keys. Click "Alter table" to see the SQL preview in a confirmation modal. Note the warning on non-transactional databases. Verify the button shows "No changes detected" when unmodified and "Alter table (X changes detected)" when changed. |
frontend/src/lib/components/apps/components/display/dbtable/queries/alterTable.ts
Outdated
Show resolved
Hide resolved
| queries.push( | ||
| renderDropDefaultValue(tableRef, original.name, datatype, dbType, op.defaultConstraintName) | ||
| ) | ||
| } else if (changes.defaultValue) { |
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.
Potential issue with setting default values: The condition changes.defaultValue uses truthiness check which means an empty string '' would be falsy and not trigger setting the default. If a user explicitly wants to set an empty string as the default value, this won't work as expected.
Consider being more explicit:
} else if (changes.defaultValue !== undefined) {| foreignKeys = transformForeignKeys(rawForeignKeys) | ||
| } | ||
| } | ||
| } catch (e) { |
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.
Silent error handling: The catch block silently catches errors and only logs a warning. While this prevents crashes, users won't know why their FK data is missing. Consider surfacing these errors more visibly in the UI, perhaps by returning an error field that can be displayed to users.
|
|
||
| let sql = '' | ||
|
|
||
| sql += `CONSTRAINT fk_${[ |
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.
Long FK constraint names: The generated constraint name could exceed PostgreSQL's 63-character limit for identifiers. Consider adding a truncation safeguard:
| sql += `CONSTRAINT fk_${[ | |
| sql += `CONSTRAINT ${`fk_${[ | |
| options.tableName, | |
| ...sourceColumns.map((c) => c?.substring(0, 10)), | |
| targetTable, | |
| ...targetColumns.map((c) => c?.substring(0, 10)) | |
| ] | |
| .join('_') | |
| .replaceAll('.', '_')}`.substring(0, 63)} ` |
Note: The .substring(0, 60) on line 54 already limits length, but applying it to the whole constraint name rather than at the concatenation level would be cleaner.
Screen.Recording.2026-01-06.at.20.37.35.mov
Works well on Postgres (and consequently Data tables) and Ducklake. It is totally usable in all other databases too (except Oracle), but not as exhaustively tested.
The E2E tests PR will allow to guarantee best quality on all databases (there are a lot of edge cases across databases that are difficult to keep track of manually)
Transactional DDL is only supported on Postgres, MS SQL and DuckDB / Ducklake. I display a warning on other databases that any failure might leave the db in an intermediate state.
Columns are "stateful" as in renaming a column a to b is not the same as deleting a then creating b.
TODO : Better UI feedback for some restrictions (e.g: BigQuery can only drop NOT NULL, never add it. Or : it can never add a NOT NULL column to an existing table for data consistency reasons)
TODO : column reordering