Problem
generateSQL currently emits only CREATE TABLE DDL. Running this output against any table that already exists in production will fail with a duplicate table error.
FoodFiles has 14 migrations already applied to its production D1 database. Adding contract-generated DDL to an established schema requires either:
ALTER TABLE ... ADD COLUMN statements for new fields
- A diff mode that computes the delta between the current contract definition and an existing schema snapshot
Without this, generateSQL is unusable for any phase-0 or later consumer whose tables are already live. The only workaround is to manually translate contract changes into migration files, which defeats the purpose of the package.
Acceptance Criteria
Context
FoodFiles is the designated phase-0 consumer. Its 14-migration history is the concrete stress-test for this feature. The pantry and organization contracts are the first candidates for diff-mode adoption once this lands.
Ref: CONTRACT-2 gap analysis (phase-0 integration audit)
Problem
generateSQLcurrently emits onlyCREATE TABLEDDL. Running this output against any table that already exists in production will fail with a duplicate table error.FoodFiles has 14 migrations already applied to its production D1 database. Adding contract-generated DDL to an established schema requires either:
ALTER TABLE ... ADD COLUMNstatements for new fieldsWithout this,
generateSQLis unusable for any phase-0 or later consumer whose tables are already live. The only workaround is to manually translate contract changes into migration files, which defeats the purpose of the package.Acceptance Criteria
generateSQL(contract, { mode: 'diff', baseline: SchemaSnapshot })emits onlyALTER TABLE ADD COLUMNstatements for columns present in the contract but absent from the baselineSchemaSnapshotcan be produced from a D1PRAGMA table_info()result (or equivalent JSON shape)DROP COLUMNstatements without an explicit{ destructive: true }opt-in flagbaseline) behavior remainsCREATE TABLEfor backwards compatibilitygenerateMigration(contract, baseline)convenience export wraps diff mode and returns a migration file string with a timestamped filenameContext
FoodFiles is the designated phase-0 consumer. Its 14-migration history is the concrete stress-test for this feature. The pantry and organization contracts are the first candidates for diff-mode adoption once this lands.
Ref: CONTRACT-2 gap analysis (phase-0 integration audit)