Start learning free

LESSON 156 OF 173 · BACKEND: SHIPPING IT

Project: The Release Checklist in C#

Practice

Before a new version goes live, a release checklist makes sure nothing was forgotten on the server. Your function ReleaseChecklist(env, db, client) gets the server's environment variables as a Dictionary<string, string>, its database as a SqliteConnection, and an HttpClient that talks to its app. It collects what is wrong in a list, problems, and the code at the end prints it.

Each check reads a value, compares it, and adds a sentence when something is wrong. Here is a check for another setting:

var env = new Dictionary<string, string> { ["SHOP_NAME"] = "Mug Shop", ["ADMIN_EMAIL"] = "" };
var problems = new List<string>();
if (env.GetValueOrDefault("ADMIN_EMAIL", "") == "") {
    problems.Add("set ADMIN_EMAIL");
}
Console.WriteLine(string.Join(", ", problems));   // set ADMIN_EMAIL

Your checklist asks four things, in this order. Debug mode is off: DEBUG is "0", or not set at all. Every name in secrets is set and not empty. Every name in migrations has its row in the table migrations: ExecuteScalar() gives null when it doesn't. And GET /health answers 200. The debug check is already written for you.

Six test servers go through the checklist. The finished code prints:

Server 1: all set
Ready to release
Server 2: debug left on
To do: turn debug off (DEBUG is 1)
Server 3: secrets forgotten
To do: set the secret SECRET_KEY
To do: set the secret WEBHOOK_SECRET
Server 4: new code, old database
To do: run the migration 003_add_reviews
Server 5: the app is not healthy
To do: fix /health, it answers 503
Server 6: nothing done yet
To do: turn debug off (DEBUG is true)
To do: set the secret SECRET_KEY
To do: set the secret PAYMENTS_API_KEY
To do: set the secret WEBHOOK_SECRET
To do: run the migration 001_create_products
To do: run the migration 002_create_orders
To do: run the migration 003_add_reviews
To do: fix /health, it answers 503

Your task: inside ReleaseChecklist, below the debug check, add the other three checks: the secrets, then the migrations, then /health. Each one adds the sentence that follows To do: in the output above.


Assignment
Follow the Coding Tutorial to add the checks of the release checklist: secrets set, migrations run and /health green, below the debug check that is already there.


Hint
GetValueOrDefault with a default never throws. Look up each migration with a $name parameter and AddWithValue. (int)response.StatusCode gives the status as a number, and a string plus a number gives a string.


STEP 1 OF 12
    Ctrl + Enter to check

    Ship Release Checklist in C#

    Keep going with C#1,600+ step-by-step lessons, from your first line of code to coding interviews. Free to start.
    Start learning free