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

Update README for CLI v4 beta #26

Merged
merged 8 commits into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 33 additions & 51 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,21 +66,17 @@ 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/) v3.0.0 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:

```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:
Expand All @@ -90,75 +86,56 @@ 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' with your preferred Region Group:
# 'us' (United States), 'eu' (Europe), or `global`.
fauna database create \
--name ECommerceJava \
--database us
```

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' with your Region Group.
fauna schema push \
--database us/ECommerceJava
```

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/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/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/ECommerceJava
```

Copy the returned `secret`. The app can use the key's secret to authenticate
Expand All @@ -170,6 +147,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=<secret> ./setup.sh
```

Expand Down Expand Up @@ -263,21 +241,25 @@ Customer documents and related API responses:
database to stage the changes:

```sh
fauna schema push
fauna schema push \
--database us/ECommerceJava
```

When prompted, accept and stage the schema.

4. Check the status of the staged schema:

```sh
fauna schema status
fauna schema status \
--database us/ECommerceJava
```

5. When the status is `ready`, commit the staged schema changes to the
database:

```sh
fauna schema commit
fauna schema commit \
--database us/ECommerceJava
```

6. In `CustomersController.java`, add the
Expand Down
4 changes: 2 additions & 2 deletions seed/categories.fql
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{"query": "[
[
{
'name': 'electronics'
},
Expand All @@ -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}!" }))
4 changes: 2 additions & 2 deletions seed/customers.fql
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{"query":"[
[
{
id: '999',
name: 'Valued Customer',
Expand All @@ -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))
7 changes: 7 additions & 0 deletions setup.sh
Original file line number Diff line number Diff line change
@@ -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"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You probably didn't see it, but I put a new file test/setup.sh that somewhat duplicates this file, I think we need to rename that file, or this file. Maybe we could rename this one seed.sh and put this script along with setup.sh and validate.sh in a directory called scripts?

Copy link
Contributor Author

@jrodewig jrodewig Dec 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I did the following:

  • Renamed this file to seed.sh and placed it in /scripts.
  • Moved /test/* files over to /scripts.
  • Updated references in test.yml
  • Deleted some redundant data in /seed/*.json files.

There's some additional work needed to update test.yml to the CLI v4 beta. Once that's done, we can just call seed.sh from setup.sh. However, that's a bit beyond the scope of this PR. I can tackle that in a separate PR if wanted.

Feel free to push changes to this PR/branch. Appreciate you taking a look!

Loading