Skip to content

Commit

Permalink
add db config docs and basic schema docs
Browse files Browse the repository at this point in the history
  • Loading branch information
jeromegn committed Aug 23, 2023
1 parent c5d1191 commit 99c4fab
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 2 deletions.
4 changes: 2 additions & 2 deletions doc/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
- [CRDTs](crdts.md)
- [Encryption]()
- [Gossip]()
- [Schema]()
- [Schema](schema.md)
- [Subscriptions]()
- [Synchronization]()
- [Templates]()
Expand All @@ -30,7 +30,7 @@
- [template]()
- [tls](cli/tls.md)
- [Configuration](config/README.md)
- [db]()
- [db](config/db.md)
- [gossip](config/gossip.md)
- [api]()
- [admin]()
Expand Down
27 changes: 27 additions & 0 deletions doc/config/db.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# The `[db]` configuration

The `[db]` block configures the Corrosion's SQLite database.

### Required fields

#### `db.path`

Path of the sqlite3 database.

```toml
[db]
path = "/var/lib/corrosion/db.sqlite"
```

### Optional fields

#### `db.schema_paths`

Array of paths where [schema]() .sql files are present.

```toml
[db]
schema_paths = ["/etc/corrosion/schema", "/path/to/table_name.sql"]
```

If a directory is specified, all .sql files will be loaded.
29 changes: 29 additions & 0 deletions doc/schema.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Schema

Corrosion's schema definition happens via files each representing one or more tables, written in SQL (SQLite-flavored). This is done through `CREATE TABLE` and `CREATE INDEX` exclusively!

Manual migrations are not supported (yet). When schema files change, Corrosion can be reloaded (or restarted) and it will compute a diff between the old and new schema and make the changes.

Any destructive actions on the table schemas are ignored / prohibited. This includes removing a table definition entirely or removing a column from a table. Indexes can be removed or added.

## Constraints

- Only `CREATE TABLE` and `CREATE INDEX` are allowed
- No unique indexes allowed (except for the default primary key unique index that does not need to be created)
- Non-nullable columns require a default value
- This is a cr-sqlite constraint, but in practice w/ Corrosion: it does not matter. Entire changes will be applied all at once and no fields will be missing.
- If table schemas are modified, then a default value is definitely required.

## Example

```sql
-- /etc/corrosion/schema/apps.sql

CREATE TABLE apps (
id INT PRIMARY KEY,
name TEXT NOT NULL DEFAULT "",
user_id INT NOT NULL DEFAULT 0,
);

CREATE INDEX apps_user_id ON apps (user_id);
```

0 comments on commit 99c4fab

Please sign in to comment.