Skip to content

Commit

Permalink
console: SyncEditor: Normalize Names option (toSameCase)
Browse files Browse the repository at this point in the history
  • Loading branch information
absorbb committed Aug 15, 2024
1 parent 0a06a11 commit c2bcb09
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 5 deletions.
41 changes: 36 additions & 5 deletions webapps/console/components/SyncEditorPage/SyncEditorPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ type SyncOptionsType = {
streams?: SelectedStreams;
namespace?: string;
tableNamePrefix?: string;
toSameCase?: boolean;
schedule?: string;
timezone?: string;
};
Expand Down Expand Up @@ -233,6 +234,10 @@ function SyncEditor({
: (syncOptions?.tableNamePrefix ?? "") + "${SOURCE_NAMESPACE}_"
: undefined;

const nameTransformer = syncOptions?.toSameCase
? (s: string) => (destinationType.id === "snowflake" ? s.toUpperCase() : s.toLowerCase())
: (s: string) => s;

const destinationNamespaces = (sourceNamespaces?.length > 0 ? sourceNamespaces : [""])
.map(ns => (syncOptions?.namespace ? syncOptions?.namespace.replaceAll("${SOURCE_NAMESPACE}", ns ?? "") : ""))
.map(ns => ns?.trim())
Expand Down Expand Up @@ -558,6 +563,32 @@ function SyncEditor({
),
}
: undefined,
destinationType.usesBulker && destinationType.id !== "s3" && destinationType.id !== "gcs"
? {
name: "Normalize Names",
documentation: (
<>
By default, Jitsu syncs table and column names exactly as they appear in the source. For instance, if a
source table is named <code>MyTableName</code>, Jitsu will create a table with the same case-sensitive
name. This means that when querying in SQL, you’ll need to use quotes, like so:{" "}
<code>select * from "MyTableName";</code>
<br />
<br />
However, if you enable tis option, Jitsu will automatically convert all table and column names to{" "}
<b>{`${destinationType.id === "snowflake" ? "UPPERCASE" : "lowercase"}`}</b>.
</>
),
component: (
<div className={"w-80"}>
<SwitchComponent
disabled={!!existingLink}
value={syncOptions?.toSameCase}
onChange={e => updateOptions({ toSameCase: e })}
/>
</div>
),
}
: undefined,
].filter(Boolean) as EditorItem[];
if (appConfig.syncs.scheduler.enabled) {
const disableScheduling =
Expand Down Expand Up @@ -777,12 +808,12 @@ function SyncEditor({
style={{ minWidth: "15rem" }}
disabled={!syncOptions?.streams?.[name]}
onChange={e => updateSelectedStream(name, "table_name", e.target.value)}
value={
value={nameTransformer(
syncOptions?.streams?.[name]?.table_name ||
(syncOptions?.tableNamePrefix
? syncOptions?.tableNamePrefix.replaceAll("${SOURCE_NAMESPACE}", stream.namespace ?? "")
: "") + tableName
}
(syncOptions?.tableNamePrefix
? syncOptions?.tableNamePrefix.replaceAll("${SOURCE_NAMESPACE}", stream.namespace ?? "")
: "") + tableName
)}
></Input>
</div>
<div className={"w-36"}></div>
Expand Down
1 change: 1 addition & 0 deletions webapps/console/lib/server/sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -616,6 +616,7 @@ export async function scheduleSync({
fullSync: fullSync ? "true" : "false",
startedBy: JSON.stringify(startedBy),
namespace: typeof sync.data?.["namespace"] !== "undefined" ? sync.data?.["namespace"] : "${LEGACY}",
toSameCase: sync.data?.["toSameCase"] ? "true" : "false",
tableNamePrefix: sync.data?.["tableNamePrefix"] ?? "",
},
body: {
Expand Down

0 comments on commit c2bcb09

Please sign in to comment.