Skip to content
Merged
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
17 changes: 17 additions & 0 deletions bridge/src/connectors/mariadb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1765,3 +1765,20 @@ export async function searchTable(
await pool.end();
}
}

/**
* listSchemaNames: Retrieves just the names of schemas (databases).
* Lightweight version for schema selector.
*/
export async function listSchemaNames(cfg: MariaDBConfig): Promise<string[]> {
const pool = mysql.createPool(createPoolConfig(cfg));
const connection = await pool.getConnection();

try {
const [rows] = await connection.query(LIST_SCHEMAS);
return (rows as any[]).map((r: any) => r.name);
} finally {
connection.release();
await pool.end();
}
}
17 changes: 17 additions & 0 deletions bridge/src/connectors/mysql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1740,3 +1740,20 @@ export async function searchTable(
await pool.end();
}
}

/**
* listSchemaNames: Retrieves just the names of schemas (databases).
* Lightweight version for schema selector.
*/
export async function listSchemaNames(cfg: MySQLConfig): Promise<string[]> {
const pool = mysql.createPool(createPoolConfig(cfg));
const connection = await pool.getConnection();

try {
const [rows] = await connection.query(LIST_SCHEMAS);
return (rows as any[]).map((r: any) => r.name);
} finally {
connection.release();
await pool.end();
}
}
20 changes: 20 additions & 0 deletions bridge/src/connectors/postgres.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1869,3 +1869,23 @@ export async function searchTable(
} catch (_) { }
}
}

/**
* listSchemaNames: Retrieves just the names of schemas.
* Lightweight version of listSchemas.
*/
export async function listSchemaNames(connection: PGConfig): Promise<string[]> {
// Check cache first (re-use schemas cache if available, or a new cache if needed)
// For now, simpler to just query as it's very fast
const client = createClient(connection);

try {
await client.connect();
const res = await client.query(PG_LIST_SCHEMAS);
return res.rows.map((r: any) => r.name);
} finally {
try {
await client.end();
} catch (e) { }
}
}
20 changes: 19 additions & 1 deletion bridge/src/handlers/databaseHandlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,32 @@ export class DatabaseHandlers {
}

const { conn, dbType } = await this.dbService.getDatabaseConnection(dbId);
const tables = await this.queryExecutor.listTables(conn, dbType);
const tables = await this.queryExecutor.listTables(conn, dbType, params.schema);
this.rpc.sendResponse(id, { ok: true, data: tables });
} catch (e: any) {
this.logger?.error({ e }, "db.listTables failed");
this.rpc.sendError(id, { code: "IO_ERROR", message: String(e) });
}
}

async handleListSchemas(params: any, id: number | string) {
try {
const { id: dbId } = params || {};
if (!dbId) {
return this.rpc.sendError(id, {
code: "BAD_REQUEST",
message: "Missing id",
});
}
const { conn, dbType } = await this.dbService.getDatabaseConnection(dbId);
const schemas = await this.queryExecutor.listSchemaNames(conn, dbType);
this.rpc.sendResponse(id, { ok: true, data: schemas });
} catch (e: any) {
this.logger?.error({ e }, "db.listSchemas failed");
this.rpc.sendError(id, { code: "IO_ERROR", message: String(e) });
}
}

async handleGetSchema(params: any, id: number | string) {
try {
const { id: dbId, schema } = params || {};
Expand Down
3 changes: 3 additions & 0 deletions bridge/src/jsonRpcHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,9 @@ export function registerDbHandlers(
rpcRegister("db.getSchema", (p, id) =>
databaseHandlers.handleGetSchema(p, id)
);
rpcRegister("db.listSchemas", (p, id) =>
databaseHandlers.handleListSchemas(p, id)
);

// ==========================================
// MIGRATION HANDLERS
Expand Down
11 changes: 11 additions & 0 deletions bridge/src/services/queryExecutor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -320,4 +320,15 @@ export class QueryExecutor {
};
}
}

async listSchemaNames(conn: DatabaseConfig, dbType: DBType): Promise<string[]> {
if (dbType === DBType.POSTGRES) {
return this.postgres.listSchemaNames(conn);
} else if (dbType === DBType.MARIADB) {
return this.mariadb.listSchemaNames(conn);
} else if (dbType === DBType.MYSQL) {
return this.mysql.listSchemaNames(conn);
}
return ["public"];
}
}
19 changes: 7 additions & 12 deletions bridge/src/utils/migrationGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,9 @@ export function generateCreateTableMigration(params: {

const allDefs = [...[columnDefs], ...fkDefs].filter(Boolean).join(",\n");

// For MySQL/MariaDB, don't use schema prefix (database is the schema)
const tableRef = (dbType === "mysql" || dbType === "mariadb")
? quoteIdent(tableName, dbType)
: `${quoteIdent(schemaName, dbType)}.${quoteIdent(tableName, dbType)}`;
// For MySQL/MariaDB, use database.table format (schemas are databases)
// For Postgres, use schema.table format
const tableRef = `${quoteIdent(schemaName, dbType)}.${quoteIdent(tableName, dbType)}`;

// Generate UP SQL
const upSQL = `CREATE TABLE ${tableRef} (
Expand Down Expand Up @@ -94,10 +93,8 @@ export function generateAlterTableMigration(params: {
const name = `alter_${tableName}_table`;
const filename = `${version}_${name}.sql`;

// For MySQL/MariaDB, don't use schema prefix
const fullTableName = (dbType === "mysql" || dbType === "mariadb")
? quoteIdent(tableName, dbType)
: `${quoteIdent(schemaName, dbType)}.${quoteIdent(tableName, dbType)}`;
// For all database types, use schema/database prefix
const fullTableName = `${quoteIdent(schemaName, dbType)}.${quoteIdent(tableName, dbType)}`;

// Build UP SQL
const upStatements: string[] = [];
Expand Down Expand Up @@ -251,10 +248,8 @@ export function generateDropTableMigration(params: {
const name = `drop_${tableName}_table`;
const filename = `${version}_${name}.sql`;

// For MySQL/MariaDB, don't use schema prefix
const fullTableName = (dbType === "mysql" || dbType === "mariadb")
? quoteIdent(tableName, dbType)
: `${quoteIdent(schemaName, dbType)}.${quoteIdent(tableName, dbType)}`;
// For all database types, use schema/database prefix
const fullTableName = `${quoteIdent(schemaName, dbType)}.${quoteIdent(tableName, dbType)}`;

let upSQL = "";
if (mode === "CASCADE") {
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
"@types/react": "^19.1.8",
"@types/react-dom": "^19.1.6",
"@vitejs/plugin-react": "^4.6.0",
"baseline-browser-mapping": "^2.9.19",
"tw-animate-css": "^1.4.0",
"typescript": "~5.8.3",
"vite": "^7.0.4"
Expand Down
11 changes: 7 additions & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 26 additions & 1 deletion src/components/database/MigrationsPanel.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useState } from "react";
import { CheckCircle2, Clock, AlertCircle, Database, Play, Undo2, Trash2, Eye } from "lucide-react";
import { CheckCircle2, Clock, AlertCircle, Database, Play, Undo2, Trash2, Eye, RefreshCw } from "lucide-react";
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
import { Badge } from "@/components/ui/badge";
import { Button } from "@/components/ui/button";
Expand All @@ -22,6 +22,22 @@ export default function MigrationsPanel({ migrations, baselined, dbId }: Migrati
const [selectedMigration, setSelectedMigration] = useState<{ version: string; name: string } | null>(null);
const [showSQLDialog, setShowSQLDialog] = useState(false);
const [sqlContent, setSqlContent] = useState<{ up: string; down: string } | null>(null);
const [isRefreshing, setIsRefreshing] = useState(false);

const handleRefresh = async () => {
setIsRefreshing(true);
try {
await Promise.all([
queryClient.invalidateQueries({ queryKey: ["migrations", dbId] }),
queryClient.invalidateQueries({ queryKey: ["tables", dbId] }),
queryClient.invalidateQueries({ queryKey: ["schema", dbId] }),
queryClient.invalidateQueries({ queryKey: ["schemaNames", dbId] }),
]);
toast.success("Refreshed successfully");
} finally {
setIsRefreshing(false);
}
};

// Merge and sort migrations
const appliedVersions = new Set(applied.map((m) => m.version));
Expand Down Expand Up @@ -115,6 +131,15 @@ export default function MigrationsPanel({ migrations, baselined, dbId }: Migrati
<Badge variant={baselined ? "default" : "secondary"} className="text-xs">
{baselined ? "Baselined" : "Not Baselined"}
</Badge>
<Button
variant="ghost"
size="icon"
className="h-7 w-7"
onClick={handleRefresh}
disabled={isRefreshing}
>
<RefreshCw className={cn("h-3.5 w-3.5", isRefreshing && "animate-spin")} />
</Button>
</div>
<p className="text-xs text-muted-foreground mt-1">
Schema version control and migration status
Expand Down
4 changes: 3 additions & 1 deletion src/components/database/TablesExplorerPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ interface TablesExplorerPanelProps {
dbId: string;
tables: TableInfo[];
selectedTable: SelectedTable | null;
selectedSchema: string;
onSelectTable: (tableName: string, schemaName: string) => void;
loading?: boolean;
}
Expand All @@ -19,6 +20,7 @@ export default function TablesExplorerPanel({
dbId,
tables,
selectedTable,
selectedSchema,
onSelectTable,
loading = false,
}: TablesExplorerPanelProps) {
Expand Down Expand Up @@ -160,7 +162,7 @@ export default function TablesExplorerPanel({
dbId={dbId}
open={createTableOpen}
onOpenChange={setCreateTableOpen}
schemaName={selectedTable?.schema || ''}
schemaName={selectedSchema}
/>
</div>
</div>
Expand Down
Loading