Step 5 — Database setup

Hard-coded mugs disappear when the server restarts. Put the catalog in a database so Ada always sees the same products — on your laptop today, on a server tomorrow.

What is a database migration? (in general)

A database is durable storage (rows in tables). Your PHP code reads and writes those rows; when the process dies, the data remains.

A migration is a versioned recipe that creates or changes tables:

  • “Create products with name, price, stock”
  • Later: “Add customers,” “Add orders

Everyone who clones the repo runs php pionia migrate and gets the same schema. That beats emailing a schema.sql around.

Pionia Shop starts with SQLite (one file, zero install). Production often uses PostgreSQL or MySQL — same migration files.

What you will learn

  • Confirm [db] for SQLite
  • Scaffold and run a products migration
Before you start

Confirm SQLite

In environment/settings.ini:

[db]
database_type=sqlite
database_name=database.sqlite3
default=true

Create the products table

php pionia make:table products \
  --columns="name:string,price:decimal,stock:integer" \
  --timestamps

Review the migration — you want something like:

Schema::create('products', function (Blueprint $table) {
    $table->id();
    $table->string('name');
    $table->decimal('price', 10, 2);
    $table->integer('stock')->default(0);
    $table->timestamps();
});
php pionia migrate
php pionia migrate:status

Optional seed via php pionia shell:

table('products')->save(['name' => 'Ada Mug', 'price' => 24.50, 'stock' => 12]);
table('products')->save(['name' => 'Pionia Sticker Pack', 'price' => 6.00, 'stock' => 200]);

Later you will add customers, orders, and wallets the same way. Full field reference: Migrations.

Common mistakes

  • Forgetting migrate — Step 6 fails with “no such table: products”
  • Running commands outside pionia-shop/