Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
DavidJKTofan opened this issue Sep 5, 2024 · 1 comment
Open

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

DavidJKTofan opened this issue Sep 5, 2024 · 1 comment

Comments

@DavidJKTofan
Copy link

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
Copy link
Author

DavidJKTofan commented Sep 5, 2024

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.

@DavidJKTofan DavidJKTofan changed the title D1 database tables missing D1 database tables missing & improvements to setup.sh Sep 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant