Test a rollback migration
Hard120 pts~45 min
- Down migrations
- Schema history
- DROP COLUMN
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
Run a migration up and back down, and verify the schema returns to its original shape while the migration history records the rollback.
Your task
- 1CREATE TABLE schema_migrations (version TEXT PRIMARY KEY, applied_at TEXT NOT NULL, rolled_back_at TEXT).
- 2Up: add customers.phone TEXT, create customer_notes (id INTEGER PRIMARY KEY, customer_id INTEGER NOT NULL REFERENCES customers(id), note TEXT NOT NULL), and insert version '2025_12_add_phone_and_notes' applied_at '2025-12-30'.
- 3Down: drop customer_notes, drop customers.phone, and set rolled_back_at = '2025-12-31' for that version.
- 4Verify: SELECT COUNT(*) AS leftover FROM (SELECT name FROM pragma_table_info('customers') WHERE name = 'phone' UNION ALL SELECT name FROM sqlite_master WHERE name = 'customer_notes') returns 0.
Acceptance criteria
- The schema matches the original plus schema_migrations, with the version marked rolled back
- The last result set shows 0 leftover objects
- The down migration uses DROP
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