Skip to content

Latest commit

 

History

History
30 lines (20 loc) · 1.29 KB

File metadata and controls

30 lines (20 loc) · 1.29 KB

How to set up a D1 database

Note

If you still have the CLOUDFLARE_D1_DATABASE_ID, CLOUDFLARE_D1_BEARER_TOKEN and CLOUDFLARE_ACCOUNT_ID variables in .dev.vars, you can delete those and follow this guide instead

Cloud Sync uses an SQL D1 database with the name of VendettaCloudSync1 to store user data.

Steps

  1. Pick a name and location (optional) for the database

    • You can list the available locations by running bunx wrangler d1 create
  2. Create the database

    $ bunx wrangler d1 create [name] --location [location]
  3. Copy the database_name and database_id values from the previous command and replace them in wrangler.jsonc

    • You may notice the database is there twice, which is intentional because otherwise wrangler shouts at me during development
  4. Initialize the database both locally (miniflare) and on the real database

    $ bunx wrangler d1 execute DB --local --file ./schema.sql
    $ bunx wrangler d1 execute DB --remote --yes --file ./schema.sql
  5. You're done!

Footnotes

  1. from the ye olden days, which is why it doesn't follow the naming convention (cloudflare doesn't let you rename databases for whatever reason)