Test a column type change
Hard120 pts~45 min
- Column type change
- Table rebuild
- Data conversion
Practice app · Acme Commerce DB
A real SQL database (SQLite engine) seeded with an e-commerce and HR dataset, with schema browser and query runner.
Your starter code already declares TEST_URL — never hardcode a host.
Objective
Change payments.amount (REAL) into amount_cents (INTEGER) with a table rebuild and verify every value converted exactly.
Your task
- 1Create payments_new (id INTEGER PRIMARY KEY, order_id INTEGER NOT NULL REFERENCES orders(id), amount_cents INTEGER NOT NULL CHECK (amount_cents >= 0), method TEXT NOT NULL CHECK (method IN ('card','paypal','bank')), paid_at TEXT NOT NULL).
- 2Copy the data with CAST(ROUND(amount * 100) AS INTEGER) for amount_cents.
- 3DROP TABLE payments, then ALTER TABLE payments_new RENAME TO payments.
- 4Verify: SELECT typeof(p.amount_cents) AS stored_type, COUNT(*) AS rows, SUM(CASE WHEN p.amount_cents = CAST(ROUND(o.total * 100) AS INTEGER) THEN 0 ELSE 1 END) AS mismatches FROM payments p JOIN orders o ON o.id = p.order_id GROUP BY typeof(p.amount_cents).
Acceptance criteria
- payments now has amount_cents INTEGER in place of amount REAL
- The last result set is one row: ('integer', every payment, 0 mismatches)
- The rebuild renames the new table
Constraints
- Every run starts from a freshly seeded database, so your script must include its own setup statements.
- Dialect: SQLite. ALTER TABLE supports ADD COLUMN, DROP COLUMN and RENAME; other type changes need a table rebuild.
- Only the last result set of your script is compared, so finish with the verification query.
SQL (SQLite engine) · Database Testing · Migrations & schema