Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
103 changes: 103 additions & 0 deletions packages/web-ui/src/api/contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,93 @@ export interface DatabaseImportRequest extends ConnectionIdRequest {
uploadToken?: string;
}

export type TableTransferConflictMode = 'fail' | 'skip';

export interface TableTransferColumnMapping {
sourceColumn: string;
/** `null` skips the source column explicitly. */
targetColumn: string | null;
}

export interface TableTransferSelection {
sourceTable: string;
targetTable: string;
/** Omitted columns are matched to the target by name. */
columns?: TableTransferColumnMapping[];
}

export interface TableTransferRequest {
sourceConnectionId: string;
sourceDatabase?: string;
sourceSchema?: string;
targetConnectionId: string;
targetDatabase?: string;
targetSchema?: string;
tables: TableTransferSelection[];
conflict?: TableTransferConflictMode;
batchRows?: number;
/** Required to run; identifies the job for progress events and cancellation. */
transferId?: string;
}

export interface TableTransferCapabilities {
pairs: Array<{source: string; target: string}>;
writeModes: string[];
conflictModes: TableTransferConflictMode[];
maxBatchRows: number;
defaultBatchRows: number;
}

export interface TableTransferIssue {
code: string;
column?: string;
}

export interface TableTransferColumnPlan {
sourceColumn: string;
sourceType: string;
targetColumn: string | null;
targetType: string | null;
rule: 'exact' | 'checked' | null;
skipped: boolean;
issue: string | null;
}

export interface TableTransferTablePlan {
sourceTable: string;
targetTable: string;
columns: TableTransferColumnPlan[];
issues: TableTransferIssue[];
blocking: boolean;
estimatedRows: number | null;
}

export interface TableTransferPlan {
tables: TableTransferTablePlan[];
issues: TableTransferIssue[];
blocking: boolean;
}

export type TableTransferStatus = 'completed' | 'failed' | 'cancelled' | 'notStarted' | 'running';

export interface TableTransferTableResult {
sourceTable: string;
targetTable: string;
status: TableTransferStatus;
rowsRead: number;
rowsWritten: number;
rowsSkipped: number;
/** Rows of the batch that was rolled back when the table failed. */
rowsFailed: number;
error: string | null;
}

export interface TableTransferResult {
transferId: string;
status: TableTransferStatus;
tables: TableTransferTableResult[];
}

export type TableSqlContent = 'structure_and_data' | 'structure_only';
export type TableSqlStructureSource = 'driver' | 'generated';
/** What "Import table from SQL" does when the table already exists. */
Expand Down Expand Up @@ -824,6 +911,22 @@ export interface CommandMap {
cancel_dump: CommandDefinition<ConnectionIdRequest, void, 'sensitive'>;
import_database: CommandDefinition<DatabaseImportRequest, void, 'sensitive'>;
cancel_import: CommandDefinition<ConnectionIdRequest, void, 'sensitive'>;
get_table_transfer_capabilities: CommandDefinition<
undefined,
TableTransferCapabilities,
'sensitive'
>;
plan_table_transfer: CommandDefinition<
{request: TableTransferRequest},
TableTransferPlan,
'sensitive'
>;
run_table_transfer: CommandDefinition<
{request: TableTransferRequest},
TableTransferResult,
'sensitive'
>;
cancel_table_transfer: CommandDefinition<{transferId: string}, void, 'sensitive'>;
export_table_to_sql: CommandDefinition<TableExportRequest, TableExportResult, 'sensitive'>;
read_table_sql_header: CommandDefinition<
TableImportFileRequest,
Expand Down
18 changes: 17 additions & 1 deletion packages/web-ui/src/api/events.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type {ConnectionTestProgressPayload} from '@/utils/connectionTest';
import type {BatchStatementResult} from '@/types/editor';
import type {AuthorizationLevel} from './contract';
import type {AuthorizationLevel, TableTransferStatus} from './contract';
import type {SshAskpassRequest} from '@/types/askpass';
import type {RequestId} from './errors';
import type {AiActivityEvent, PendingApproval} from '@/types/ai';
Expand Down Expand Up @@ -52,6 +52,21 @@ export interface EventMap {
},
'database'
>;
table_transfer_progress: EventDefinition<
{
transfer_id: string;
table_index: number;
total_tables: number;
source_table: string;
target_table: string;
status: TableTransferStatus;
rows_read: number;
rows_written: number;
rows_skipped: number;
estimated_rows: number | null;
},
'database'
>;
export_progress: EventDefinition<{connection_id: string; rows_processed: number}, 'database'>;
'ssh-askpass://request': EventDefinition<SshAskpassRequest, 'sensitive'>;
'ssh-askpass://dismiss': EventDefinition<number, 'sensitive'>;
Expand Down Expand Up @@ -103,6 +118,7 @@ export const EVENT_AUTHORIZATION = {
'query-cancelled': 'database',
dump_progress: 'database',
import_progress: 'database',
table_transfer_progress: 'database',
export_progress: 'database',
'ssh-askpass://request': 'sensitive',
'ssh-askpass://dismiss': 'sensitive',
Expand Down
38 changes: 38 additions & 0 deletions packages/web-ui/src/components/layout/ExplorerSidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {buildDropTableSql} from '@/utils/dropTable';
import {formatObjectNameForCopy, type ObjectNameCopyFormat} from '@/utils/objectNameCopy';
import {isPostgresDriver, triggerFunctionName} from '@/utils/triggerSql';
import {
ArrowRightLeft,
Database,
Plus,
FileCode,
Expand Down Expand Up @@ -90,6 +91,9 @@ import {CreateForeignKeyModal} from '@/components/modals/CreateForeignKeyModal';
import {GenerateSQLModal} from '@/components/modals/GenerateSQLModal';
import {DumpDatabaseModal} from '@/components/modals/DumpDatabaseModal';
import {ImportDatabaseModal} from '@/components/modals/ImportDatabaseModal';
import {TableTransferModal} from '@/components/modals/TableTransferModal';
import {useTableTransferCapabilities} from '@/hooks/useTableTransferCapabilities';
import {canTransferFrom} from '@/utils/tableRowTransfer';
import {ExportTableModal} from '@/components/modals/ExportTableModal';
import {ImportTableModal} from '@/components/modals/ImportTableModal';
import {ClipboardImportModal} from '@/components/modals/ClipboardImportModal';
Expand Down Expand Up @@ -420,6 +424,12 @@ export const ExplorerSidebar = ({
query?: SavedQuery;
}>({isOpen: false});
const [dumpModal, setDumpModal] = useState<{database: string; schema?: string} | null>(null);
const tableTransferCapabilities = useTableTransferCapabilities();
const [transferModal, setTransferModal] = useState<{
table: string;
schema?: string;
database?: string;
} | null>(null);
const [importModal, setImportModal] = useState<{
inputFile: ChosenInputFile;
database: string;
Expand Down Expand Up @@ -3794,6 +3804,23 @@ export const ExplorerSidebar = ({
},
}
: null,
tableTransferCapabilities &&
canTransferFrom(
tableTransferCapabilities.pairs,
activeDriver ?? '',
)
? {
label: t('tableRowTransfer.contextMenuLabel'),
icon: ArrowRightLeft,
action: () =>
setTransferModal({
table: contextMenu.id,
schema:
ctxSchema ?? activeSchema ?? undefined,
database: ctxDatabase,
}),
}
: null,
supportsTableExport(activeCapabilities)
? {
label: t('tableTransfer.exportMenu'),
Expand Down Expand Up @@ -5263,6 +5290,17 @@ export const ExplorerSidebar = ({
/>
)}

{transferModal && activeConnectionId && (
<TableTransferModal
isOpen={true}
onClose={() => setTransferModal(null)}
sourceConnectionId={activeConnectionId}
sourceTable={transferModal.table}
sourceSchema={transferModal.schema}
sourceDatabase={transferModal.database}
/>
)}

{importModal && activeConnectionId && (
<ImportDatabaseModal
isOpen={true}
Expand Down
Loading