From cb51a105122e050ecb0a1b701ae2de52b380197b Mon Sep 17 00:00:00 2001 From: sokphaladam Date: Mon, 16 Dec 2024 22:06:12 +0700 Subject: [PATCH] change: schema database --- src/components/gui/schema-sidebar.tsx | 4 +- .../schema-database-collation.tsx | 55 ++++++------------- .../schema-database-dialog.tsx | 2 +- src/drivers/base-driver.ts | 2 +- src/drivers/mysql/mysql-driver.ts | 2 +- src/drivers/postgres/postgres-driver.ts | 5 +- src/drivers/sqlite-base-driver.ts | 5 ++ 7 files changed, 29 insertions(+), 46 deletions(-) diff --git a/src/components/gui/schema-sidebar.tsx b/src/components/gui/schema-sidebar.tsx index 10fe5b7..3006f44 100644 --- a/src/components/gui/schema-sidebar.tsx +++ b/src/components/gui/schema-sidebar.tsx @@ -30,7 +30,7 @@ export default function SchemaView() { const ActivatorButton = () => { - if (!databaseDriver.getFlags().suppoerCreateUpdateDatabase && !databaseDriver.getFlags().supportCreateUpdateTable) { + if (!databaseDriver.getFlags().supportCreateUpdateDatabase && !databaseDriver.getFlags().supportCreateUpdateTable) { return <> } @@ -68,7 +68,7 @@ export default function SchemaView() { { - databaseDriver.getFlags().suppoerCreateUpdateDatabase && onNewDatabase()}>New schema/database + databaseDriver.getFlags().supportCreateUpdateDatabase && onNewDatabase()}>New schema/database } { databaseDriver.getFlags().supportCreateUpdateTable && onNewTable()}>New table diff --git a/src/components/gui/tabs/schema-database-tab/schema-database-collation.tsx b/src/components/gui/tabs/schema-database-tab/schema-database-collation.tsx index 38f4ea0..bae6944 100644 --- a/src/components/gui/tabs/schema-database-tab/schema-database-collation.tsx +++ b/src/components/gui/tabs/schema-database-tab/schema-database-collation.tsx @@ -1,10 +1,7 @@ -import { cn } from "@/components/lib/utils"; import { Button } from "@/components/ui/button"; -import { Command, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList } from "@/components/ui/command"; -import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover"; +import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger } from "@/components/ui/dropdown-menu"; import { useDatabaseDriver } from "@/context/driver-provider"; -import { Check, ChevronsUpDown } from "lucide-react"; -import { useState } from "react"; +import { ChevronsUpDown } from "lucide-react"; interface SchemaCollateSelectProps { value?: string; @@ -19,11 +16,10 @@ export function SchemaDatabaseCollation( }: SchemaCollateSelectProps ) { const driver = useDatabaseDriver(); - const [open, setOpen] = useState(false); return ( - - + + - - - - - - No matched collation - - { - driver.databaseDriver.getCollationList().map(x => { - return ( - { - onChange(x); - setOpen(false) - }}> - - {x} - - ) - }) - } - - - - - + + + { + driver.databaseDriver.getCollationList().map(x => { + return ( + { + onChange(x); + }}>{x} + ) + }) + } + + ) } \ No newline at end of file diff --git a/src/components/gui/tabs/schema-database-tab/schema-database-dialog.tsx b/src/components/gui/tabs/schema-database-tab/schema-database-dialog.tsx index 26840ad..7cc0811 100644 --- a/src/components/gui/tabs/schema-database-tab/schema-database-dialog.tsx +++ b/src/components/gui/tabs/schema-database-tab/schema-database-dialog.tsx @@ -42,7 +42,7 @@ export function SchemaDatabaseDialog({ previewScript, onClose, schema }: Props) setIsExecuting(false); }) } - }, [databaseDriver, onClose, previewScript, refreshSchema]) + }, [databaseDriver, onClose, previewScript, refreshSchema, replaceCurrentTab, schema.name.new]) return ( diff --git a/src/drivers/base-driver.ts b/src/drivers/base-driver.ts index 576ef93..b7cdfa8 100644 --- a/src/drivers/base-driver.ts +++ b/src/drivers/base-driver.ts @@ -240,7 +240,7 @@ export interface DriverFlags { supportInsertReturning: boolean; supportUpdateReturning: boolean; supportRowId: boolean; - suppoerCreateUpdateDatabase: boolean; + supportCreateUpdateDatabase: boolean; } export interface DatabaseTableColumnChange { diff --git a/src/drivers/mysql/mysql-driver.ts b/src/drivers/mysql/mysql-driver.ts index 24b1e5c..6908403 100644 --- a/src/drivers/mysql/mysql-driver.ts +++ b/src/drivers/mysql/mysql-driver.ts @@ -128,7 +128,7 @@ export default abstract class MySQLLikeDriver extends CommonSQLImplement { supportModifyColumn: true, mismatchDetection: false, supportCreateUpdateTable: true, - suppoerCreateUpdateDatabase: true, + supportCreateUpdateDatabase: true, dialect: "mysql", supportUseStatement: true, diff --git a/src/drivers/postgres/postgres-driver.ts b/src/drivers/postgres/postgres-driver.ts index 7f9d4ea..417c73d 100644 --- a/src/drivers/postgres/postgres-driver.ts +++ b/src/drivers/postgres/postgres-driver.ts @@ -1,6 +1,5 @@ import { ColumnTypeSelector, - DatabaseSchemaChange, DatabaseSchemaItem, DatabaseSchemas, DatabaseTableColumn, @@ -78,7 +77,7 @@ export default abstract class PostgresLikeDriver extends CommonSQLImplement { supportModifyColumn: false, mismatchDetection: false, supportCreateUpdateTable: false, - suppoerCreateUpdateDatabase: false, + supportCreateUpdateDatabase: false, supportInsertReturning: true, supportUpdateReturning: true, }; @@ -352,7 +351,7 @@ WHERE throw new Error("Not implemented"); } - createUpdateDatabaseSchema(change: DatabaseSchemaChange): string[] { + createUpdateDatabaseSchema(): string[] { throw new Error("Not implemented"); } diff --git a/src/drivers/sqlite-base-driver.ts b/src/drivers/sqlite-base-driver.ts index e6be8ad..6895c44 100644 --- a/src/drivers/sqlite-base-driver.ts +++ b/src/drivers/sqlite-base-driver.ts @@ -51,6 +51,7 @@ export abstract class SqliteLikeBaseDriver extends CommonSQLImplement { optionalSchema: true, mismatchDetection: false, supportCreateUpdateTable: true, + supportCreateUpdateDatabase: false, dialect: "sqlite", }; } @@ -230,6 +231,10 @@ export abstract class SqliteLikeBaseDriver extends CommonSQLImplement { return generateSqlSchemaChange(change); } + createUpdateDatabaseSchema(): string[] { + throw new Error("Not implemented"); + } + override async findFirst( schemaName: string, tableName: string,