Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Optional: persist notes in MariaDB

This chapter replaces the primary PostgreSQL attachment. It uses the same web routes, Redis queue, worker, and object-storage integration. The app selects the same SQL notes table, through its MariaDB driver. This is a fresh dataset, not an automatic migration of your PostgreSQL notes.

1. Create the alternative database

Dashboard: in nodejs create Database notes-mariadb, engine MariaDB, 1 GB storage. Wait until running. CLI:

paas dbs create notes-mariadb --type mariadb --storage-gb 1 -o "$TUTORIAL_ORG" -p examples -e nodejs
paas dbs info notes-mariadb -o "$TUTORIAL_ORG" -p examples -e nodejs

2. Pause traffic and change both apps

Finish outstanding exports, then stop using the sample app while changing stores. On the worker’s Overview, use − in Replicas to reach zero and confirm, or run paas scale 0 -a notes-worker -o "$TUTORIAL_ORG" -p examples -e nodejs.

Dashboard: for both notes-web and notes-worker, open Config and detach only the current primary database (DATABASE_URL). Attach notes-mariadb using DATABASE_URL, then set DATABASE_ENGINE=mariadb. Keep Redis and bucket attachments.

CLI: list each app’s attachments and copy the ID for its primary database:

paas apps attachments notes-web -o "$TUTORIAL_ORG" -p examples -e nodejs
paas apps attachments notes-worker -o "$TUTORIAL_ORG" -p examples -e nodejs

Replace the two placeholders below with the attachment IDs, which differ per app and are not the database resource ID:

paas apps detach notes-web <web-primary-attachment-id> -o "$TUTORIAL_ORG" -p examples -e nodejs
paas apps detach notes-worker <worker-primary-attachment-id> -o "$TUTORIAL_ORG" -p examples -e nodejs
paas apps attach notes-web notes-mariadb -o "$TUTORIAL_ORG" -p examples -e nodejs
paas apps attach notes-worker notes-mariadb -o "$TUTORIAL_ORG" -p examples -e nodejs
paas config set DATABASE_ENGINE=mariadb -a notes-web -o "$TUTORIAL_ORG" -p examples -e nodejs
paas config set DATABASE_ENGINE=mariadb -a notes-worker -o "$TUTORIAL_ORG" -p examples -e nodejs

Do not keep a plain DATABASE_URL variable that could override the injected attachment. Changing attachments/config rolls out the app automatically; wait until the web process is running. See attachments and configuration precedence.

3. Initialize and verify

Dashboard: run /cnb/process/migrate in notes-web’s Console.

CLI:

paas run -a notes-web -o "$TUTORIAL_ORG" -p examples -e nodejs -- /cnb/process/migrate

Expect Schema ready. Restore the worker to one replica using + on Overview or with paas scale 1 -a notes-worker -o "$TUTORIAL_ORG" -p examples -e nodejs. Create a new note identifying MariaDB, restart the web app, and verify it remains. Generate a new export and confirm the new note appears in the JSON. Previously generated export files are snapshots of the old store; they do not change.

To return to PostgreSQL, repeat the attachment change for notes-db and set DATABASE_ENGINE=postgresql on both apps. Your earlier PostgreSQL notes remain there until you explicitly delete that database. Each engine can be followed independently; you do not have to finish the other optional chapter first.

Continue with MariaDB or MongoDB if you want to compare primary stores. Each is optional and starts a separate dataset. Then prepare the app for production or clean up the tutorial resources.