-
Notifications
You must be signed in to change notification settings - Fork 156
feat: implement PostgreSQL operation deparser for CREATE TABLE DDL generation #2094
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
Conversation
- Introduced addTableOperationSchema for adding table operations, including path validation and value schema. - Implemented isAddTableOperation type guard for runtime validation of add table operations. - Updated operationsSchema to include the new addTableOperationSchema, enhancing the overall schema capabilities. This change improves the flexibility of the operations schema by allowing the addition of tables with structured validation.
- Added postgresqlOperationDeparser to handle CREATE TABLE statements from add table operations. - Introduced operation deparser tests to ensure correct DDL generation and error handling for unsupported operations. - Updated index exports to include postgresqlOperationDeparser and its associated types. This enhancement improves the capability to generate PostgreSQL DDL from structured operations, ensuring robust validation and error management.
- Move PATH_PATTERNS constants from src/diff/constants.ts to src/operation/constants.ts - Update operationsSchema.ts to use PATH_PATTERNS.TABLE_BASE instead of hardcoded regex - Update all import statements across the codebase to use new constants location - Ensure consistent path pattern validation across the system 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
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.
We originally prepared PATH_PATTERNS to implement UI diffs, but decided to move it to a different location because we wanted to use it elsewhere.
const addTableOperationSchema = v.object({ | ||
op: v.literal('add'), | ||
path: v.custom<`/tables/${string}`>( | ||
isTablePath, | ||
'Path must match the pattern /tables/{tableName}', | ||
), | ||
value: tableSchema, | ||
}) |
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.
In the interim, I have decided to strictly define the schema for adding tables, possibly supporting many patterns such as columns, indexes, etc.We'll adjust the strictness once we understand how hard it will be.
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
PR Code Suggestions ✨Explore these optional code suggestions:
|
COMMENT ON COLUMN users.id IS 'User ID'; | ||
COMMENT ON COLUMN users.email IS 'User email';" | ||
`) | ||
}) |
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.
@NoritakaIkeda
It still only supports CREATE TABLE
, but using it this way allows us to create DDL from operation!
The operation is the value in building_schema_versions.patch
.Please let me know if you have any questions!
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.
That policy seems good!
Issue
Why is this change needed?
This change adds PostgreSQL operation deparser functionality to generate CREATE TABLE DDL statements from addTableOperation. This enables converting table creation operations into executable PostgreSQL DDL, supporting the database schema management workflow.
What would you like reviewers to focus on?
postgresqlOperationDeparser
and its test coveragediff/constants
tooperation/constants
Testing Verification
postgresqlOperationDeparser
with comprehensive test casesWhat was done
🤖 Generated by PR Agent at 2cb2249
• Implement PostgreSQL operation deparser for CREATE TABLE DDL generation
• Add comprehensive operation schema with table operation support
• Refactor constants from diff to operation directory
• Update all import paths across codebase
Detailed Changes
5 files
Export postgresqlOperationDeparser function
Implement PostgreSQL operation deparser logic
Add OperationDeparser type definition
Add addTableOperation schema and type guards
Export new operation deparser functionality
1 files
Add comprehensive tests for operation deparser
1 files
Move PATH_PATTERNS constants from diff directory
12 files
Update import path for PATH_PATTERNS
Update import path for PATH_PATTERNS
Update import path for PATH_PATTERNS
Update import path for PATH_PATTERNS
Update import path for PATH_PATTERNS
Update import path for PATH_PATTERNS
Update import path for PATH_PATTERNS
Update import path for PATH_PATTERNS
Update import path for PATH_PATTERNS
Update import path for PATH_PATTERNS
Update import path for PATH_PATTERNS
Update import path for PATH_PATTERNS
25 files
Additional Notes
This implementation focuses on CREATE TABLE operations. Future enhancements can extend support for other DDL operations like ALTER TABLE, DROP TABLE, etc.