Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/ItsJhonAlex/Ecommerce/llms.txt

Use this file to discover all available pages before exploring further.

Avanzar In Time Shop uses PostgreSQL 17 (Alpine) as its data store, provisioned locally via Docker Compose. The schema is defined in TypeScript using Drizzle ORM inside the @avanzar/db package, which exports both the Drizzle client (db) and all table definitions. Schema migrations are managed by drizzle-kit, which reads DATABASE_URL from the environment and applies SQL migration files from the packages/db/drizzle/ directory. All database commands are available as bun run db:* scripts from the monorepo root.

Starting PostgreSQL

Bring up the PostgreSQL container in the background with a single command:
bun run db:up
This runs docker compose up -d. Docker Compose reads POSTGRES_USER, POSTGRES_PASSWORD, POSTGRES_DB, and POSTGRES_HOST_PORT from your .env file at the monorepo root. The container is named avanzar_postgres and data is persisted in the named volume avanzar_pgdata. The service includes a healthcheck so dependent tooling can wait for the database to be ready before connecting:
healthcheck:
  test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER:-avanzar} -d ${POSTGRES_DB:-avanzar}"]
  interval: 5s
  timeout: 5s
  retries: 10

Running Migrations

Apply all pending migrations to your database with:
bun run db:migrate
This delegates to bun run --env-file=../../.env drizzle-kit migrate inside packages/db, loading DATABASE_URL from the monorepo root .env before drizzle-kit runs. The initial migration file is located at:
packages/db/drizzle/0000_violet_shriek.sql
This file creates all 14 tables, the 5 PostgreSQL enum types, and the necessary foreign key constraints in a single transaction. Always run migrations before starting the backend for the first time or after pulling schema changes.

Available Database Commands

Run all of the following from the monorepo root:
CommandDescription
bun run db:generateIntrospect schema changes and generate a new SQL migration file in packages/db/drizzle/
bun run db:migrateApply all pending migration files to the target database
bun run db:pushPush the current schema directly to the database without creating a migration file — development only
bun run db:studioOpen Drizzle Studio in your browser for a visual GUI over the live database
bun run db:upStart the PostgreSQL Docker container in detached mode
bun run db:downStop and remove the PostgreSQL Docker container
Use bun run db:studio during development to browse rows, inspect foreign key relationships, and manually edit data without writing raw SQL. Drizzle Studio runs entirely locally and reads DATABASE_URL from your .env file.

Schema Overview

The schema is defined in packages/db/src/schema/ and is divided into four functional domains.

Enum Types

Five PostgreSQL native enums are defined in packages/db/src/schema/enums.ts:
EnumValues
user_rolecustomer, staff, admin
product_statusdraft, active, archived
order_statuspending_payment, paid, preparing, shipped, delivered, cancelled
payment_methodcod, transfer_local, zelle
payment_statuspending, confirmed, rejected
product_status uses archived as its soft-delete sentinel — rows are never hard-deleted from the products table. payment_status reflects the manual confirmation workflow where staff or admin confirms or rejects each payment.

Tables by Domain

Auth — managed by Better Auth via the Drizzle adapter:
TablePurpose
userCore user record with name, email, role, and timestamps
sessionActive session tokens with expiry and user-agent metadata
accountOAuth provider link records (also used for email+password)
verificationTime-limited verification tokens for email flows
Catalog — product data:
TablePurpose
productsProduct master record with product_status and user_id ownership
product_pricesVersioned pricing rows linked to a product
product_imagesOrdered image URLs attached to a product
categoriesFlat category taxonomy
product_categoriesMany-to-many join between products and categories
Commerce — order lifecycle:
TablePurpose
ordersTop-level order record linked to a user and shipping address
order_itemsLine items within an order (product, quantity, unit price)
order_status_historyAppend-only log of every order_status transition
paymentsPayment record with payment_method and payment_status
Address / Shipping:
TablePurpose
addressesSaved delivery addresses belonging to a user
shipping_ratesFlat-rate shipping fee configurations
The Drizzle config at packages/db/drizzle.config.ts reads DATABASE_URL directly from process.env. The db:migrate, db:push, and db:studio scripts all inject the env file with --env-file=../../.env so the variable is always available when drizzle-kit runs.

Build docs developers (and LLMs) love