[go: nahoru, domu]

Skip to content

Commit

Permalink
Virtual foreign key docs (#2203)
Browse files Browse the repository at this point in the history
  • Loading branch information
alishakawaguchi committed Jun 25, 2024
1 parent 709bf5e commit 6221138
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 6 deletions.
38 changes: 38 additions & 0 deletions docs/docs/table-constraints/virtual-foreign-keys.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
---
title: Virtual Foreign Keys
description: Learn how to add virtual foreign keys in Neosync
id: virtual-foreign-keys
hide_title: false
slug: /table-constraints/virtual-foreign-keys
---

## Introduction

Neosync supports virtual foreign keys, which can be added using the Neosync app. Virtual foreign keys allow you to create relationships between tables that do not have explicit foreign key constraints in the database. This is particularly useful when dealing with legacy databases or when you need to create temporary relationships for data syncing purposes.

To add a virtual foreign key in Neosync, follow these steps:

**Navigate to the Schema Mapping Page:**

- Go to the Transformer Mapping page in the Neosync app where you define your data mappings. Click on the `Virtual Foreign Keys` tab.

**Define the Relationship:**

- Specify the source and target columns that you want to link with the virtual foreign key. Ensure that these columns logically relate to each other based on your data structure.

**Save the Virtual Foreign Key:**

- After defining the virtual foreign keys click update to save. The Neosync app will now treat these columns as if they had a real foreign key constraint, maintaining the integrity of your data during syncing operations.

:::info

1. When transforming the source (primary key) of a virtual foreign key the target (foreign key) must be set to passthrough.
2. The column datatypes must align for the source and target of virtual foreign keys
3. The source (primary key) column of a virtual foreign key must be non-nullable and unique.

:::

## Transforming & Subsetting Virtual Foreign Keys

Transforming and subsetting virtual foreign keys behave in the exact same way as foreign keys defined in a database.
Please refer to [Foreign Keys](foreign-keys.mdx) and [Subsetting](subsetting.mdx)
2 changes: 1 addition & 1 deletion docs/protos/mgmt/v1alpha1/connection_data.proto.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ _**package** mgmt.v1alpha1_


### `DatabaseColumn`
<ProtoMessage key={4} message={{"name":"DatabaseColumn","longName":"DatabaseColumn","fullName":"mgmt.v1alpha1.DatabaseColumn","description":"","hasExtensions":false,"hasFields":true,"hasOneofs":true,"extensions":[],"fields":[{"name":"schema","description":"The database schema. Ex: public","label":"","type":"string","longType":"string","fullType":"string","ismap":false,"isoneof":false,"oneofdecl":"","defaultValue":""},{"name":"table","description":"The name of the table in the schema","label":"","type":"string","longType":"string","fullType":"string","ismap":false,"isoneof":false,"oneofdecl":"","defaultValue":""},{"name":"column","description":"The name of the column","label":"","type":"string","longType":"string","fullType":"string","ismap":false,"isoneof":false,"oneofdecl":"","defaultValue":""},{"name":"data_type","description":"The datatype of the column","label":"","type":"string","longType":"string","fullType":"string","ismap":false,"isoneof":false,"oneofdecl":"","defaultValue":""},{"name":"is_nullable","description":"The isNullable Flag of the column","label":"","type":"string","longType":"string","fullType":"string","ismap":false,"isoneof":false,"oneofdecl":"","defaultValue":""},{"name":"column_default","description":"The default value of the column if available","label":"optional","type":"string","longType":"string","fullType":"string","ismap":false,"isoneof":true,"oneofdecl":"_column_default","defaultValue":""},{"name":"generated_type","description":"Populated if the column is generated. The value is the type of generated column it is. For example, postgres is 's' for stored\nMay be other values in the future, or other DB providers may use a different value types.","label":"optional","type":"string","longType":"string","fullType":"string","ismap":false,"isoneof":true,"oneofdecl":"_generated_type","defaultValue":""}]}} />
<ProtoMessage key={4} message={{"name":"DatabaseColumn","longName":"DatabaseColumn","fullName":"mgmt.v1alpha1.DatabaseColumn","description":"","hasExtensions":false,"hasFields":true,"hasOneofs":true,"extensions":[],"fields":[{"name":"schema","description":"The database schema. Ex: public","label":"","type":"string","longType":"string","fullType":"string","ismap":false,"isoneof":false,"oneofdecl":"","defaultValue":""},{"name":"table","description":"The name of the table in the schema","label":"","type":"string","longType":"string","fullType":"string","ismap":false,"isoneof":false,"oneofdecl":"","defaultValue":""},{"name":"column","description":"The name of the column","label":"","type":"string","longType":"string","fullType":"string","ismap":false,"isoneof":false,"oneofdecl":"","defaultValue":""},{"name":"data_type","description":"The datatype of the column","label":"","type":"string","longType":"string","fullType":"string","ismap":false,"isoneof":false,"oneofdecl":"","defaultValue":""},{"name":"is_nullable","description":"The isNullable Flag of the column","label":"","type":"string","longType":"string","fullType":"string","ismap":false,"isoneof":false,"oneofdecl":"","defaultValue":""},{"name":"column_default","description":"The default value of the column if available","label":"optional","type":"string","longType":"string","fullType":"string","ismap":false,"isoneof":true,"oneofdecl":"_column_default","defaultValue":""},{"name":"generated_type","description":"Populated if the column is generated. The value is the type of generated column it is. For example, postgres is 's' for stored\nMay be other values in the future, or other DB providers may use a different value types.","label":"optional","type":"string","longType":"string","fullType":"string","ismap":false,"isoneof":true,"oneofdecl":"_generated_type","defaultValue":""},{"name":"identity_generation","description":"Populated if the column is an identity. The value is the type of the identity column it is. For example, postgres is 'd' for generated by default, or 'a' for generated always.","label":"optional","type":"string","longType":"string","fullType":"string","ismap":false,"isoneof":true,"oneofdecl":"_identity_generation","defaultValue":""}]}} />


### `DatabaseTable`
Expand Down
Loading

0 comments on commit 6221138

Please sign in to comment.