- Multi-tenant ownership by
company_profiles. - Strong local-first SQLite behavior for desktop reliability.
- Cloud-sync-ready records using deterministic external IDs and sync metadata.
- Soft-delete support for conflict-safe replication.
idINTEGER PK (local surrogate key)external_idTEXT UNIQUE (cloud-safe identity)company_nameTEXT NOT NULLtax_registration_numberTEXT NULLowner_name,email,phone,addressTEXT NULLsync_statusTEXT NOT NULL DEFAULTlocal_onlysync_versionINTEGER NOT NULL DEFAULT1last_synced_atTEXT NULLdeleted_atTEXT NULLcreated_atTEXT NOT NULL DEFAULT CURRENT_TIMESTAMP
idINTEGER PKexternal_idTEXT UNIQUEcompany_idINTEGER (tenant owner)name,skuTEXT NOT NULLstock_qtyINTEGER NOT NULLpriceREAL NOT NULLsync_status,sync_version,last_synced_at,deleted_at,created_at
idINTEGER PKexternal_idTEXT UNIQUEcompany_idINTEGER (tenant owner)nameTEXT NOT NULLtax_registration_numberTEXT NULL (buyer tax registration)phone,addressTEXT NULLsync_status,sync_version,last_synced_at,deleted_at,created_at
idINTEGER PKexternal_idTEXT UNIQUEdc_numberTEXT UNIQUEcompany_idINTEGER (issuer company)customer_idINTEGER NOT NULL (buyer)sync_status,sync_version,last_synced_at,deleted_at,created_at
idINTEGER PKexternal_idTEXT UNIQUEdc_idINTEGER NOT NULLproduct_idINTEGER NOT NULLquantityINTEGER NOT NULLrateREAL NOT NULLsync_status,sync_version,last_synced_at,deleted_at,created_at
- Every business row is scoped to one
company_id. - Delivery challan creation validates that
customer_idand allproduct_ids belong to the same company. - Stock deduction happens only in that company scope and inside one transaction.
- Use
external_idas canonical cross-database ID. - Keep local
idfor SQLite performance and FK ergonomics. - Sync engine can map:
- SQLite
external_id<-> Mongo_id(or separate uniqueexternalId) - SQLite
sync_versionfor optimistic conflict checks deleted_atfor tombstone replication
- SQLite
- Add
(company_id, sku)unique index migration for per-tenant SKU uniqueness. - Add audit fields (
created_by_user_id,updated_by_user_id) once auth/users module is introduced. - Add outbox table (
sync_outbox) for resilient push-to-cloud sync retries.