Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions skills/create-prisma-ppg/SKILL.md
Original file line number Diff line number Diff line change
@@ -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.
39 changes: 39 additions & 0 deletions skills/create-prisma-ppg/resources/ai_rules.md
Original file line number Diff line number Diff line change
@@ -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.
117 changes: 117 additions & 0 deletions skills/create-prisma-ppg/resources/setup_instructions.md
Original file line number Diff line number Diff line change
@@ -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
```
103 changes: 103 additions & 0 deletions skills/create-prisma-ppg/scripts/install_node_official.ps1
Original file line number Diff line number Diff line change
@@ -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\<version>
# - 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 }
}
Loading