You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Network functions may encounter specific errors during synchronization:
487
+
488
+
#### Device Limit Exceeded
489
+
490
+
If the device limit for your current plan on the cloud node is exceeded, network functions return error code `SQLITE_ERROR` (1) with the error message:
491
+
492
+
```
493
+
403 Device limit reached: You've already registered the maximum number of <n> devices allowed by your current plan.
494
+
```
495
+
496
+
**Resolution:** To resolve this error, you can:
497
+
-[Upgrade to a higher plan](https://www.sqlite.ai/pricing) to increase your device limit
498
+
- Remove unused devices from the OffSync section of your database in the [SQLite Cloud dashboard](https://dashboard.sqlitecloud.io/)
assigned_to TEXT-- Nullable for optional assignment
301
+
);
302
+
```
303
+
304
+
### UNIQUE Constraint Considerations
305
+
306
+
When converting from single-tenant to multi-tenant database schemas with Row-Level Security, **UNIQUE constraints must be globally unique** across all tenants in the cloud database. For columns that should only be unique within a tenant, use composite UNIQUE constraints.
307
+
308
+
```sql
309
+
-- ❌ Single-tenant: Unique email per database
310
+
CREATETABLEusers (
311
+
id TEXTPRIMARY KEY,
312
+
email TEXT UNIQUE NOT NULL-- Problem: Not unique across tenants
313
+
);
314
+
315
+
-- ✅ Multi-tenant: Composite unique constraint
316
+
CREATETABLEusers (
317
+
id TEXTPRIMARY KEY,
318
+
tenant_id TEXTNOT NULL,
319
+
email TEXTNOT NULL,
320
+
UNIQUE(tenant_id, email) -- Unique email per tenant
321
+
);
322
+
```
323
+
324
+
### Foreign Key Compatibility
325
+
326
+
When using foreign key constraints with SQLite Sync, be aware that interactions with the CRDT merge algorithm and Row-Level Security policies may cause constraint violations.
327
+
328
+
#### Potential Conflicts
329
+
330
+
**CRDT Merge Algorithm and DEFAULT Values**
331
+
332
+
- CRDT changes are applied column-by-column during synchronization
333
+
- Columns may be temporarily assigned DEFAULT values during the merge process
334
+
- If a foreign key column has a DEFAULT value, that value must exist in the referenced table
335
+
336
+
**Row-Level Security and CASCADE Actions**
337
+
- RLS policies may block operations required for maintaining referential integrity
338
+
- CASCADE DELETE/UPDATE operations may fail if RLS prevents access to related rows
339
+
340
+
#### Recommendations
341
+
342
+
**Database Design Patterns**
343
+
- Prefer application-level cascade logic over database-level CASCADE actions
344
+
- Design RLS policies to accommodate referential integrity operations
345
+
- Use nullable foreign keys where appropriate to avoid DEFAULT value issues
346
+
- Alternatively, ensure DEFAULT values for foreign key columns exist in their referenced tables
347
+
348
+
**Testing and Validation**
349
+
- Test synchronization scenarios with foreign key constraints enabled
350
+
- Monitor for constraint violations during sync operations in development
351
+
352
+
### Trigger Compatibility
353
+
354
+
Be aware that certain types of triggers can cause errors during synchronization due to SQLite Sync's merge logic.
355
+
356
+
**Duplicate Operations**
357
+
- If a trigger modifies a table that is also synchronized with SQLite Sync, changes performed by the trigger may be applied twice during the merge operation
358
+
- This can lead to constraint violations or unexpected data states depending on the table's constraints
359
+
360
+
**Column-by-Column Processing**
361
+
- SQLite Sync applies changes column-by-column during synchronization
362
+
- UPDATE triggers may be called multiple times for a single row as each column is processed
363
+
- This can result in unexpected trigger behavior
364
+
365
+
366
+
254
367
## License
255
368
256
369
This project is licensed under the [Elastic License 2.0](./LICENSE.md). You can use, copy, modify, and distribute it under the terms of the license for non-production use. For production or managed service use, please [contact SQLite Cloud, Inc](mailto:[email protected]) for a commercial license.
0 commit comments