Skip to content

Commit

Permalink
Heirarchical UI For CDC Table Picker And Refactoring (#700)
Browse files Browse the repository at this point in the history
- Redesigns the table picking section of Create CDC Mirror to have a
heirarchical view of Schema -> Table -> Columns
- Wired up with column exclusion and column exclusion tested from PG ->
SF
- Refactors code and organises files into CDC and QRep folders
<img width="1097" alt="Screenshot 2023-11-23 at 9 54 22 AM"
src="https://github.com/PeerDB-io/peerdb/assets/65964360/5a45412b-344c-4e0c-a18b-af905e3eb3e7">
  • Loading branch information
Amogh-Bharadwaj authored Nov 23, 2023
1 parent 7e84b31 commit 4b1447b
Show file tree
Hide file tree
Showing 15 changed files with 728 additions and 775 deletions.
42 changes: 37 additions & 5 deletions flow/cmd/peer_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,40 @@ func (h *FlowRequestHandler) GetColumns(
}

defer peerPool.Close()
rows, err := peerPool.Query(ctx, "SELECT column_name, data_type"+
" FROM information_schema.columns"+
" WHERE table_schema = $1 AND table_name = $2;", req.SchemaName, req.TableName)
rows, err := peerPool.Query(ctx, `
SELECT
cols.column_name,
cols.data_type,
CASE
WHEN constraint_type = 'PRIMARY KEY' THEN true
ELSE false
END AS is_primary_key
FROM
information_schema.columns cols
LEFT JOIN
(
SELECT
kcu.column_name,
tc.constraint_type
FROM
information_schema.key_column_usage kcu
JOIN
information_schema.table_constraints tc
ON
kcu.constraint_name = tc.constraint_name
AND kcu.constraint_schema = tc.constraint_schema
AND kcu.constraint_name = tc.constraint_name
WHERE
tc.constraint_type = 'PRIMARY KEY'
AND kcu.table_schema = $1
AND kcu.table_name = $2
) AS pk
ON
cols.column_name = pk.column_name
WHERE
cols.table_schema = $3
AND cols.table_name = $4;
`, req.SchemaName, req.TableName, req.SchemaName, req.TableName)
if err != nil {
return &protos.TableColumnsResponse{Columns: nil}, err
}
Expand All @@ -147,11 +178,12 @@ func (h *FlowRequestHandler) GetColumns(
for rows.Next() {
var columnName string
var datatype string
err := rows.Scan(&columnName, &datatype)
var isPkey bool
err := rows.Scan(&columnName, &datatype, &isPkey)
if err != nil {
return &protos.TableColumnsResponse{Columns: nil}, err
}
column := fmt.Sprintf("%s:%s", columnName, datatype)
column := fmt.Sprintf("%s:%s:%v", columnName, datatype, isPkey)
columns = append(columns, column)
}
return &protos.TableColumnsResponse{Columns: columns}, nil
Expand Down
1 change: 1 addition & 0 deletions ui/app/dto/MirrorsDTO.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export type CDCConfig = FlowConnectionConfigs;
export type MirrorConfig = CDCConfig | QRepConfig;
export type MirrorSetter = Dispatch<SetStateAction<CDCConfig | QRepConfig>>;
export type TableMapRow = {
schema: string;
source: string;
destination: string;
partitionKey: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import { Switch } from '@/lib/Switch';
import { TextField } from '@/lib/TextField';
import { Dispatch, SetStateAction } from 'react';
import ReactSelect from 'react-select';
import { InfoPopover } from '../../../components/InfoPopover';
import { CDCConfig, MirrorSetter, TableMapRow } from '../../dto/MirrorsDTO';
import { MirrorSetting } from './helpers/common';
import { InfoPopover } from '../../../../components/InfoPopover';
import { CDCConfig, MirrorSetter, TableMapRow } from '../../../dto/MirrorsDTO';
import { MirrorSetting } from '../helpers/common';
import TableMapping from './tablemapping';

interface MirrorConfigProps {
Expand All @@ -19,8 +19,6 @@ interface MirrorConfigProps {
setter: MirrorSetter;
rows: TableMapRow[];
setRows: Dispatch<SetStateAction<TableMapRow[]>>;
schema: string;
setSchema: Dispatch<SetStateAction<string>>;
}

const SyncModeOptions = ['AVRO', 'Copy with Binary'].map((value) => ({
Expand All @@ -46,8 +44,6 @@ export default function CDCConfigForm({
setter,
rows,
setRows,
schema,
setSchema,
}: MirrorConfigProps) {
const setToDefault = (setting: MirrorSetting) => {
const destinationPeerType = mirrorConfig.destination?.type;
Expand Down Expand Up @@ -81,15 +77,13 @@ export default function CDCConfigForm({
return true;
};

if (mirrorConfig.source != undefined)
if (mirrorConfig.source != undefined && mirrorConfig.destination != undefined)
return (
<>
<TableMapping
sourcePeerName={mirrorConfig.source?.name}
rows={rows}
setRows={setRows}
setSchema={setSchema}
schema={schema}
peerType={mirrorConfig.destination?.type}
/>
{settings.map((setting, id) => {
Expand Down
Loading

0 comments on commit 4b1447b

Please sign in to comment.