RafalWilinski / cloudflare-rag

Fullstack "Chat with your PDFs" RAG (Retrieval Augmented Generation) app built fully on Cloudflare
https://rwilinski.ai
415 stars 42 forks source link

D1 database tables missing & improvements to setup.sh #6

Open DavidJKTofan opened 1 week ago

DavidJKTofan commented 1 week ago

Add the following command to the https://github.com/RafalWilinski/cloudflare-rag/blob/main/setup.sh setup file, after creating the D1 database, in order to automatically create the necessary tables too:

npx wrangler d1 execute cloudflare-rag --remote --file=./drizzle/20240828100648_skinny_midnight.sql
DavidJKTofan commented 1 week ago

Further improvements for the setup.sh file...

Replace the following part:

# After running this, you'll need to replace the database_id in wrangler.toml
npx wrangler d1 create cloudflare-rag

# After running this, you'll need to replace the id in wrangler.toml
npx wrangler kv namespace create rate-limiter

With:

# Step 1: Run the wrangler command and capture the database_id
output=$(npx wrangler d1 create cloudflare-rag)
# Extract the new database_id from the output using grep and cut
new_database_id=$(echo "$output" | grep "database_id =" | cut -d '"' -f 2)
# Step 2: Replace the old database_id in the wrangler.toml file
sed -i '' "s/database_id = \".*\"/database_id = \"$new_database_id\"/" wrangler.toml
echo "Updated wrangler.toml with new database_id: $new_database_id"

# Step 3: Create the KV namespace and capture the id
kv_output=$(npx wrangler kv namespace create rate-limiter)
new_kv_id=$(echo "$kv_output" | grep "id =" | awk -F '"' '{print $2}')
# Step 4: Replace the old KV id in the wrangler.toml file for the rate_limiter binding
sed -i '' "/\[\[kv_namespaces\]\]/,/^\[/{
  /binding = \"rate_limiter\"/{
    n
    s/id = \".*\"/id = \"$new_kv_id\"/
  }
}" wrangler.toml
echo "Updated wrangler.toml with new KV id for rate_limiter: $new_kv_id"

In order to automatically update the wrangler.toml with the new D1 and KV IDs.