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
36 changes: 36 additions & 0 deletions skills/postgres/resources/ai_rules.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# AI Rules for the PostgreSQL Project

## 1. Project Overview

This project provides a self-contained, reproducible PostgreSQL development environment using Nix. It is designed to be a ready-to-use database starter with a pre-defined schema and sample data.

The key characteristics are:

- **Automated Setup:** The environment is fully automated by the `.idx/dev.nix` file. It starts a PostgreSQL 16 server, creates a database, and initializes it.
- **Database Details:**
- **Database Name:** `youtube`
- **User:** `user`
- **Password:** `mypassword`
- **Pre-configured Tools:** The environment includes the `sqltools` and `sqltools-driver-pg` VS Code extensions for immediate database interaction.

## 2. Key Files

When providing assistance, be aware of the following files:

- **`create.sql`**: Defines the database schema (tables, columns, etc.). This is the source of truth for the database structure.
- **`example.sql`**: Contains sample data that is inserted into the database after the schema is created. Useful for demonstrating queries.
- **`.idx/dev.nix`**: The core Nix file that defines the entire development environment, including services, packages, and startup scripts. Avoid suggesting manual installation of packages that can be managed here.

## 3. Development Environment

- **Nix-Managed:** The environment is controlled by Nix. Do not suggest using `apt`, `brew`, or other system-level package managers. Dependencies like `postgresql` are managed through the `dev.nix` file.
- **SQLTools:** The workspace is pre-configured with SQLTools. Encourage users to leverage this extension for running queries, browsing the schema, and managing the database directly from the IDE.
- **Connection String:** The `POSTGRESQL_CONN_STRING` environment variable is available for applications that need to connect to the database.

## 4. Interaction Guidelines

- Assume the user is familiar with SQL but may be new to this Nix-based, automated setup.
- When generating SQL queries, tailor them to the schema defined in `create.sql` (e.g., query the `videos` table).
- If a user wants to modify the database schema, guide them to edit the `create.sql` file. Remind them that for the changes to take effect in a new workspace, the setup script must be re-run (which happens automatically on creation). For an existing workspace, they may need to apply the changes manually using SQLTools.
- Proactively suggest using the integrated SQLTools for database interaction instead of external clients.
- If the user asks about connection details, refer them to the pre-set database name (`youtube`), user (`user`), and password (`mypassword`).
28 changes: 28 additions & 0 deletions skills/postgres/resources/setup_instructions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Postgres Workspace Setup Instructions

This skill automates the entire setup of a new PostgreSQL database environment. There are no manual installation steps required.

---

## 1. Create the Database Project

When you run this skill, you will be prompted for a `Project Name`. This name will be used to create a new directory for your database project.

The skill will then automatically perform the following actions:

- **Scaffold the Project:** It copies a pre-configured set of files into your new project directory.
- **Configure the Environment:** A file at `.idx/dev.nix` is included, which tells IDX to automatically:
- Start a PostgreSQL 16 server.
- Create a database named `youtube`.
- Create a user named `user` with the password `mypassword`.
- Initialize the database schema by running `create.sql`.
- Populate the database with sample data by running `example.sql`.
- **Set Environment Variables:** It configures the `POSTGRESQL_CONN_STRING` environment variable so you can connect to your database instantly.

---

## 2. Using Your Database

Once the skill is finished, your PostgreSQL database is ready to use immediately.

No further setup is required. You can connect to the database using the provided connection string or use the integrated SQLTools within the IDE.
12 changes: 12 additions & 0 deletions skills/postgres/scripts/install_postgres.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Prompt the user for a project name.
$ProjectName = Read-Host -Prompt "Enter the project name (default: my-postgres-project)"

# If no project name is entered, use the default.
if ([string]::IsNullOrWhiteSpace($ProjectName)) {
$ProjectName = "my-postgres-project"
}

# Copy the pre-configured postgres app template to the new project directory.
Copy-Item -Path "postgres/app" -Destination $ProjectName -Recurse -Force

Write-Host "PostgreSQL project '$ProjectName' created successfully."
14 changes: 14 additions & 0 deletions skills/postgres/scripts/install_postgres.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash

# Prompt the user for a project name.
read -p "Enter the project name (default: my-postgres-project): " projectName

# If no project name is entered, use the default.
if [ -z "$projectName" ]; then
projectName="my-postgres-project"
fi

# Copy the pre-configured postgres app template to the new project directory.
cp -r postgres/app/ "$projectName"

echo "PostgreSQL project \'"$projectName"\' created successfully."
22 changes: 22 additions & 0 deletions skills/postgres/skill.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
name: postgres
description: Creates a new PostgreSQL database project using a pre-configured development environment with custom AI rules.
---

## When to Use This Skill

Use this skill when the user wants to create a new, ready-to-use PostgreSQL database environment. The skill scaffolds a complete project with a running database server, a pre-defined schema, and example data.

## Instructions

1. **Read Setup Instructions**

Review the [setup instructions](resources/setup_instructions.md) to understand how the project is initialized.

*Action: Read `resources/setup_instructions.md`.*

2. **Create the Project**

This skill uses a script to create the project. The script will copy the necessary files and set up the initial project structure.

*Action: `run_terminal_command(command='bash skills/postgres/scripts/install_postgres.sh', windowsCommand='powershell -File skills/postgres/scripts/install_postgres.ps1')`.*