---
# System prepended metadata

title: Tenant based DB architecture

---

# Tenant based DB architecture

Scrpit : 
```
CREATE TABLE IF NOT EXISTS facl_sku_documents (
    document_id text, 
    data jsonb, 
    source_timestamp bigint, 
    modified_at timestamptz,
    source_updated_at timestamptz,
    position SERIAL,
    PRIMARY KEY(document_id)
    );

CREATE INDEX IF NOT EXISTS facl_position_idx ON facl_sku_documents (position);

```

## copy tenant specific data 
```
INSERT INTO facl_sku_documents 
SELECT s.document_id,s.data,s.source_timestamp,s.modified_at,s.source_updated_at 
FROM sku_documents AS s
WHERE s.tenant_id ='5f66269c-6d96-48fb-abe0-e91ae769c54c';
```