build: build-ui build-api

migrate:
    # Apply schema migrations to the remote D1 database.
    # The ALTER TABLE at the end will error if hidden already exists — that's expected.
    wrangler d1 execute quotesdb --remote --file migrations/schema.sql

build-api:
    # worker-build runs wasm-bindgen to produce ES-module-compatible output in build/worker/.
    # Install once with: cargo install worker-build
    # --features workers-api enables D1 bindings and route handlers for the Workers runtime.
    worker-build --release -- --features workers-api

build-ui:
    trunk build --release

deploy: deploy-ui deploy-api

deploy-ui:
    # --commit-dirty=true silences the git-dirty warning (expected during local deploys).
    wrangler pages deploy dist --project-name quotesdb-ui --branch quotesdb --commit-dirty=true

deploy-api:
    wrangler deploy --config wrangler.toml

run-api:
    cargo run --features workers-api

run-ui:
    trunk serve

rotate-admin-code:
    #!/usr/bin/env bash
    set -euo pipefail
    CODE="$(pwgen -s 32 1)"
    echo "New ADMIN_AUTH_CODE: $CODE"
    echo "$CODE" | wrangler secret put ADMIN_AUTH_CODE --config wrangler.toml
