Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
Manage schema migrations at scale
00:00
5 left

Manage schema migrations at scale

MediumSQL · PostgreSQL

Problem

How do you manage database schema migrations in a high-scale, production environment?

Using the provided migration metadata, write a query that reports the current production migration health for every service, including services without a production migration.

Output

  1. One row per service with service_name, migration_version, latest_status, failed_step_count, total_step_count, and duration_seconds
  2. Include services without a production run, using NULL migration details and zero step counts
  3. Return the latest production run per service, ordered by service_name ascending

Schema

services
ColumnTypeDescription
service_idPKINTUnique service identifier
service_nameVARCHAR(100)Name of the service
migration_runs
ColumnTypeDescription
run_idPKINTUnique migration run identifier
service_idINTService executing the migration
environmentVARCHAR(20)Deployment environment
migration_versionVARCHAR(50)Migration version identifier
statusVARCHAR(20)Overall migration status
started_atTIMESTAMPMigration start timestamp
completed_atTIMESTAMPMigration completion timestamp
migration_steps
ColumnTypeDescription
step_idPKINTUnique migration step identifier
run_idINTMigration run containing the step
step_nameVARCHAR(100)Migration step name
statusVARCHAR(20)Step execution status
Tablesservicesmigration_runsmigration_steps
Interviewer

Your question is Manage schema migrations at scale. Start with the requirements and the three tables in the Question tab.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.
CodePostgreSQL
You need to log in / sign up to run or submit.Ln 1
Run your query to see results here.