fix: cargo dump failure due to schema changes [CM-1282] - #4247
Merged
Conversation
…aging_ddl Signed-off-by: Mouad BANI <mouad-mb@outlook.com>
|
|
Contributor
There was a problem hiding this comment.
Pull request overview
Refactors the Cargo dump CSV ingest in packages_worker to make staging table creation resilient to upstream schema changes by deriving the staging DDL from each CSV’s header and validating required columns before loading.
Changes:
- Replace the static staging DDL with per-CSV dynamic
DROP/CREATE TABLEbuilt from the CSV header. - Add required-column validation to fail fast when crates.io’s dump schema changes.
- Add a lightweight CSV header reader used during the load loop.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Signed-off-by: Mouad BANI <mouad-mb@outlook.com>
Comment on lines
+46
to
+48
| for await (const line of rl) { | ||
| return line.split(',').map((c) => c.trim()) | ||
| } |
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.
This pull request refactors how staging tables are created and validated when loading cargo dump CSVs. Instead of relying on a static DDL string, the code now dynamically constructs the SQL table definitions based on the CSV headers and enforces that required columns are present. This makes the process more robust to schema changes in the input data.
Key changes:
Dynamic Table Creation and Validation
STAGING_DDLwith logic that reads CSV headers and dynamically builds theCREATE TABLEstatements for each staging table. This ensures the table schema matches the actual CSV columns and types, and adapts automatically to changes in the dump format.Supporting Utilities
readCsvHeaderutility to efficiently read the header row from a CSV file.COLUMN_TYPESandREQUIRED_COLUMNSdefinitions to specify expected types and required fields for each table, used in dynamic DDL generation and validation.Integration with Load Process
loadDumpfunction to call the new dynamic table creation logic (buildStagingTable) for each CSV, instead of executing a static DDL block.These changes make the CSV import process more maintainable and resilient to upstream schema changes.
Note
Medium Risk
Changes the packages worker cargo ingest path; failures are clearer but header parsing is naive (comma-split) and downstream SQL still assumes specific column names exist in staging.
Overview
Fixes cargo dump loads breaking when crates.io adds or reorders CSV columns by replacing the fixed
STAGING_DDLwith per-file staging tables built from each file’s header row.loadDumpnow only ensures thecargo_syncschema exists, then for each dump CSV callsbuildStagingTable(read header → validateREQUIRED_COLUMNS→DROP/CREATEwithCOLUMN_TYPESwhere defined, elsetext) beforeCOPY. Missing required columns fail fast with a message that points at a crates.io schema change.New columns in upstream dumps are accepted as extra
textfields without code changes, while core ingest columns stay explicitly required.Reviewed by Cursor Bugbot for commit cb185ec. Bugbot is set up for automated code reviews on this repo. Configure here.