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

FE-6254 Setting schema on 'fauna local --database Foo' #533

Merged
merged 13 commits into from
Dec 17, 2024
Merged

Conversation

cleve-fauna
Copy link
Contributor

@cleve-fauna cleve-fauna commented Dec 16, 2024

Problem

When using fauna local, it's likely you'll want to spin up a database and commit the current schema if the disks are ephemeral. We already let you create a fresh db when using fauna local. We should allow you to push FSL at this time too.

Solution

Add the flags required to push schema to the database being created when running fauna local with one major changes: --active is true by default in fauna local.

This change in behavior compared to fauna schema push is required to enable a seamless "one command" way to run fauna locally against a local database. Otherwise, you'd run fauna local and it would do everything other than commit the db changes.

Given the interactive prompt is still turned on, some protections are in place in case this isn't something someone wants to do.

Result

Too big for a screenshot:

➜  ~  fauna local --database demo --dir /tmp/fsl  
[PullImage] Pulling image 'fauna/faunadb:latest'...
latest: Pulling from fauna/faunadb 
[PullImage] Image 'fauna/faunadb:latest' pulled.
[FindContainer] Looking for container 'faunadb'...
[StartContainer] Starting container 'faunadb'...
[StartContainer] Container 'faunadb' started. Monitoring HealthCheck for readiness.
[HealthCheck] Waiting for Fauna to be ready at http://0.0.0.0:8443...
[HealthCheck] Fauna is not yet ready. Attempt 1/100 failed with error: fetch failed. Retrying in 10 seconds...
<..snip>
[CreateDatabase] Database 'demo' created.
{
  name: "demo",
  coll: Database,
  ts: Time("2024-12-17T00:02:14.990Z"),
  global_id: "yzf1sy7n1ybyy"
}
[CreateDatabaseSchema] Creating schema for database 'demo' from directory '/tmp/fsl'...
Proposed diff:

* Adding collection `Category` to collections.fsl:55:1:
  * Computed fields:
  + add computed field `products`

  * Indexes:
  + add index `byName`

  * Constraints:
  + add unique constraint on [.name]

* Adding collection `Customer` to collections.fsl:2:1:
  * Computed fields:
  + add computed field `cart`
  + add computed field `orders`

  * Indexes:
  + add index `byEmail`

  * Constraints:
  + add unique constraint on [.email]

* Adding collection `Order` to collections.fsl:67:1:
  * Computed fields:
  + add computed field `items`
  + add computed field `total`

  * Indexes:
  + add index `byCustomer`
  + add index `byCustomerAndStatus`

  * Constraints:
  + add check constraint `oneOrderInCart`

* Adding collection `OrderItem` to collections.fsl:99:1:
  * Indexes:
  + add index `byOrder`
  + add index `byOrderAndProduct`

  * Constraints:
  + add unique constraint on [.order, .product]
  + add check constraint `positiveQuantity`

* Adding collection `Product` to collections.fsl:26:1:
  * Indexes:
  + add index `byCategory`
  + add index `sortedByCategory`
  + add index `byName`
  + add index `sortedByPriceLowToHigh`

  * Constraints:
  + add unique constraint on [.name]
  + add check constraint `stockIsValid`
  + add check constraint `priceIsValid`

* Adding function `checkout` to functions.fsl:70:1

* Adding function `createOrUpdateCartItem` to functions.fsl:2:1

* Adding function `getOrCreateCart` to functions.fsl:51:1

* Adding function `validateOrderStatusTransition` to functions.fsl:120:1

* Adding role `test` to main.fsl:4:1

✔ Push the above changes? yes

[CreateDatabaseSchema] Schema for database 'demo' created from directory '/tmp/fsl'.

## Testing

Functional tests cover the `--active` and `--no-active` conditions.

@cleve-fauna cleve-fauna changed the title FE-6254 Boilerplate for setting schema on 'fauna local --database Foo' FE-6254 Setting schema on 'fauna local --database Foo' Dec 16, 2024
@ecooper ecooper marked this pull request as ready for review December 17, 2024 00:07
@ecooper ecooper requested a review from a team as a code owner December 17, 2024 00:07
@ecooper ecooper requested review from echo-bravo-yahoo, henryfauna, mryan-fauna and jrodewig and removed request for mryan-fauna December 17, 2024 00:08
@mwilde345 mwilde345 merged commit feca576 into v3 Dec 17, 2024
4 checks passed
@mwilde345 mwilde345 deleted the v3_schemaLocal branch December 17, 2024 04:42
@mwilde345 mwilde345 mentioned this pull request Dec 18, 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

Successfully merging this pull request may close these issues.

5 participants