fix: add missing customer_email and total_amount columns to orders table - #11
Open
asarkar157 wants to merge 1 commit into
Open
fix: add missing customer_email and total_amount columns to orders table#11asarkar157 wants to merge 1 commit into
asarkar157 wants to merge 1 commit into
Conversation
…ble\n\nThe initdb schema was missing the customer_email and total_amount columns\nthat the application handler code writes to and reads from. This caused\nHTTP 500 errors on every POST /api/orders request with the error:\n\n SQL logic error: table orders has no column named customer_email (1)\n\nChanges:\n- Add customer_email TEXT NOT NULL and total_amount REAL NOT NULL to the\n CREATE TABLE IF NOT EXISTS orders DDL (fixes fresh databases)\n- Add ALTER TABLE migration statements for existing databases that were\n initialized without these columns (fixes running deployments)\n- Add isDuplicateColumnErr helper to gracefully ignore duplicate-column\n errors when ALTER TABLE runs on already-migrated databases
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
The
orderstable schema incmd/initdb/main.gowas missing thecustomer_emailandtotal_amountcolumns that the application handler code expects, causing HTTP 500 errors on everyPOST /api/ordersrequest.Error:
Root Cause
Schema divergence between DB initialization and application code:
internal/handlers/orders.gowritesINSERT INTO orders (customer_email, total_amount, status)cmd/initdb/main.goCREATE TABLEonly definedamountandstatuscolumnsThe column
customer_email(andtotal_amount) were added to the handler layer but theinitdbschema was never updated.Fix
CREATE TABLE IF NOT EXISTS ordersDDL to includecustomer_email TEXT NOT NULLandtotal_amount REAL NOT NULL— fixes all fresh database initializations.ALTER TABLEmigration statements for existing databases already initialized without these columns — fixes running deployments without requiring a full DB wipe.isDuplicateColumnErrhelper to gracefully skipALTER TABLEwhen columns already exist (idempotent migrations).Files Changed
cmd/initdb/main.go— schema DDL + migration statementsVerification
After applying this fix and running
make init-db(or restarting with the updated initdb):POST /api/ordersshould return HTTP 201 instead of 500[aiden-demo] order-service HTTP errorsshould recover from Alert → OK within 1–2 minutes[aiden-demo] order-service schema mismatch logsmonitor should remain OKCreated using StackGen