Skip to content

Commit

Permalink
Merge pull request #224 from dolthub/taylor/dg-support
Browse files Browse the repository at this point in the history
web,graphql: Progress on doltgres support
  • Loading branch information
tbantle22 authored Oct 17, 2024
2 parents 1a5537b + 024daf3 commit cf8ae21
Show file tree
Hide file tree
Showing 68 changed files with 830 additions and 371 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# dolt-workbench

A modern, browser-based, open source SQL workbench for your MySQL and PostgreSQL
compatible databases. Use [Dolt](https://doltdb.com) to unlock powerful version control
features. [Doltgres](https://github.com/dolthub/doltgresql) support coming soon.
compatible databases. Use [Dolt](https://doltdb.com) or
[Doltgres](https://github.com/dolthub/doltgresql) to unlock powerful version control
features.

## Installation

Expand Down
8 changes: 3 additions & 5 deletions graphql-server/schema.gql
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ type DatabaseConnection {
hideDoltFeatures: Boolean
useSSL: Boolean
type: DatabaseType
schema: String
isDolt: Boolean
}

Expand All @@ -118,7 +117,6 @@ type DoltDatabaseDetails {

type CurrentDatabaseState {
currentDatabase: String
currentSchema: String
}

type DiffStat {
Expand Down Expand Up @@ -291,7 +289,7 @@ type Query {
currentDatabase: String
storedConnections: [DatabaseConnection!]!
databases: [String!]!
schemas(databaseName: String!): [String!]!
schemas(databaseName: String!, refName: String!): [String!]!
doltDatabaseDetails: DoltDatabaseDetails!
diffStat(databaseName: String!, fromRefName: String!, toRefName: String!, refName: String, type: CommitDiffType, tableName: String): DiffStat!
diffSummaries(databaseName: String!, fromRefName: String!, toRefName: String!, refName: String, type: CommitDiffType, tableName: String): [DiffSummary!]!
Expand Down Expand Up @@ -341,10 +339,10 @@ enum DiffRowType {
type Mutation {
createBranch(databaseName: String!, newBranchName: String!, fromRefName: String!): String!
deleteBranch(databaseName: String!, branchName: String!): Boolean!
addDatabaseConnection(connectionUrl: String!, name: String!, hideDoltFeatures: Boolean, useSSL: Boolean, type: DatabaseType, schema: String): CurrentDatabaseState!
addDatabaseConnection(connectionUrl: String!, name: String!, hideDoltFeatures: Boolean, useSSL: Boolean, type: DatabaseType): CurrentDatabaseState!
removeDatabaseConnection(name: String!): Boolean!
createDatabase(databaseName: String!): Boolean!
createSchema(databaseName: String!, schemaName: String!): Boolean!
createSchema(refName: String!, databaseName: String!, schemaName: String!): Boolean!
resetDatabase(newDatabase: String): Boolean!
loadDataFile(schemaName: String, tableName: String!, refName: String!, databaseName: String!, importOp: ImportOperation!, fileType: FileType!, file: Upload!, modifier: LoadDataModifier): Boolean!
mergePull(fromBranchName: String!, toBranchName: String!, databaseName: String!, author: AuthorInfo): Boolean!
Expand Down
3 changes: 0 additions & 3 deletions graphql-server/src/databases/database.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@ export class DatabaseConnection {
@Field(_type => DatabaseType, { nullable: true })
type?: DatabaseType;

@Field({ nullable: true })
schema?: string;

@Field({ nullable: true })
isDolt?: boolean;
}
16 changes: 4 additions & 12 deletions graphql-server/src/databases/database.resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
import { ConnectionProvider } from "../connections/connection.provider";
import { DataStoreService } from "../dataStore/dataStore.service";
import { FileStoreService } from "../fileStore/fileStore.service";
import { DBArgs, SchemaArgs } from "../utils/commonTypes";
import { DBArgs, RefArgs, RefSchemaArgs } from "../utils/commonTypes";
import { DatabaseType } from "./database.enum";
import { DatabaseConnection } from "./database.model";

Expand All @@ -30,9 +30,6 @@ class AddDatabaseConnectionArgs {

@Field(_type => DatabaseType, { nullable: true })
type?: DatabaseType;

@Field({ nullable: true })
schema?: string;
}

@ObjectType()
Expand All @@ -51,10 +48,6 @@ class DoltDatabaseDetails {
class CurrentDatabaseState {
@Field({ nullable: true })
currentDatabase?: string;

// Postgres only
@Field({ nullable: true })
currentSchema?: string;
}

@ArgsType()
Expand Down Expand Up @@ -99,7 +92,7 @@ export class DatabaseResolver {
}

@Query(_returns => [String])
async schemas(@Args() args: DBArgs): Promise<string[]> {
async schemas(@Args() args: RefArgs): Promise<string[]> {
const conn = this.conn.connection();
if (!conn.schemas) return [];
const schemas = await conn.schemas(args);
Expand Down Expand Up @@ -133,7 +126,6 @@ export class DatabaseResolver {
hideDoltFeatures: !!args.hideDoltFeatures,
useSSL: !!args.useSSL,
type,
schema: args.schema,
};

const { isDolt } = await this.conn.addConnection(workbenchConfig);
Expand All @@ -146,7 +138,7 @@ export class DatabaseResolver {
}

const db = await this.currentDatabase();
return { currentDatabase: db, currentSchema: args.schema };
return { currentDatabase: db };
}

@Mutation(_returns => Boolean)
Expand All @@ -169,7 +161,7 @@ export class DatabaseResolver {
}

@Mutation(_returns => Boolean)
async createSchema(@Args() args: SchemaArgs): Promise<boolean> {
async createSchema(@Args() args: RefSchemaArgs): Promise<boolean> {
const conn = this.conn.connection();
if (!conn.createSchema) return false;
await conn.createSchema(args);
Expand Down
12 changes: 11 additions & 1 deletion graphql-server/src/queryFactory/dolt/doltEntityManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,27 @@ import { SchemaType } from "../../schemas/schema.enums";
import { SchemaItem } from "../../schemas/schema.model";
import { DoltSystemTable } from "../../systemTables/systemTable.enums";
import { ROW_LIMIT, handleTableNotFound } from "../../utils";
import { tableWithSchema } from "../postgres/utils";
import * as t from "../types";
import { getOrderByColForBranches } from "./queries";

export async function getDoltSchemas(
em: EntityManager,
type?: SchemaType,
pgSchema?: string,
): Promise<SchemaItem[]> {
let sel = em
.createQueryBuilder()
.select("*")
.from(DoltSystemTable.SCHEMAS, "");
.from(
pgSchema
? tableWithSchema({
tableName: DoltSystemTable.SCHEMAS,
schemaName: pgSchema,
})
: DoltSystemTable.SCHEMAS,
DoltSystemTable.SCHEMAS,
);
if (type) {
sel = sel.where(`${DoltSystemTable.SCHEMAS}.type = :type`, {
type,
Expand Down
3 changes: 2 additions & 1 deletion graphql-server/src/queryFactory/dolt/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,8 @@ export class DoltQueryFactory

if (res.length && res[0].conflicts !== "0") {
await query("ROLLBACK");
throw new Error("Merge conflict detected");
const msg = res[0].message ?? "Merge conflict detected";
throw new Error(msg);
}

await query("COMMIT");
Expand Down
Loading

0 comments on commit cf8ae21

Please sign in to comment.