# Build-In Postgres Database Adapter Schema

## Content

## Sql

```auto
CREATE TABLE IF NOT EXISTS documents (
    id TEXT PRIMARY KEY,
    type TEXT NOT NULL,
    version INT NOT NULL,
    snapshot_version INT NOT NULL
);

CREATE TABLE IF NOT EXISTS operations (
    doc_id TEXT NOT NULL,
    version INTEGER NOT NULL,
    operation TEXT NOT NULL,
    PRIMARY KEY (doc_id, version),
    FOREIGN KEY (doc_id) REFERENCES documents (id) ON DELETE CASCADE
);

CREATE TABLE IF NOT EXISTS snapshot_fragments (
    doc_id TEXT NOT NULL REFERENCES documents(id) ON DELETE CASCADE,
    fragment_id TEXT NOT NULL,
    data TEXT NOT NULL,
    PRIMARY KEY (doc_id, fragment_id)
);
```

## Schema

| **Table Name** | **Column Name** | **Data Type** | **Description** |
| ---------- | ----------- | --------- | ----------- |
| @rows=4:documents | id | TEXT | Unique identifier for the document |
| version | INTEGER | Version number of the document |
| snapshotVersion | INTEGER | Snapshot version number |
| type | TEXT | Type of the document |
| @rows=3:operations | doc\_id | TEXT | Unique identifier for the document |
| version | INTEGER | Version of the operation |
| operation | TEXT | Data related to the operation |
| @rows=3:fragments | doc\_id | TEXT | Unique identifier for the document |
| fragment\_id | TEXT | Unique identifier for the fragment |
| data | TEXT | Data related to the fragment |
