Chirp's users table holds every account: you, Ada, and thousands more.
You made it by typing CREATE TABLE into Supabase's SQL Editor.
And Chirp itself runs at localhost:3000, on your computer only.
Now each profile needs a bio: a line about its person, like X has.
So how does a new column get into a table full of rows, and stay in your repository?
In this project you add it as a migration, with Supabase's command line tool.
Then you put Chirp on the internet, where anyone with its link can open it.
Supabase has a command line tool for changing your database from your terminal. In your chirp folder, install it.
npm install supabase --save-dev
Log it in to your Supabase account. It opens your browser: follow it, then come back.
npx supabase login
Then give your repository a supabase folder, where your migrations will live.
npx supabase init
Then link the folder to your project.
npx supabase link
Pick simplified-practice from the list.
It asks for your database password: the one you saved when you made the project.
Why does it need that password?
Because it opens a connection to your Postgres, and logs in, as any app server does.
You should see
Finished supabase link. in your terminal, and a new supabase folder in chirp.
Make an empty migration file, named for its one change.
npx supabase migration new add_bio
It lands in supabase/migrations, with the date and time in front of its name, like this.
supabase/migrations/20261117093000_add_bio.sql
A later file always gets a bigger number, so the files run in order, just as 001, 002 and 003 do.
Open the file. It's empty, and the change is yours to write.
Here is the new column:
| Column | Type | Rules |
|---|---|---|
| bio | varchar(160) | None: no DEFAULT |
160 characters is as long as a bio on X.
Your turn 1
Write the query that adds a bio column to the users table you already have, keeping its rows. Save it in the migration file.
The file holds one ALTER TABLE, ending in a semicolon.
ALTER TABLE users ADD COLUMN bio varchar(160);
You should see
Your migration file in supabase/migrations, holding your ALTER TABLE.
Send your migration to your project's database.
npx supabase db push --remote
--remote sends it to the project you linked.
It lists your add_bio migration, and asks before it runs. Type y.
Then open the Table Editor, and pick users.
What does bio hold for Ada, and for you?
NULL: every row was saved before bio existed, and bio has no DEFAULT.
Now run the same command again.
npx supabase db push --remote
Supabase keeps a list of the migrations each database has run, inside that database.
add_bio is on it, so it doesn't run twice.
You should see
A bio column in users, NULL in every row. The second run says your linked project is up to date, and runs nothing.
A profile page, like localhost:3000/you, shows a bio under the name, from getUser(handle).
getUser still returns sample data.
And Settings has a Bio box, whose Save button calls updateBio(userId, bio), which saves nothing yet.
Your turn 1
Make getUser(handle) send back that person's id, handle, name and bio.
localhost:3000/you and localhost:3000/ada load as before, with no bio and no sample data tag.
// SELECT id, handle, name, bio FROM users WHERE handle = 'you';
export async function getUser(handle: string) {
const { data, error } = await supabase
.from("users")
.select("id, handle, name, bio")
.eq("handle", handle)
.single();
if (error) throw new Error(error.message);
return data;
}
Your turn 2
Make updateBio(userId, bio) save that bio in that user's row, and no one else's.
Save Learning databases, one checkpoint at a time. in Settings, and it shows under your name at localhost:3000/you. Ada's profile still has none.
// UPDATE users SET bio = 'Learning databases, one checkpoint at a time.' WHERE id = 7;
export async function updateBio(userId: number, bio: string) {
const { error } = await supabase
.from("users")
.update({ bio })
.eq("id", userId);
if (error) throw new Error(error.message);
}
Commit your code and the supabase folder, with your migration in it.
git add -A
git commit -m "Add a bio to profiles, as a migration"
git push
A teammate now reads your schema change in GitHub, like any code.
You should see
Your commit on GitHub, with supabase/migrations and your add_bio file in it, and no .env.local.
Vercel runs Next.js apps on its servers, for free on its Hobby plan.
Sign up at vercel.com with your GitHub account, on the Hobby plan.
Start a new project, and import your chirp repository from GitHub.
Before you deploy, open Environment Variables, and add two.
SUPABASE_URL
SUPABASE_SECRET_KEY
Give each the same value as in your .env.local. Make the secret key a Secret.
Why type them in again?
Because .env.local never went to GitHub, so Vercel can't read it.
Vercel keeps them, and hands them to your server code only.
Then press Deploy, and wait for the build to finish.
Chirp has no login, so anyone with its link acts as you. Share it only with people you trust.
You should see
Your Chirp at its own address, ending in .vercel.app, with the same feed as localhost:3000.
On your live Chirp, open Settings, and save a new bio: Now live on the internet.
Then open localhost:3000/you on your computer.
Why does it show the bio you just saved on the internet?
Because both servers send their queries to the same Postgres database, your simplified-practice.
npx supabase link doesn't list simplified-practice
You logged in to a different Supabase account. Run npx supabase login again, with the account that has the project.
I lost my database password
Reset it in your project's database settings, then run npx supabase link again with the new one.
db push says the bio column already exists
You added bio in the SQL Editor before, so the migration can't add it again. Run ALTER TABLE users DROP COLUMN bio; there, which removes the column and what it holds, then push again.
An error that says column users.bio does not exist
Your migration hasn't run on this database. Run npx supabase db push --remote, then reload.
An error that says value too long for type character varying(160)
Your bio is over 160 characters, so Postgres refuses it. Make it shorter.
The live site shows an error, but localhost:3000 works
A variable is missing or misspelt on Vercel. Fix it in the project's settings, then deploy again, because a change only reaches a new deployment.
Supabase says your project is paused
Free projects pause after a week with no activity. Press Restore project on its page, and wait a few minutes: your live Chirp needs it too.
Tick every step once you've seen what it says you should see. Then mark the project complete to unlock the next lesson.