-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add db config docs and basic schema docs
- Loading branch information
Showing
3 changed files
with
58 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
``` |