From 3636365f9d5fb2a1c9c9d03f2dee6e75f6069c9d Mon Sep 17 00:00:00 2001 From: James Rodewig Date: Mon, 16 Dec 2024 10:58:20 -0500 Subject: [PATCH 1/8] Update README for CLI v4 --- README.md | 84 ++++++++++++++++++--------------------------- seed/categories.fql | 4 +-- seed/customers.fql | 4 +-- setup.sh | 7 ++++ 4 files changed, 45 insertions(+), 54 deletions(-) create mode 100644 setup.sh diff --git a/README.md b/README.md index 4651f8e..8d8518e 100644 --- a/README.md +++ b/README.md @@ -68,19 +68,15 @@ To run the app, you'll need: - Your preferred flavor of Java 17 -- [Fauna CLI](https://docs.fauna.com/fauna/current/tools/shell/) v3.0.0 or later. +- [Fauna CLI](https://docs.fauna.com/fauna/current/tools/shell/) 4.0.0-beta or later. + - [Node.js](https://nodejs.org/en/download/) v20.x or later. To install the CLI, run: ```sh - npm install -g fauna-shell@latest + npm install -g fauna-shell@">=4.0.0-beta" ``` -You should also be familiar with basic Fauna CLI commands and usage. For an -overview, see the [Fauna CLI -docs](https://docs.fauna.com/fauna/current/tools/shell/). - - ## Setup 1. Clone the repo and navigate to the `java-sample-app` directory: @@ -90,75 +86,58 @@ docs](https://docs.fauna.com/fauna/current/tools/shell/). cd java-sample-app ``` -2. Log in to Fauna using the Fauna CLI: +2. If you haven't already, log in to Fauna using the Fauna CLI: ```sh - fauna cloud-login + fauna login ``` - When prompted, enter: - - * **Endpoint name:** `cloud` (Press Enter) - * **Email address:** The email address for your Fauna account. - * **Password:** The password for your Fauna account. - * **Which endpoint would you like to set as default?** The `cloud-*` - endpoint for your preferred region group. For example, to use the US - region group, use `cloud-us`. - - The command requires an email and password login. If you log in to Fauna - using GitHub or Netlify, you can enable email and password login using the - [Forgot Password](https://dashboard.fauna.com/forgot-password) workflow. - -3. Use the Fauna CLI to create the `ECommerceJava` database: +3. Use the CLI to create the `ECommerceJava` database: ```sh - fauna create-database ECommerceJava + # Replace 'us-std' with your preferred Region Group + # identifier: 'us-std' (United States), 'eu-std' (Europe), + # or `global`. + fauna database create \ + --name ECommerceJava \ + --database us-std ``` -4. Create a - [`.fauna-project`](https://docs.fauna.com/fauna/current/tools/shell/#proj-config) - config file for the project: - - ```sh - fauna project init - ``` - - When prompted, enter: - - * `schema` as the schema directory. - * `dev` as the environment name. - * The default endpoint. - * `ECommerce` as the database. - -5. Push the `.fsl` files in the `schema` directory to the `ECommerceJava` +4. Push the `.fsl` files in the `schema` directory to the `ECommerceJava` database: ```sh - fauna schema push + # Replace 'us-std' with your Region Group identifier. + fauna schema push \ + --database us-std/ECommerceJava \ + --dir ./schema ``` When prompted, accept and stage the schema. -6. Check the status of the staged schema: +5. Check the status of the staged schema: ```sh - fauna schema status + fauna schema status \ + --database us-std/ECommerceJava ``` -7. When the status is `ready`, commit the staged schema to the database: +6. When the status is `ready`, commit the staged schema to the database: ```sh - fauna schema commit + fauna schema commit \ + --database us-std/ECommerceJava ``` The commit applies the staged schema to the database. The commit creates the collections and user-defined functions (UDFs) defined in the `.fsl` files of the `schema` directory. -8. Create a key with the `server` role for the `ECommerceJava` database: +7. Create a key with the `server` role for the `ECommerceJava` database: ```sh - fauna create-key --environment='' ECommerceJava server + fauna query "Key.create({ role: 'server' })" \ + --database us-std/ECommerceJava ``` Copy the returned `secret`. The app can use the key's secret to authenticate @@ -170,6 +149,7 @@ The app includes a setup script that adds sample documents to the `ECommerceJava` database. From the root directory, run: ```sh +chmod +x setup.sh FAUNA_SECRET= ./setup.sh ``` @@ -263,21 +243,25 @@ Customer documents and related API responses: database to stage the changes: ```sh - fauna schema push + fauna schema push \ + --database us-std/ECommerceJava \ + --dir ./schema ``` When prompted, accept and stage the schema. 4. Check the status of the staged schema: ```sh - fauna schema status + fauna schema status \ + --database us-std/ECommerceJava ``` 5. When the status is `ready`, commit the staged schema changes to the database: ```sh - fauna schema commit + fauna schema commit \ + --database us-std/ECommerceJava ``` 6. In `CustomersController.java`, add the diff --git a/seed/categories.fql b/seed/categories.fql index 867f4d9..0534bda 100644 --- a/seed/categories.fql +++ b/seed/categories.fql @@ -1,4 +1,4 @@ -{"query": "[ +[ { 'name': 'electronics' }, @@ -8,4 +8,4 @@ { 'name': 'movies' } -].map(c => Category.byName(c.name).first() ?? Category.create({ name: c.name, description: \"Bargain #{c.name}!\" }))"} +].map(c => Category.byName(c.name).first() ?? Category.create({ name: c.name, description: "Bargain #{c.name}!" })) diff --git a/seed/customers.fql b/seed/customers.fql index 0cb732c..cfbbdf3 100644 --- a/seed/customers.fql +++ b/seed/customers.fql @@ -1,4 +1,4 @@ -{"query":"[ +[ { id: '999', name: 'Valued Customer', @@ -11,4 +11,4 @@ country: 'Netherlands' } } -].map(c => Customer.byEmail(c.email).first() ?? Customer.create(c))"} +].map(c => Customer.byEmail(c.email).first() ?? Customer.create(c)) diff --git a/setup.sh b/setup.sh new file mode 100644 index 0000000..156a00a --- /dev/null +++ b/setup.sh @@ -0,0 +1,7 @@ +fauna query --input seed/categories.fql --secret "$FAUNA_SECRET" +echo -e "\n\n" +fauna query --input seed/customers.fql --secret "$FAUNA_SECRET" +echo -e "\n\n" +fauna query --input seed/products.fql --secret "$FAUNA_SECRET" +echo -e "\n\n" +fauna query --input seed/orders.fql --secret "$FAUNA_SECRET" From 5b38eccb8aa7a045c8471110fb20831eba11a852 Mon Sep 17 00:00:00 2001 From: James Rodewig Date: Mon, 16 Dec 2024 16:41:57 -0500 Subject: [PATCH 2/8] Use shorthand region group identifiers --- README.md | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 8d8518e..90e3141 100644 --- a/README.md +++ b/README.md @@ -95,21 +95,20 @@ To run the app, you'll need: 3. Use the CLI to create the `ECommerceJava` database: ```sh - # Replace 'us-std' with your preferred Region Group - # identifier: 'us-std' (United States), 'eu-std' (Europe), - # or `global`. + # Replace 'us' with your preferred Region Group: + # 'us' (United States), 'eu' (Europe), or `global`. fauna database create \ --name ECommerceJava \ - --database us-std + --database us ``` 4. Push the `.fsl` files in the `schema` directory to the `ECommerceJava` database: ```sh - # Replace 'us-std' with your Region Group identifier. + # Replace 'us' with your Region Group. fauna schema push \ - --database us-std/ECommerceJava \ + --database us/ECommerceJava \ --dir ./schema ``` @@ -119,14 +118,14 @@ To run the app, you'll need: ```sh fauna schema status \ - --database us-std/ECommerceJava + --database us/ECommerceJava ``` 6. When the status is `ready`, commit the staged schema to the database: ```sh fauna schema commit \ - --database us-std/ECommerceJava + --database us/ECommerceJava ``` The commit applies the staged schema to the database. The commit creates the @@ -137,7 +136,7 @@ To run the app, you'll need: ```sh fauna query "Key.create({ role: 'server' })" \ - --database us-std/ECommerceJava + --database us/ECommerceJava ``` Copy the returned `secret`. The app can use the key's secret to authenticate @@ -244,7 +243,7 @@ Customer documents and related API responses: ```sh fauna schema push \ - --database us-std/ECommerceJava \ + --database us/ECommerceJava \ --dir ./schema ``` @@ -253,7 +252,7 @@ Customer documents and related API responses: 4. Check the status of the staged schema: ```sh fauna schema status \ - --database us-std/ECommerceJava + --database us/ECommerceJava ``` 5. When the status is `ready`, commit the staged schema changes to the @@ -261,7 +260,7 @@ Customer documents and related API responses: ```sh fauna schema commit \ - --database us-std/ECommerceJava + --database us/ECommerceJava ``` 6. In `CustomersController.java`, add the From d18683c0093ab83fb485b7444b78821b85137a1f Mon Sep 17 00:00:00 2001 From: James Rodewig Date: Thu, 19 Dec 2024 18:10:25 -0500 Subject: [PATCH 3/8] Update link. Various improvements. --- README.md | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 90e3141..b80aff5 100644 --- a/README.md +++ b/README.md @@ -66,9 +66,9 @@ To run the app, you'll need: - A [Fauna account](https://dashboard.fauna.com/register). You can sign up for a free account at https://dashboard.fauna.com/register. -- Your preferred flavor of Java 17 +- Your preferred flavor of Java 17. -- [Fauna CLI](https://docs.fauna.com/fauna/current/tools/shell/) 4.0.0-beta or later. +- [Fauna CLI v4 beta](https://docs.fauna.com/fauna/current/build/cli/v4/) or later. - [Node.js](https://nodejs.org/en/download/) v20.x or later. To install the CLI, run: @@ -108,8 +108,7 @@ To run the app, you'll need: ```sh # Replace 'us' with your Region Group. fauna schema push \ - --database us/ECommerceJava \ - --dir ./schema + --database us/ECommerceJava ``` When prompted, accept and stage the schema. @@ -243,13 +242,13 @@ Customer documents and related API responses: ```sh fauna schema push \ - --database us/ECommerceJava \ - --dir ./schema + --database us/ECommerceJava ``` When prompted, accept and stage the schema. 4. Check the status of the staged schema: + ```sh fauna schema status \ --database us/ECommerceJava From b4d58cb1f76717e4691e78a8b169cf661e979e04 Mon Sep 17 00:00:00 2001 From: James Rodewig Date: Fri, 20 Dec 2024 09:20:13 -0500 Subject: [PATCH 4/8] Rename + move script --- .github/workflows/test.yml | 8 ++++---- README.md | 8 ++++---- {test => scripts}/http-client.env.json | 0 {test => scripts}/requests.http | 0 setup.sh => scripts/seed.sh | 0 {test => scripts}/setup.sh | 0 {test => scripts}/validate.sh | 0 7 files changed, 8 insertions(+), 8 deletions(-) rename {test => scripts}/http-client.env.json (100%) rename {test => scripts}/requests.http (100%) rename setup.sh => scripts/seed.sh (100%) rename {test => scripts}/setup.sh (100%) rename {test => scripts}/validate.sh (100%) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 64d1d25..5907451 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -22,13 +22,13 @@ jobs: distribution: corretto - name: Install fauna-shell run: - npm install -g fauna-shell + npm install -g fauna-shell@">=4.0.0-beta" - name: Setup Test Database - run: ./test/setup.sh + run: ./scripts/setup.sh - name: Test sample app run: | ./gradlew build FAUNA_ENDPOINT=http://localhost:8443 FAUNA_SECRET=`cat .fauna_key` ./gradlew bootRun > bootrun.log 2>&1 & - ./test/validate.sh - cat bootrun.log \ No newline at end of file + ./scripts/validate.sh + cat bootrun.log diff --git a/README.md b/README.md index b80aff5..6816ef6 100644 --- a/README.md +++ b/README.md @@ -143,12 +143,12 @@ To run the app, you'll need: ## Add sample data -The app includes a setup script that adds sample documents to the +The app includes a seed script that adds sample documents to the `ECommerceJava` database. From the root directory, run: ```sh -chmod +x setup.sh -FAUNA_SECRET= ./setup.sh +chmod +x ./scripts/seed.sh +FAUNA_SECRET= ./seed.sh ``` You can view documents created by the script in the [Fauna @@ -210,7 +210,7 @@ Customer documents and related API responses: 1. If you haven't already, add the sample data: ```sh - FAUNA_SECRET= ./setup.sh + FAUNA_SECRET= ./scripts/seed.sh ``` If the app server is running, stop the server by pressing Ctrl+C. diff --git a/test/http-client.env.json b/scripts/http-client.env.json similarity index 100% rename from test/http-client.env.json rename to scripts/http-client.env.json diff --git a/test/requests.http b/scripts/requests.http similarity index 100% rename from test/requests.http rename to scripts/requests.http diff --git a/setup.sh b/scripts/seed.sh similarity index 100% rename from setup.sh rename to scripts/seed.sh diff --git a/test/setup.sh b/scripts/setup.sh similarity index 100% rename from test/setup.sh rename to scripts/setup.sh diff --git a/test/validate.sh b/scripts/validate.sh similarity index 100% rename from test/validate.sh rename to scripts/validate.sh From 7bb7b0250b67d185aef44d3ee6918fc1cac8af46 Mon Sep 17 00:00:00 2001 From: James Rodewig Date: Fri, 20 Dec 2024 09:23:20 -0500 Subject: [PATCH 5/8] Update setup.sh --- scripts/setup.sh | 4 ++-- seed/categories.json | 14 -------------- seed/customers.json | 13 ------------- 3 files changed, 2 insertions(+), 29 deletions(-) delete mode 100644 seed/categories.json delete mode 100644 seed/customers.json diff --git a/scripts/setup.sh b/scripts/setup.sh index bfd81de..1a853b4 100755 --- a/scripts/setup.sh +++ b/scripts/setup.sh @@ -18,7 +18,7 @@ fauna eval "Key.create({ role: 'server' }).secret" | xargs > .fauna_key fauna schema push -y --active --dir=schema -fauna import --collection Category --path seed/categories.json -fauna import --collection Customer --path seed/customers.json +fauna eval --file seed/categories.fql +fauna eval --file seed/customers.fql fauna eval --file seed/products.fql fauna eval --file seed/orders.fql diff --git a/seed/categories.json b/seed/categories.json deleted file mode 100644 index 68c8183..0000000 --- a/seed/categories.json +++ /dev/null @@ -1,14 +0,0 @@ -[ - { - "name": "electronics", - "description": "bargain electronics" - }, - { - "name": "books", - "description": "bargain books" - }, - { - "name": "movies", - "description": "bargain movies" - } -] diff --git a/seed/customers.json b/seed/customers.json deleted file mode 100644 index 0c70300..0000000 --- a/seed/customers.json +++ /dev/null @@ -1,13 +0,0 @@ -[ - { - "name": "Valued Customer", - "email": "fake@fauna.com", - "address": { - "street": "Herengracht", - "city": "Amsterdam", - "state": "North Holland", - "postalCode": "1015BT", - "country": "Netherlands" - } - } -] From ce1e4c889aa904f4320c9d97b5f12ed5761afc49 Mon Sep 17 00:00:00 2001 From: James Rodewig Date: Fri, 20 Dec 2024 09:24:23 -0500 Subject: [PATCH 6/8] Fix test.yml --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 5907451..72c3577 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -22,7 +22,7 @@ jobs: distribution: corretto - name: Install fauna-shell run: - npm install -g fauna-shell@">=4.0.0-beta" + npm install -g fauna-shell - name: Setup Test Database run: ./scripts/setup.sh From e94f019edb5f67e217e7265f3a6c120bfc4fdd28 Mon Sep 17 00:00:00 2001 From: James Rodewig Date: Fri, 20 Dec 2024 09:36:20 -0500 Subject: [PATCH 7/8] Stray ref --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 6816ef6..69799d4 100644 --- a/README.md +++ b/README.md @@ -148,7 +148,7 @@ The app includes a seed script that adds sample documents to the ```sh chmod +x ./scripts/seed.sh -FAUNA_SECRET= ./seed.sh +FAUNA_SECRET= ./scripts/seed.sh ``` You can view documents created by the script in the [Fauna From f271285898aaba2c358e81f1b3328798e47997c2 Mon Sep 17 00:00:00 2001 From: James Rodewig Date: Fri, 20 Dec 2024 10:46:46 -0500 Subject: [PATCH 8/8] Update region group comment --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 69799d4..e67859e 100644 --- a/README.md +++ b/README.md @@ -96,7 +96,7 @@ To run the app, you'll need: ```sh # Replace 'us' with your preferred Region Group: - # 'us' (United States), 'eu' (Europe), or `global`. + # 'us' (United States), 'eu' (Europe), or `global` (available to Pro accounts and above). fauna database create \ --name ECommerceJava \ --database us