Last active
December 6, 2024 09:05
-
-
Save wasdee/aa62473eb56f65ff8689c6971cf0d6b2 to your computer and use it in GitHub Desktop.
Generate the DB schema for the AI Contexts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# mise description="Generate the DB schema for the AI Contexts" | |
set -euo pipefail | |
cd "$(git rev-parse --show-toplevel)" | |
mkdir -p ./AIContexts/ | |
docker run --rm -v "$PWD/AIContexts:/data" postgres:15 \ | |
pg_dump $POSTGRES_URL -s -O -x -n public -t public.* -f /data/db_schema.sql | |
echo "Please follow up by asking ai (Cursor Long Context Chat) to create compressed version of the db schema | |
Rewrite this DB schema for AI context: | |
- Shorten it by incorporating foreign keys, indexes, primary keys, and unique constraints directly into CREATE TABLE statements. | |
- Remove views, `SET` statements, and `create policy` statements. | |
" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
script({ | |
title: "DB Schema Refiner", | |
description: "Compresses and simplifies SQL schema for AI context", | |
model: "openai:gpt-4", | |
temperature: 0 | |
}) | |
def("SQL_FILES", env.files, { endsWith: ".sql" }) | |
$`You are a database expert. Your task is to rewrite the SQL schema in SQL_FILES to be more concise and AI-friendly. | |
Follow these rules: | |
1. Incorporate foreign keys, indexes, primary keys, and unique constraints directly into CREATE TABLE statements | |
2. Remove all SET statements, and create policy statements | |
3. Keep only essential schema information, including comments but as sql comments | |
4. Use clear but concise column names | |
5. Include only CREATE TABLE statements | |
Format the output as valid SQL that can be executed. | |
Here is the schema to refine:` | |
$`${SQL_FILES}` | |
$`Rewrite the schema following the rules above. Respond only with the SQL statements.` | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment