2. Persist notes in PostgreSQL
Replace hello with the notes checkpoint, attach PostgreSQL, and create the schema once. The Redis and S3 code is present but is not used until you request an export.
1. Replace the source checkpoint
Download the complete notes ZIP beside your hello directory.
From inside rust-hello, run:
cd ..
unzip rust-notes.zip
cp -R rust-notes/. rust-hello/
cd rust-hello
rm src/main.rs
cargo build --locked
This retains the hello directory’s .git history and shared remote. The rm command
removes only the superseded hello source file in this tutorial directory. The source appendix
shows the database implementation. Notes use UUID IDs, validated text,
and parameterized SQL or the MongoDB driver; no file on the app instance stores notes.
For an optional local run, follow Local services and run
cargo run --locked --bin migrate before cargo run --locked --bin web.
2. Create and attach PostgreSQL
Dashboard: in rust add a Database named notes-db, engine PostgreSQL, with
1 GB storage. Wait until running. Open notes-web → Config → Attached Resources,
select notes-db, leave the variable name blank (DATABASE_URL), and click Attach.
In the same Config tab add plain variable DATABASE_ENGINE=postgresql.
CLI:
paas dbs create notes-db --type postgresql --storage-gb 1 -o "$TUTORIAL_ORG" -p examples -e rust
paas dbs info notes-db -o "$TUTORIAL_ORG" -p examples -e rust
paas apps attach notes-web notes-db -o "$TUTORIAL_ORG" -p examples -e rust
paas config set DATABASE_ENGINE=postgresql -a notes-web -o "$TUTORIAL_ORG" -p examples -e rust
Wait for database provisioning before trying to initialize the schema. The attachment
injects DATABASE_URL; never copy credentials into the source or .env in Git.
Check attachment names with paas apps attachments notes-web -o "$TUTORIAL_ORG" -p examples -e rust.
3. Deploy the notes app
git add .
git commit -m "Add persistent notes and export processes"
git push d2o main
Dashboard: wait for notes-web to be running in its Deployments/Overview view.
CLI: run paas watch -a notes-web -o "$TUTORIAL_ORG" -p examples -e rust. /health succeeds even before the schema exists;
/notes may return 503 until the next step.
4. Initialize the schema
Dashboard: notes-web → Console → select a running instance → Connect. Run:
/cnb/process/migrate
CLI:
paas run -a notes-web -o "$TUTORIAL_ORG" -p examples -e rust -- /cnb/process/migrate
Expect Schema ready. The command creates the notes table if missing, so it is safe to
repeat for this example. paas run does not relay the remote exit code: inspect the output
and verify /notes, rather than assuming a zero CLI exit means the schema succeeded.
5. Check persistence
Open the app URL, enter a sample note, and choose Save note. Refresh; the note remains. You can also test from your terminal:
curl -fsS -H "Content-Type: application/json" -d '{"body":"My first persistent note"}' "$APP_URL/notes"
curl -fsS "$APP_URL/notes"
Restart notes-web from its dashboard action or run paas restart -a notes-web -o "$TUTORIAL_ORG" -p examples -e rust.
Wait for it to be running and fetch /notes again; the note must still be present.
An empty body returns HTTP 400. Leave Export notes for the next chapter.
For production, replace manual schema setup with versioned release-command migrations.
Next: Add a Redis export worker.