---
title: "Simple Table Migration"
description: "Minimal setup to replicate a single SQL table into a RavenDB collection using CDC Sink."
url: "https://docs.ravendb.net/7.2/server/ongoing-tasks/cdc-sink/examples/example-simple-migration"
version: "7.2"
language: "csharp"
---

# Simple Table Migration

> Client language: C#.
>
> RavenDB publishes an official agent skill for coding assistants at https://docs.ravendb.net/skills/ravendb/SKILL.md (also installable with `npx skills add ravendb/skills`). The skill describes itself as: "Read this before writing any RavenDB query, client call or /databases/ request. Covers server setup, document modelling, the Node.js, .NET and Python clients, RQL, indexes, vector search and AI agents. Code written from recall tends to run and return the wrong rows, because RQL resembles SQL and the clients take field names as plain strings."

> **Note**
>
> - This example shows the basic CDC Sink configuration to migrate a single SQL table into a RavenDB collection.
>
> - For detailed instructions on creating a CDC Sink task with the Client API or Studio,  
>   see [Create a CDC Sink task](https://docs.ravendb.net/7.2/server/ongoing-tasks/cdc-sink/manage-cdc-sink-tasks/create-task.md).
>
> - In this article:
>   - [Source schema](#source-schema)
>   - [Task configuration](#task-configuration)
>     - [Via the Client API](#via-the-client-api)
>     - [Via Studio](#via-studio)
>   - [Resulting documents](#resulting-documents)

## Source schema {#source-schema}

A simple customers table:

```sql
CREATE TABLE customers (
    id         SERIAL PRIMARY KEY,
    name       TEXT NOT NULL,
    email      TEXT NOT NULL,
    created_at TIMESTAMPTZ DEFAULT now()
);
```

## Task configuration {#task-configuration}

### Via the Client API

Define the task with the client API:

```csharp
var config = new CdcSinkConfiguration
{
    Name = "Customers-CDC-Sink",
    ConnectionStringName = "ConnectionStringToPostgreSQL",
    Tables = new List<CdcSinkTableConfig>
    {
        new CdcSinkTableConfig
        {
            CollectionName = "Customers",
            SourceTableSchema = "public",
            SourceTableName = "customers",
            PrimaryKeyColumns = new List<string> { "id" },
            // Column = source SQL column, Name = RavenDB document property
            Columns =
            [
                new CdcColumnMapping() { Column = "id",         Name = "Id" },
                new CdcColumnMapping() { Column = "name",       Name = "Name" },
                new CdcColumnMapping() { Column = "email",      Name = "Email" },
                new CdcColumnMapping() { Column = "created_at", Name = "CreatedAt" },
            ]
        }
    }
};

await store.Maintenance.SendAsync(new AddCdcSinkOperation(config));
```

---

### Via Studio

In Studio, configure how the selected `customers` source table maps to the `Customers` target collection:  
set the source schema/table, primary key column, and field mapping (source column → target property).

![Configure the customers table](https://docs.ravendb.net/assets/images/example-simple-migration-1-85788f96b8b107f3df95bd9ab3af734d.png)

---

Alternatively, toggle **Raw config** and paste the equivalent JSON:

![Use raw config](https://docs.ravendb.net/assets/images/example-simple-migration-2-96ce2bb95714ac804017fb3f59ea2bee.png)

```json
{
    "Name": "Customers-CDC-Sink",
    "ConnectionStringName": "ConnectionStringToPostgreSQL",
    "Tables": [
        {
            "CollectionName": "Customers",
            "SourceTableSchema": "public",
            "SourceTableName": "customers",
            "PrimaryKeyColumns": ["id"],
            "Columns": [
                { "Column": "id",         "Name": "Id" },
                { "Column": "name",       "Name": "Name" },
                { "Column": "email",      "Name": "Email" },
                { "Column": "created_at", "Name": "CreatedAt" }
            ]
        }
    ]
}
```

## Resulting documents {#resulting-documents}

Given this SQL row:

```text
id=1, name='Alice', email='alice@example.com', created_at='2024-01-15 10:30:00+00'
```

CDC Sink generates the document ID from `CollectionName` and the configured primary key column value.  
Here, `CollectionName = "Customers"` and `PrimaryKeyColumns = ["id"]`, so the document ID is `Customers/1`.

The `id` column must also be mapped in `Columns`; otherwise, the task configuration is rejected.  
In this example, it is mapped to the `Id` document property.

The resulting RavenDB document:

```json
{
    "Id": 1,
    "Name": "Alice",
    "Email": "alice@example.com",
    "CreatedAt": "2024-01-15T10:30:00+00:00",
    "@metadata": {
        "@collection": "Customers"
    }
}
```

## See also

- [Denormalization](https://docs.ravendb.net/7.2/server/ongoing-tasks/cdc-sink/examples/example-denormalization.md)
- [Event Sourcing](https://docs.ravendb.net/7.2/server/ongoing-tasks/cdc-sink/examples/example-running-balance.md)
- [Complex Nesting](https://docs.ravendb.net/7.2/server/ongoing-tasks/cdc-sink/examples/example-complex-nesting.md)
- [Schema Design](https://docs.ravendb.net/7.2/server/ongoing-tasks/cdc-sink/document-modeling/schema-design.md)
- [Column Mapping](https://docs.ravendb.net/7.2/server/ongoing-tasks/cdc-sink/document-modeling/column-mapping.md)
