Four new killer features leveraging AI (Ollama) and PostgreSQL internals: - Data Validation: describe quality rules in natural language, AI generates SQL to find violations, run with pass/fail results and sample violations - Test Data Generator: right-click table to generate realistic FK-aware test data with AI, preview before inserting in a transaction - Index Advisor: analyze pg_stat tables + AI recommendations for CREATE/DROP INDEX with one-click apply - Data Snapshots: export selected tables to JSON (FK-ordered), restore from file with optional truncate in a transaction Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
568 lines
11 KiB
TypeScript
568 lines
11 KiB
TypeScript
export type DbFlavor = "postgresql" | "greenplum";
|
|
|
|
export interface ConnectResult {
|
|
version: string;
|
|
flavor: DbFlavor;
|
|
}
|
|
|
|
export interface ConnectionConfig {
|
|
id: string;
|
|
name: string;
|
|
host: string;
|
|
port: number;
|
|
user: string;
|
|
password: string;
|
|
database: string;
|
|
ssl_mode?: string;
|
|
color?: string;
|
|
environment?: string;
|
|
}
|
|
|
|
export interface QueryResult {
|
|
columns: string[];
|
|
types: string[];
|
|
rows: unknown[][];
|
|
row_count: number;
|
|
execution_time_ms: number;
|
|
}
|
|
|
|
export interface PaginatedQueryResult extends QueryResult {
|
|
total_rows: number;
|
|
page: number;
|
|
page_size: number;
|
|
ctids: string[];
|
|
}
|
|
|
|
export interface SchemaObject {
|
|
name: string;
|
|
object_type: string;
|
|
schema: string;
|
|
row_count?: number;
|
|
size_bytes?: number;
|
|
}
|
|
|
|
export interface ColumnDetail {
|
|
column_name: string;
|
|
data_type: string;
|
|
is_nullable: boolean;
|
|
column_default: string | null;
|
|
is_identity: boolean;
|
|
}
|
|
|
|
export interface ColumnInfo {
|
|
name: string;
|
|
data_type: string;
|
|
is_nullable: boolean;
|
|
column_default: string | null;
|
|
ordinal_position: number;
|
|
character_maximum_length: number | null;
|
|
is_primary_key: boolean;
|
|
comment: string | null;
|
|
}
|
|
|
|
export interface ConstraintInfo {
|
|
name: string;
|
|
constraint_type: string;
|
|
columns: string[];
|
|
referenced_schema: string | null;
|
|
referenced_table: string | null;
|
|
referenced_columns: string[] | null;
|
|
update_rule: string | null;
|
|
delete_rule: string | null;
|
|
}
|
|
|
|
export interface IndexInfo {
|
|
name: string;
|
|
definition: string;
|
|
is_unique: boolean;
|
|
is_primary: boolean;
|
|
}
|
|
|
|
export interface HistoryEntry {
|
|
id: string;
|
|
connection_id: string;
|
|
connection_name: string;
|
|
database: string;
|
|
sql: string;
|
|
status: string;
|
|
error_message?: string;
|
|
row_count?: number;
|
|
execution_time_ms: number;
|
|
executed_at: string;
|
|
}
|
|
|
|
export interface ExplainNode {
|
|
"Node Type": string;
|
|
"Relation Name"?: string;
|
|
"Schema"?: string;
|
|
"Alias"?: string;
|
|
"Startup Cost": number;
|
|
"Total Cost": number;
|
|
"Plan Rows": number;
|
|
"Plan Width": number;
|
|
"Actual Startup Time"?: number;
|
|
"Actual Total Time"?: number;
|
|
"Actual Rows"?: number;
|
|
"Actual Loops"?: number;
|
|
"Shared Hit Blocks"?: number;
|
|
"Shared Read Blocks"?: number;
|
|
"Filter"?: string;
|
|
"Join Type"?: string;
|
|
"Index Name"?: string;
|
|
"Index Cond"?: string;
|
|
"Hash Cond"?: string;
|
|
"Sort Key"?: string[];
|
|
Plans?: ExplainNode[];
|
|
[key: string]: unknown;
|
|
}
|
|
|
|
export interface ExplainResult {
|
|
Plan: ExplainNode;
|
|
"Planning Time": number;
|
|
"Execution Time": number;
|
|
}
|
|
|
|
export interface DatabaseInfo {
|
|
name: string;
|
|
owner: string;
|
|
encoding: string;
|
|
collation: string;
|
|
ctype: string;
|
|
tablespace: string;
|
|
connection_limit: number;
|
|
size: string;
|
|
description: string | null;
|
|
}
|
|
|
|
export interface CreateDatabaseParams {
|
|
name: string;
|
|
owner?: string;
|
|
template?: string;
|
|
encoding?: string;
|
|
tablespace?: string;
|
|
connection_limit?: number;
|
|
}
|
|
|
|
export interface RoleInfo {
|
|
name: string;
|
|
is_superuser: boolean;
|
|
can_login: boolean;
|
|
can_create_db: boolean;
|
|
can_create_role: boolean;
|
|
inherit: boolean;
|
|
is_replication: boolean;
|
|
connection_limit: number;
|
|
password_set: boolean;
|
|
valid_until: string | null;
|
|
member_of: string[];
|
|
members: string[];
|
|
description: string | null;
|
|
}
|
|
|
|
export interface CreateRoleParams {
|
|
name: string;
|
|
password?: string;
|
|
login: boolean;
|
|
superuser: boolean;
|
|
createdb: boolean;
|
|
createrole: boolean;
|
|
inherit: boolean;
|
|
replication: boolean;
|
|
connection_limit?: number;
|
|
valid_until?: string;
|
|
in_roles: string[];
|
|
}
|
|
|
|
export interface AlterRoleParams {
|
|
name: string;
|
|
password?: string;
|
|
login?: boolean;
|
|
superuser?: boolean;
|
|
createdb?: boolean;
|
|
createrole?: boolean;
|
|
inherit?: boolean;
|
|
replication?: boolean;
|
|
connection_limit?: number;
|
|
valid_until?: string;
|
|
rename_to?: string;
|
|
}
|
|
|
|
export interface TablePrivilege {
|
|
grantee: string;
|
|
table_schema: string;
|
|
table_name: string;
|
|
privilege_type: string;
|
|
is_grantable: boolean;
|
|
}
|
|
|
|
export interface GrantRevokeParams {
|
|
action: string;
|
|
privileges: string[];
|
|
object_type: string;
|
|
object_name: string;
|
|
role_name: string;
|
|
with_grant_option: boolean;
|
|
}
|
|
|
|
export interface RoleMembershipParams {
|
|
action: string;
|
|
role_name: string;
|
|
member_name: string;
|
|
}
|
|
|
|
export interface SessionInfo {
|
|
pid: number;
|
|
usename: string | null;
|
|
datname: string | null;
|
|
state: string | null;
|
|
query: string | null;
|
|
query_start: string | null;
|
|
wait_event_type: string | null;
|
|
wait_event: string | null;
|
|
client_addr: string | null;
|
|
}
|
|
|
|
export interface SavedQuery {
|
|
id: string;
|
|
name: string;
|
|
sql: string;
|
|
connection_id?: string;
|
|
created_at: string;
|
|
}
|
|
|
|
export type AiProvider = "ollama" | "openai" | "anthropic";
|
|
|
|
export interface AiSettings {
|
|
provider: AiProvider;
|
|
ollama_url: string;
|
|
openai_api_key?: string;
|
|
anthropic_api_key?: string;
|
|
model: string;
|
|
}
|
|
|
|
export interface OllamaModel {
|
|
name: string;
|
|
}
|
|
|
|
// Entity Lookup
|
|
export interface LookupTableMatch {
|
|
schema: string;
|
|
table: string;
|
|
column_type: string;
|
|
columns: string[];
|
|
types: string[];
|
|
rows: unknown[][];
|
|
row_count: number;
|
|
total_count: number;
|
|
}
|
|
|
|
export interface LookupDatabaseResult {
|
|
database: string;
|
|
tables: LookupTableMatch[];
|
|
error: string | null;
|
|
search_time_ms: number;
|
|
}
|
|
|
|
export interface EntityLookupResult {
|
|
column_name: string;
|
|
value: string;
|
|
databases: LookupDatabaseResult[];
|
|
total_databases_searched: number;
|
|
total_tables_matched: number;
|
|
total_rows_found: number;
|
|
total_time_ms: number;
|
|
}
|
|
|
|
export interface LookupProgress {
|
|
lookup_id: string;
|
|
database: string;
|
|
status: string;
|
|
tables_found: number;
|
|
rows_found: number;
|
|
error: string | null;
|
|
completed: number;
|
|
total: number;
|
|
}
|
|
|
|
export interface TriggerInfo {
|
|
name: string;
|
|
event: string;
|
|
timing: string;
|
|
orientation: string;
|
|
function_name: string;
|
|
is_enabled: boolean;
|
|
definition: string;
|
|
}
|
|
|
|
export interface ErdColumn {
|
|
name: string;
|
|
data_type: string;
|
|
is_nullable: boolean;
|
|
is_primary_key: boolean;
|
|
}
|
|
|
|
export interface ErdTable {
|
|
schema: string;
|
|
name: string;
|
|
columns: ErdColumn[];
|
|
}
|
|
|
|
export interface ErdRelationship {
|
|
constraint_name: string;
|
|
source_schema: string;
|
|
source_table: string;
|
|
source_columns: string[];
|
|
target_schema: string;
|
|
target_table: string;
|
|
target_columns: string[];
|
|
update_rule: string;
|
|
delete_rule: string;
|
|
}
|
|
|
|
export interface ErdData {
|
|
tables: ErdTable[];
|
|
relationships: ErdRelationship[];
|
|
}
|
|
|
|
// App Settings
|
|
export type DockerHost = "local" | "remote";
|
|
|
|
export interface McpSettings {
|
|
enabled: boolean;
|
|
port: number;
|
|
}
|
|
|
|
export interface DockerSettings {
|
|
host: DockerHost;
|
|
remote_url?: string;
|
|
}
|
|
|
|
export interface AppSettings {
|
|
mcp: McpSettings;
|
|
docker: DockerSettings;
|
|
}
|
|
|
|
export interface McpStatus {
|
|
enabled: boolean;
|
|
port: number;
|
|
running: boolean;
|
|
}
|
|
|
|
// Docker
|
|
export interface DockerStatus {
|
|
installed: boolean;
|
|
daemon_running: boolean;
|
|
version: string | null;
|
|
error: string | null;
|
|
}
|
|
|
|
export type CloneMode = "schema_only" | "full_clone" | "sample_data";
|
|
|
|
export interface CloneToDockerParams {
|
|
source_connection_id: string;
|
|
source_database: string;
|
|
container_name: string;
|
|
pg_version: string;
|
|
host_port: number | null;
|
|
clone_mode: CloneMode;
|
|
sample_rows: number | null;
|
|
postgres_password: string | null;
|
|
}
|
|
|
|
export interface CloneProgress {
|
|
clone_id: string;
|
|
stage: string;
|
|
percent: number;
|
|
message: string;
|
|
detail: string | null;
|
|
}
|
|
|
|
export interface TuskContainer {
|
|
container_id: string;
|
|
name: string;
|
|
status: string;
|
|
host_port: number;
|
|
pg_version: string;
|
|
source_database: string | null;
|
|
source_connection: string | null;
|
|
created_at: string | null;
|
|
}
|
|
|
|
export interface CloneResult {
|
|
container: TuskContainer;
|
|
connection_id: string;
|
|
connection_url: string;
|
|
}
|
|
|
|
export type TabType = "query" | "table" | "structure" | "roles" | "sessions" | "lookup" | "erd" | "validation" | "index-advisor" | "snapshots";
|
|
|
|
export interface Tab {
|
|
id: string;
|
|
type: TabType;
|
|
title: string;
|
|
connectionId: string;
|
|
database?: string;
|
|
schema?: string;
|
|
table?: string;
|
|
sql?: string;
|
|
roleName?: string;
|
|
lookupColumn?: string;
|
|
lookupValue?: string;
|
|
}
|
|
|
|
// --- Wave 1: Validation ---
|
|
|
|
export type ValidationStatus = "pending" | "generating" | "running" | "passed" | "failed" | "error";
|
|
|
|
export interface ValidationRule {
|
|
id: string;
|
|
description: string;
|
|
generated_sql: string;
|
|
status: ValidationStatus;
|
|
violation_count: number;
|
|
sample_violations: unknown[][];
|
|
violation_columns: string[];
|
|
error: string | null;
|
|
}
|
|
|
|
export interface ValidationReport {
|
|
rules: ValidationRule[];
|
|
total_rules: number;
|
|
passed: number;
|
|
failed: number;
|
|
errors: number;
|
|
execution_time_ms: number;
|
|
}
|
|
|
|
// --- Wave 2: Data Generator ---
|
|
|
|
export interface GenerateDataParams {
|
|
connection_id: string;
|
|
schema: string;
|
|
table: string;
|
|
row_count: number;
|
|
include_related: boolean;
|
|
custom_instructions?: string;
|
|
}
|
|
|
|
export interface GeneratedDataPreview {
|
|
tables: GeneratedTableData[];
|
|
insert_order: string[];
|
|
total_rows: number;
|
|
}
|
|
|
|
export interface GeneratedTableData {
|
|
schema: string;
|
|
table: string;
|
|
columns: string[];
|
|
rows: unknown[][];
|
|
row_count: number;
|
|
}
|
|
|
|
export interface DataGenProgress {
|
|
gen_id: string;
|
|
stage: string;
|
|
percent: number;
|
|
message: string;
|
|
detail: string | null;
|
|
}
|
|
|
|
// --- Wave 3A: Index Advisor ---
|
|
|
|
export interface TableStats {
|
|
schema: string;
|
|
table: string;
|
|
seq_scan: number;
|
|
idx_scan: number;
|
|
n_live_tup: number;
|
|
table_size: string;
|
|
index_size: string;
|
|
}
|
|
|
|
export interface IndexStatsInfo {
|
|
schema: string;
|
|
table: string;
|
|
index_name: string;
|
|
idx_scan: number;
|
|
index_size: string;
|
|
definition: string;
|
|
}
|
|
|
|
export interface SlowQuery {
|
|
query: string;
|
|
calls: number;
|
|
total_time_ms: number;
|
|
mean_time_ms: number;
|
|
rows: number;
|
|
}
|
|
|
|
export type IndexRecommendationType = "create_index" | "drop_index" | "replace_index";
|
|
|
|
export interface IndexRecommendation {
|
|
id: string;
|
|
recommendation_type: IndexRecommendationType;
|
|
table_schema: string;
|
|
table_name: string;
|
|
index_name: string | null;
|
|
ddl: string;
|
|
rationale: string;
|
|
estimated_impact: string;
|
|
priority: string;
|
|
}
|
|
|
|
export interface IndexAdvisorReport {
|
|
table_stats: TableStats[];
|
|
index_stats: IndexStatsInfo[];
|
|
slow_queries: SlowQuery[];
|
|
recommendations: IndexRecommendation[];
|
|
has_pg_stat_statements: boolean;
|
|
}
|
|
|
|
// --- Wave 3B: Snapshots ---
|
|
|
|
export interface SnapshotMetadata {
|
|
id: string;
|
|
name: string;
|
|
created_at: string;
|
|
connection_name: string;
|
|
database: string;
|
|
tables: SnapshotTableMeta[];
|
|
total_rows: number;
|
|
file_size_bytes: number;
|
|
version: number;
|
|
}
|
|
|
|
export interface SnapshotTableMeta {
|
|
schema: string;
|
|
table: string;
|
|
row_count: number;
|
|
columns: string[];
|
|
column_types: string[];
|
|
}
|
|
|
|
export interface SnapshotProgress {
|
|
snapshot_id: string;
|
|
stage: string;
|
|
percent: number;
|
|
message: string;
|
|
detail: string | null;
|
|
}
|
|
|
|
export interface CreateSnapshotParams {
|
|
connection_id: string;
|
|
tables: TableRef[];
|
|
name: string;
|
|
include_dependencies: boolean;
|
|
}
|
|
|
|
export interface TableRef {
|
|
schema: string;
|
|
table: string;
|
|
}
|
|
|
|
export interface RestoreSnapshotParams {
|
|
connection_id: string;
|
|
file_path: string;
|
|
truncate_before_restore: boolean;
|
|
}
|