From fe8af38de59ebf8b8306080f7462250e25517c2c Mon Sep 17 00:00:00 2001 From: "karthi.m" Date: Fri, 13 Mar 2026 09:59:41 +0000 Subject: [PATCH] Skill creation for Prisma template --- skills/create-prisma-ppg/SKILL.md | 33 ++++ .../create-prisma-ppg/resources/ai_rules.md | 39 +++++ .../resources/setup_instructions.md | 117 ++++++++++++++ .../scripts/install_node_official.ps1 | 103 ++++++++++++ .../scripts/install_node_official.sh | 152 ++++++++++++++++++ 5 files changed, 444 insertions(+) create mode 100644 skills/create-prisma-ppg/SKILL.md create mode 100644 skills/create-prisma-ppg/resources/ai_rules.md create mode 100644 skills/create-prisma-ppg/resources/setup_instructions.md create mode 100644 skills/create-prisma-ppg/scripts/install_node_official.ps1 create mode 100644 skills/create-prisma-ppg/scripts/install_node_official.sh diff --git a/skills/create-prisma-ppg/SKILL.md b/skills/create-prisma-ppg/SKILL.md new file mode 100644 index 00000000..9aae8227 --- /dev/null +++ b/skills/create-prisma-ppg/SKILL.md @@ -0,0 +1,33 @@ +--- +name: create-prisma-ppg +description: Creates a new Prisma project with a PostgreSQL database on Prisma Data Platform. +inputs: + - id: workspace_name + name: Workspace Name + type: string + description: The name of the folder for the new project. + default: my-prisma-ppg-app +--- + +## When to Use This Skill + +Use this skill to create a new Prisma project configured to work with a PostgreSQL database hosted on the Prisma Data Platform. + +## Instructions + +1. **Read Setup Instructions** + Review the [setup instructions](resources/setup_instructions.md) to understand how to initialize the project, check for prerequisites, set up the database, and run the application. + + *Action:* Read `resources/setup_instructions.md`. + +2. **Execute Setup** + Follow the steps outlined in `resources/setup_instructions.md` to: + - Create the project directory and copy the template files. + - Create the `.agents/rules/prisma-ppg.md` file using the content from `resources/airules.md`. + - Set up the database, install dependencies, and run migrations. + +3. **Final Verification** + Check that: + - `package.json` exists in the new project. + - `.agents/rules/prisma-ppg.md` exists. + - The template repository files exist in the new project directory. diff --git a/skills/create-prisma-ppg/resources/ai_rules.md b/skills/create-prisma-ppg/resources/ai_rules.md new file mode 100644 index 00000000..453ae72d --- /dev/null +++ b/skills/create-prisma-ppg/resources/ai_rules.md @@ -0,0 +1,39 @@ +# Gemini AI Rules for Prisma Projects + +## 1. Persona & Expertise + +You are an expert back-end developer and database architect with a deep specialization in Prisma ORM. You are proficient in data modeling, schema design, and writing type-safe, performant database queries using Prisma Client. You have a strong understanding of PostgreSQL and how to interact with it effectively through Prisma, especially when using the Prisma Data Platform. + +## 2. Project Context + +This project uses Prisma as its primary ORM for database access, with a PostgreSQL database hosted on the Prisma Data Platform. The `schema.prisma` file is the single source of truth for the database schema. The project is written in TypeScript and runs on Node.js. It also leverages Prisma Accelerate for connection pooling and caching. + +## 3. Coding Standards & Best Practices + +### General +- **Language:** Use TypeScript for all database-related code to leverage Prisma's full type-safety features. +- **Security:** Prioritize security in all database interactions. This includes validating and sanitizing all user input before it's used in a query and handling sensitive data like passwords with care (e.g., hashing). +- **Environment Variables:** Always store the `DATABASE_URL` and other sensitive credentials in an environment variable (`.env` file or via the environment), never in the source code. + +### Prisma-Specific +- **Schema First:** The `schema.prisma` file is the single source of truth. Always start by defining your models and relationships there. + - **Naming Conventions:** Use singular, PascalCase names for models (e.g., `User`, `Post`) and camelCase for fields (e.g., `firstName`). +- **Query Optimization:** + - **Selective Fields:** Use `select` or `include` to fetch only the data you need. Avoid fetching all fields of a model if they are not all required. + - **Pagination:** For queries that can return many records, always use cursor-based pagination (`cursor`, `take`, `skip`). + - **Batch Operations:** Use Prisma's batching capabilities (`createMany`, `updateMany`, `deleteMany`) for bulk write operations to reduce database overhead. +- **Migrations:** + - Use `prisma migrate dev` to create and apply migrations during development. + - For production environments, use the migration files generated by `prisma migrate dev` to ensure a predictable and version-controlled evolution of your database schema. +- **Prisma Client & Accelerate:** + - **Instantiation:** Instantiate Prisma Client (with Accelerate) once and reuse the instance across your application. + - **Type Safety:** Fully leverage the generated types from Prisma Client to ensure all your database queries are type-safe. + - **Caching:** Use Prisma Accelerate's caching features (`cacheStrategy`) to improve the performance of frequently executed queries. + +## 4. Interaction Guidelines + +- Assume the user is familiar with database concepts but may need guidance on Prisma-specific syntax and best practices. +- Provide clear and actionable code examples for defining Prisma schemas and writing queries with Prisma Client. +- When asked to add a feature, start by modifying the `schema.prisma` file, then generate and run a migration, and finally, write the application code that uses the new schema. +- If a request is ambiguous, ask for clarification about the data model, relationships between models, or the specific data to be queried. +- Break down complex tasks into smaller steps: defining the schema, running migrations, and writing the client-side query logic. diff --git a/skills/create-prisma-ppg/resources/setup_instructions.md b/skills/create-prisma-ppg/resources/setup_instructions.md new file mode 100644 index 00000000..2bcf4e2c --- /dev/null +++ b/skills/create-prisma-ppg/resources/setup_instructions.md @@ -0,0 +1,117 @@ +# Prisma with PostgreSQL Setup Instructions + +Follow these steps to initialize the workspace. + +--- + +## 1. Install prerequisites (Node.js + npm) + +This skill requires: +- Node.js (recommended 20.x+) +- npm (bundled with Node) + +### 1.1 Verify +Run: +- `node -v` +- `npm -v` + +If both work, go to **Step 2**. + +### 1.2 Install automatically from official Node.js downloads (recommended) +Use the provided prereq installer script that: +- detects OS + CPU architecture +- fetches the latest LTS from Node’s official release index +- downloads the correct official installer/binary from nodejs.org +- installs it + +Run ONE of the following depending on your OS: + +#### Windows (PowerShell) +Run: +- `powershell -ExecutionPolicy Bypass -File "skills/prisma-ppg/scripts/install_node_official.ps1"` + +Then restart terminal / Antigravity session and verify: +- `node -v` +- `npm -v` + +#### macOS / Linux (bash) +Run: +- `bash "skills/prisma-ppg/scripts/install_node_official.sh"` + +Then restart shell and verify: +- `node -v` +- `npm -v` + +> Note: macOS/Linux install may require `sudo` for system-wide installation. + +--- + +## 2. Create the project (copy template files) + +Create the project directory from the project root: + +```bash +mkdir -p "${workspace_name}" +``` + +Copy the Prisma with PostgreSQL template files into the workspace: + +```bash +# Copy from this repo's template into the new workspace +cp -r templates/prisma/app-ppg/* "${workspace_name}/" +``` + +Then enter the workspace: + +```bash +cd "${workspace_name}" +``` + +--- + +## 3. Configure Agents Rules + +This step copies the AI rules file into the new workspace. + +```bash +mkdir -p ".agents/rules" +cp ../../skills/prisma-ppg/resources/airules.md .agents/rules/prisma-ppg.md +``` + +--- + +## 4. Set up the Database + +### 4.1 Create a Prisma Postgres database +You'll need to create a new project on the [Prisma Data Platform](https://console.prisma.io/) and create a new Prisma Postgres database. + +### 4.2 Set the DATABASE_URL +Once your database is ready, copy the `DATABASE_URL` and add it to the `.idx/dev.nix` file. After you've done that, you'll need to rebuild the environment for the changes to take effect. + +--- + +## 5. Run Migrations + +Once your database is set up and the environment is rebuilt, run the following command in the terminal to create the database tables: + +```bash +npx prisma migrate dev --name init +``` + +--- + +## 6. Run the Application + +The main application logic is in `src/queries.ts`. You can run it with: + +```bash +npm run queries +``` + +This will execute a number of CRUD queries against your database. + +You can also explore Prisma Accelerate caching by running: + +```bash +npm run caching +``` diff --git a/skills/create-prisma-ppg/scripts/install_node_official.ps1 b/skills/create-prisma-ppg/scripts/install_node_official.ps1 new file mode 100644 index 00000000..81169cc3 --- /dev/null +++ b/skills/create-prisma-ppg/scripts/install_node_official.ps1 @@ -0,0 +1,103 @@ +# Installs the latest Node.js LTS from official nodejs.org releases (user-local install). +# - Detects CPU architecture +# - Fetches latest LTS from Node dist index.json +# - Downloads the official ZIP +# - Extracts to %LOCALAPPDATA%\Programs\nodejs\ +# - Adds to user PATH (no admin required) +# - Prompts to restart terminal / Antigravity + +$ErrorActionPreference = "Stop" +Set-StrictMode -Version Latest + +function Get-LatestLtsVersion { + $index = Invoke-RestMethod -Uri "https://nodejs.org/dist/index.json" + $lts = $index | Where-Object { $_.lts -ne $false } | Select-Object -First 1 + if (-not $lts -or -not $lts.version) { + throw "Could not determine latest LTS from https://nodejs.org/dist/index.json" + } + return $lts.version # e.g., v20.11.1 +} + +function Get-PlatformSuffix { + $arch = $env:PROCESSOR_ARCHITECTURE + switch ($arch) { + "AMD64" { return "win-x64" } + "ARM64" { return "win-arm64" } + "x86" { return "win-x86" } + default { throw "Unsupported Windows architecture: $arch" } + } +} + +function Get-MajorVersion([string]$v) { + # v like "v20.11.1" + $v = $v.Trim() + if ($v.StartsWith("v")) { $v = $v.Substring(1) } + return [int]($v.Split(".")[0]) +} + +# If Node already installed and >= 20, do nothing. +try { + $existing = & node -v 2>$null + if ($LASTEXITCODE -eq 0) { + $major = Get-MajorVersion $existing + if ($major -ge 20) { + Write-Host "Node is already installed ($existing). No action needed." + Write-Host "npm version: " -NoNewline; & npm -v + exit 0 + } + Write-Host "Node detected ($existing) but < 20; proceeding to install latest LTS." + } +} catch { + # node not found +} + +$version = Get-LatestLtsVersion +$platform = Get-PlatformSuffix +$zipName = "node-$version-$platform.zip" +$zipUrl = "https://nodejs.org/dist/$version/$zipName" + +$installBase = Join-Path $env:LOCALAPPDATA "Programs\nodejs" +New-Item -ItemType Directory -Force -Path $installBase | Out-Null + +$tmpDir = Join-Path $env:TEMP ("node-install-" + [guid]::NewGuid().ToString("N")) +New-Item -ItemType Directory -Force -Path $tmpDir | Out-Null +$zipPath = Join-Path $tmpDir $zipName + +try { + Write-Host "Downloading $zipUrl" + Invoke-WebRequest -Uri $zipUrl -OutFile $zipPath + + Write-Host "Extracting to $installBase" + Expand-Archive -Path $zipPath -DestinationPath $installBase -Force + + $extractedDir = Join-Path $installBase ("node-" + $version + "-" + $platform) + if (-not (Test-Path $extractedDir)) { + throw "Extraction failed; expected folder not found: $extractedDir" + } + + # Add to user PATH if not present + $userPath = [Environment]::GetEnvironmentVariable("Path", "User") + if (-not $userPath) { $userPath = "" } + + $already = $userPath.Split(";") | Where-Object { $_.Trim() -ieq $extractedDir } + if (-not $already) { + $newUserPath = ($extractedDir + ";" + $userPath).TrimEnd(";") + [Environment]::SetEnvironmentVariable("Path", $newUserPath, "User") + Write-Host "Added Node to user PATH: $extractedDir" + } else { + Write-Host "Node path already present in user PATH." + } + + # Also update current session PATH + $env:Path = $extractedDir + ";" + $env:Path + + Write-Host "Installed Node $version" + Write-Host "Verify:" + & node -v + & npm -v + + Write-Host "" + Write-Host "Restart your terminal / Antigravity session so PATH updates fully." +} finally { + if (Test-Path $tmpDir) { Remove-Item -Recurse -Force $tmpDir } +} \ No newline at end of file diff --git a/skills/create-prisma-ppg/scripts/install_node_official.sh b/skills/create-prisma-ppg/scripts/install_node_official.sh new file mode 100644 index 00000000..0c722bdb --- /dev/null +++ b/skills/create-prisma-ppg/scripts/install_node_official.sh @@ -0,0 +1,152 @@ +#!/usr/bin/env bash +set -euo pipefail + +# Installs latest Node.js LTS from official nodejs.org releases (user-local install). +# - Detects OS + CPU arch +# - Fetches latest LTS from Node dist index.json +# - Downloads official tarball and installs under ~/.local/node/current +# - Updates shell profile PATH (bash/zsh/profile) +# - Prompts restart + +need_cmd() { command -v "$1" >/dev/null 2>&1; } + +if need_cmd node; then + ver="$(node -v)" + major="${ver#v}"; major="${major%%.*}" + if [[ "$major" -ge 20 ]]; then + echo "Node is already installed ($ver). No action needed." + npm -v || true + exit 0 + fi + echo "Node detected ($ver) but < 20; proceeding to install latest LTS." +fi + +DL_TOOL="" +if need_cmd curl; then DL_TOOL="curl -fsSL" +elif need_cmd wget; then DL_TOOL="wget -qO-" +else + echo "Error: need curl or wget" + exit 1 +fi + +OS="$(uname -s)" +ARCH="$(uname -m)" + +case "$OS" in + Darwin) OS_TAG="darwin" ;; + Linux) OS_TAG="linux" ;; + *) + echo "Unsupported OS: $OS" + exit 1 + ;; +esac + +case "$ARCH" in + x86_64|amd64) ARCH_TAG="x64" ;; + arm64|aarch64) ARCH_TAG="arm64" ;; + armv7l) ARCH_TAG="armv7l" ;; + *) + echo "Unsupported architecture: $ARCH" + exit 1 + ;; +esac + +INDEX_JSON="$($DL_TOOL https://nodejs.org/dist/index.json)" + +# Parse latest LTS version: +if need_cmd jq; then + VERSION="$(printf '%s' "$INDEX_JSON" | jq -r '.[] | select(.lts != false) | .version' | head -n 1)" +elif need_cmd python3; then + VERSION="$(python3 - <<'PY' +import json,sys +data=json.load(sys.stdin) +for r in data: + if r.get("lts") not in (False, None): + print(r["version"]) + break +PY +<<<"$INDEX_JSON")" +else + echo "Error: need jq or python3 to parse Node release index.json" + exit 1 +fi + +if [[ -z "${VERSION:-}" || "${VERSION}" == "null" ]]; then + echo "Error: could not determine latest LTS version" + exit 1 +fi + +PLATFORM="${OS_TAG}-${ARCH_TAG}" + +# Node uses .tar.gz for macOS builds, and .tar.xz for Linux builds. +EXT="tar.xz" +[[ "$OS_TAG" == "darwin" ]] && EXT="tar.gz" + +TARBALL="node-${VERSION}-${PLATFORM}.${EXT}" +URL="https://nodejs.org/dist/${VERSION}/${TARBALL}" + +INSTALL_BASE="${INSTALL_BASE:-$HOME/.local/node}" +INSTALL_DIR="${INSTALL_BASE}/${VERSION}" + +mkdir -p "$INSTALL_BASE" + +TMP="$(mktemp -d)" +cleanup() { rm -rf "$TMP"; } +trap cleanup EXIT + +echo "Downloading $URL" +if need_cmd curl; then + curl -fsSL "$URL" -o "$TMP/$TARBALL" +else + wget -q "$URL" -O "$TMP/$TARBALL" +fi + +echo "Installing to $INSTALL_DIR" +rm -rf "$INSTALL_DIR" +mkdir -p "$INSTALL_DIR" + +if [[ "$EXT" == "tar.gz" ]]; then + tar -xzf "$TMP/$TARBALL" -C "$TMP" +else + tar -xJf "$TMP/$TARBALL" -C "$TMP" +fi + +EXTRACTED="$TMP/node-${VERSION}-${PLATFORM}" +if [[ ! -d "$EXTRACTED" ]]; then + echo "Error: expected extracted folder not found: $EXTRACTED" + exit 1 +fi + +# Move contents into versioned install dir +cp -R "$EXTRACTED"/. "$INSTALL_DIR"/ + +# Update 'current' symlink +ln -sfn "$INSTALL_DIR" "$INSTALL_BASE/current" + +NODE_BIN="$INSTALL_BASE/current/bin" +EXPORT_LINE="export PATH=\"$NODE_BIN:\$PATH\"" +MARKER="# >>> antigravity node >>>" + +write_profile() { + local f="$1" + [[ -f "$f" ]] || touch "$f" + if ! grep -q "$MARKER" "$f"; then + { + echo "" + echo "$MARKER" + echo "$EXPORT_LINE" + echo "# <<< antigravity node <<<" + } >> "$f" + fi +} + +# Update common profiles +write_profile "$HOME/.bashrc" +write_profile "$HOME/.zshrc" +write_profile "$HOME/.profile" + +echo "" +echo "Installed Node ${VERSION} under $INSTALL_BASE/current" +echo "Restart your shell / Antigravity session, then verify:" +echo " node -v" +echo " npm -v" \ No newline at end of file