Skip to content

Commit f457a33

Browse files
committed
docs: update sqlite sync docs
1 parent 8612ed4 commit f457a33

34 files changed

+1699
-23
lines changed

.github/workflows/aisearch.yaml

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,24 @@ name: Process docs for SQLite AI Search
22

33
on:
44
workflow_dispatch:
5-
5+
push:
6+
branches:
7+
- main
8+
- stage
9+
610
jobs:
7-
docsearch:
11+
aisearch:
812
runs-on: ubuntu-latest
913
environment: ${{ github.ref_name }}
14+
permissions:
15+
contents: read
1016

1117
steps:
1218
- uses: actions/checkout@v4
13-
14-
# - uses: sqlitecloud/sqlite-ai-action@v1
15-
# with:
16-
# project-string: ${{ secrets.PROJECT_STRING }}
17-
# base-url: ${{ vars.BASE_URL }}
18-
# database: documentation_ai.sqlite
19+
20+
- uses: sqliteai/sqlite-aisearch-action@v1
21+
with:
22+
connection_string: ${{ secrets.PROJECT_STRING }}
23+
base_url: ${{ vars.BASE_URL }}
24+
database_name: documentation_ai.sqlite
25+
source_files: ./

sqlite-cloud/sqlite-ai/sqlite-sync.mdx

Lines changed: 0 additions & 15 deletions
This file was deleted.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
### `cloudsync_begin_alter(table_name)`
2+
3+
**Description:** Prepares a synchronized table for schema changes. This function must be called before altering the table. Failure to use `cloudsync_begin_alter` and `cloudsync_commit_alter` can lead to synchronization errors and data divergence.
4+
5+
**Parameters:**
6+
7+
- `table_name` (TEXT): The name of the table that will be altered.
8+
9+
**Returns:** None.
10+
11+
**Example:**
12+
13+
```sql
14+
SELECT cloudsync_init('my_table');
15+
-- ... later
16+
SELECT cloudsync_begin_alter('my_table');
17+
ALTER TABLE my_table ADD COLUMN new_column TEXT;
18+
SELECT cloudsync_commit_alter('my_table');
19+
```
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
### `cloudsync_cleanup(table_name)`
2+
3+
**Description:** Removes the `sqlite-sync` synchronization mechanism from a specified table or all tables. This operation drops the associated `_cloudsync` metadata table and removes triggers from the target table(s). Use this function when synchronization is no longer desired for a table.
4+
5+
**Parameters:**
6+
7+
- `table_name` (TEXT): The name of the table to clean up.
8+
9+
**Returns:** None.
10+
11+
**Example:**
12+
13+
```sql
14+
-- Clean up a single table
15+
SELECT cloudsync_cleanup('my_table');
16+
17+
```
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
### `cloudsync_commit_alter(table_name)`
2+
3+
**Description:** Finalizes schema changes for a synchronized table. This function must be called after altering the table's schema, completing the process initiated by `cloudsync_begin_alter` and ensuring CRDT data consistency.
4+
5+
**Parameters:**
6+
7+
- `table_name` (TEXT): The name of the table that was altered.
8+
9+
**Returns:** None.
10+
11+
**Example:**
12+
13+
```sql
14+
SELECT cloudsync_init('my_table');
15+
-- ... later
16+
SELECT cloudsync_begin_alter('my_type');
17+
ALTER TABLE my_table ADD COLUMN new_column TEXT;
18+
SELECT cloudsync_commit_alter('my_table');
19+
```
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
### `cloudsync_db_version()`
2+
3+
**Description:** Returns the current database version.
4+
5+
**Parameters:** None.
6+
7+
**Returns:** The database version as an INTEGER.
8+
9+
**Example:**
10+
11+
```sql
12+
SELECT cloudsync_db_version();
13+
```
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
### `cloudsync_disable(table_name)`
2+
3+
**Description:** Disables synchronization for the specified table.
4+
5+
**Parameters:**
6+
7+
- `table_name` (TEXT): The name of the table to disable.
8+
9+
**Returns:** None.
10+
11+
**Example:**
12+
13+
```sql
14+
SELECT cloudsync_disable('my_table');
15+
```
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
### `cloudsync_enable(table_name)`
2+
3+
**Description:** Enables synchronization for the specified table.
4+
5+
**Parameters:**
6+
7+
- `table_name` (TEXT): The name of the table to enable.
8+
9+
**Returns:** None.
10+
11+
**Example:**
12+
13+
```sql
14+
SELECT cloudsync_enable('my_table');
15+
```
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
### `cloudsync_init(table_name, [crdt_algo], [force])`
2+
3+
**Description:** Initializes a table for `sqlite-sync` synchronization. This function is idempotent and needs to be called only once per table on each site; configurations are stored in the database and automatically loaded with the extension.
4+
5+
Before initialization, `cloudsync_init` performs schema sanity checks to ensure compatibility with CRDT requirements and best practices. These checks include:
6+
7+
- Primary keys should not be auto-incrementing integers; GUIDs (UUIDs, ULIDs) are highly recommended to prevent multi-node collisions.
8+
- All primary key columns must be `NOT NULL`.
9+
- All non-primary key `NOT NULL` columns must have a `DEFAULT` value.
10+
11+
**Schema Design Considerations:**
12+
13+
When designing your database schema for SQLite Sync, follow these essential requirements:
14+
15+
- **Primary Keys**: Use TEXT primary keys with `cloudsync_uuid()` for globally unique identifiers. Avoid auto-incrementing integers.
16+
- **Column Constraints**: All NOT NULL columns (except primary keys) must have DEFAULT values to prevent synchronization errors.
17+
- **UNIQUE Constraints**: In multi-tenant scenarios, use composite UNIQUE constraints (e.g., `UNIQUE(tenant_id, email)`) instead of global uniqueness.
18+
- **Foreign Key Compatibility**: Be aware of potential conflicts during CRDT merge operations and RLS policy interactions.
19+
- **Trigger Compatibility**: Triggers may cause duplicate operations or be called multiple times due to column-by-column processing.
20+
21+
For comprehensive guidelines, see the [Database Schema Recommendations](https://github.com/sqliteai/sqlite-sync/blob/main/README.md#database-schema-recommendations) section.
22+
23+
The function supports three overloads:
24+
25+
- `cloudsync_init(table_name)`: Uses the default 'cls' CRDT algorithm.
26+
- `cloudsync_init(table_name, crdt_algo)`: Specifies a CRDT algorithm ('cls', 'dws', 'aws', 'gos').
27+
- `cloudsync_init(table_name, crdt_algo, force)`: Specifies an algorithm and, if `force` is `true` (or `1`), skips the integer primary key check (use with caution, GUIDs are strongly recommended).
28+
29+
**Parameters:**
30+
31+
- `table_name` (TEXT): The name of the table to initialize.
32+
- `crdt_algo` (TEXT, optional): The CRDT algorithm to use. Can be "cls", "dws", "aws", "gos". Defaults to "cls".
33+
- `force` (BOOLEAN, optional): If `true` (or `1`), it skips the check that prevents the use of a single-column INTEGER primary key. Defaults to `false`. It is strongly recommended to use globally unique primary keys instead of integers.
34+
35+
**Returns:** None.
36+
37+
**Example:**
38+
39+
```sql
40+
-- Initialize a single table for synchronization with the Causal-Length Set (CLS) Algorithm (default)
41+
SELECT cloudsync_init('my_table');
42+
43+
-- Initialize a single table for synchronization with a different algorithm Delete-Wins Set (DWS)
44+
SELECT cloudsync_init('my_table', 'dws');
45+
46+
```
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
### `cloudsync_is_enabled(table_name)`
2+
3+
**Description:** Checks if synchronization is enabled for the specified table.
4+
5+
**Parameters:**
6+
7+
- `table_name` (TEXT): The name of the table to check.
8+
9+
**Returns:** 1 if enabled, 0 otherwise.
10+
11+
**Example:**
12+
13+
```sql
14+
SELECT cloudsync_is_enabled('my_table');
15+
```

0 commit comments

Comments
 (0)