Skip to content

Commit

Permalink
cli: Initialize schema by default in dev
Browse files Browse the repository at this point in the history
  • Loading branch information
matlin authored and pbohlman committed May 17, 2024
1 parent a7465dd commit 7672ecb
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 9 deletions.
5 changes: 5 additions & 0 deletions .changeset/friendly-glasses-run.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@triplit/cli': patch
---

The dev command will now initialize the dev server with a schema (--initWithSchema) by default
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export const schema = {
Start the Triplit development [sync server](https://www.triplit.dev/docs/syncing-data).

```bash
npm run triplit dev --initWithSchema
npm run triplit dev
```

This will output some important [environmental variables](https://www.triplit.dev/docs/local-development#additional-environment-variables) that your app will need to sync with the server. Add them to your `.env` file (Vite example below).
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/commands/dev.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export default Command({
initWithSchema: Flag.Boolean({
char: 'i',
description: 'Initialize the database with the local schema',
default: false,
default: true,
}),
seed: Flag.String({
char: 'S',
Expand Down
1 change: 1 addition & 0 deletions packages/docs/src/pages/cli/dev.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ Flags:
--dbPort, -d Port to run the database server on
--verbose, -v Verbose logging
--initWithSchema, -i Initialize the database with the local schema
default: true
--seed, -S Seed the database with data
```
4 changes: 2 additions & 2 deletions packages/docs/src/pages/getting-started.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -228,10 +228,10 @@ So far we've covered how to set up a local database and query it. Triplit provid
Triplit has a robust local development environment that you can set up with a single command.

```bash
triplit dev --initWithSchema
triplit dev
```

This will start a local development server that you can use to test syncing. The `--initWithSchema` flag will ensure the development server loads the schema defined at `./triplit/schema.ts`.
This will start a local development server that you can use to test syncing. The development server will automatically load the schema defined at `./triplit/schema.ts`.

The default URL for the local development server is `http://localhost:6543`. It will also generate a Service Token and an Anonymous Token that your client app can use to authorize with the server.

Expand Down
10 changes: 5 additions & 5 deletions packages/docs/src/pages/schema-management.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ export const schema = {
} satisfies ClientSchema;
```

You can start the development server with the schema pre-loaded with the `--initWithSchema` or `-i` option.
You can start the development server with the schema pre-loaded.

```bash copy
triplit dev --initWithSchema
triplit dev
```

By default, the server will use in-memory storage, meaning that if you shut down the server, all of your data will be lost. This can be useful when you're early in development and frequently iterating on your schema. If you like this quick feedback loop but don't want to repeatedly re-insert test data by hand, you can use Triplit's [`seed` commands](/seeding). You can use seed command on its own:
Expand All @@ -47,20 +47,20 @@ triplit seed run my-seed
Or use the `--seed` flag with `triplit dev`:

```bash copy
triplit dev --initWithSchema --seed=my-seed
triplit dev --seed=my-seed
```

If you want a development environment that's more constrained and closer to production, consider using the [SQLite](https://www.sqlite.org/) persistent storage option for the development server:

```bash copy
triplit dev --initWithSchema --storage=sqlite
triplit dev --storage=sqlite
```

Your database will be saved to `triplit/.data`. You can delete this folder to clear your database.

## Updating your schema

Let's assume you've run some version of `triplit dev --initWithSchema` shown above and have a server up and running with a schema. You've also [properly configured your `.env`](/getting-started#syncing-in-local-development) such that Triplit CLI commands will be pointing at it. Let's also assume you've added some initial todos:
Let's assume you've run some version of `triplit dev` shown above and have a server up and running with a schema. You've also [properly configured your `.env`](/getting-started#syncing-in-local-development) such that Triplit CLI commands will be pointing at it. Let's also assume you've added some initial todos:

```ts copy filename="App.tsx"
import { TriplitClient } from '@triplit/client';
Expand Down

0 comments on commit 7672ecb

Please sign in to comment.