Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
feat(frontend): add "database" field for PostgreSQL instances (#3729)
Liu Jic5f01aab258b
diff --git a/frontend/src/components/CreateInstanceForm.vue b/frontend/src/components/CreateInstanceForm.vueindex 49385ab655..45fc9ae857 100644--- a/frontend/src/components/CreateInstanceForm.vue+++ b/frontend/src/components/CreateInstanceForm.vue@@ -166,6 +166,24 @@/></div>+ <div v-if="showDatabase" class="sm:col-span-1 sm:col-start-1">+ <div class="flex flex-row items-center space-x-2">+ <label for="database" class="textlabel block">+ {{ $t("common.database") }}+ </label>+ </div>+ <input+ id="database"+ name="database"+ type="text"+ class="textfield mt-1 w-full"+ autocomplete="off"+ :placeholder="$t('common.database')"+ :value="state.instance.database"+ @input="handleInstanceDatabaseInput"+ />+ </div>+<div v-if="showSSL" class="sm:col-span-3 sm:col-start-1"><div class="flex flex-row items-center space-x-2"><label class="textlabel block">{{@@ -345,6 +363,10 @@ const showSSL = computed((): boolean => {return state.instance.engine === "CLICKHOUSE";});+const showDatabase = computed((): boolean => {+ return state.instance.engine === "POSTGRES";+});+const isInOnboaringCreateDatabaseGuide = computed(() => {const guideName = useOnboardingGuideStore().guideName;return guideName === "create-database";@@ -437,6 +459,10 @@ const handleInstancePasswordInput = (event: Event) => {updateInstance("password", (event.target as HTMLInputElement).value);};+const handleInstanceDatabaseInput = (event: Event) => {+ updateInstance("database", (event.target as HTMLInputElement).value);+};+const updateInstance = (field: string, value: string) => {let str = value;if (@@ -445,7 +471,8 @@ const updateInstance = (field: string, value: string) => {field === "port" ||field === "externalLink" ||field === "username" ||- field === "password"+ field === "password" ||+ field === "database") {str = value.trim();}@@ -534,6 +561,11 @@ const tryCreate = () => {// Conceptually, data source is the proper place to store connection info (thinking of DSN)const doCreate = () => {state.isCreatingInstance = true;++ if (state.instance.engine !== "POSTGRES") {+ // Clear the `database` field if not needed.+ state.instance.database = "";+ }useInstanceStore().createInstance(state.instance).then((createdInstance) => {@@ -562,6 +594,8 @@ const testConnection = () => {engine: instance.engine,username: instance.username,password: instance.password,+ // Use the `database` field only when needed.+ database: instance.engine === "POSTGRES" ? instance.database : undefined,useEmptyPassword: false,instanceId: undefined,};diff --git a/frontend/src/components/InstanceForm.vue b/frontend/src/components/InstanceForm.vueindex 3c9466b952..f59c36c286 100644--- a/frontend/src/components/InstanceForm.vue+++ b/frontend/src/components/InstanceForm.vue@@ -288,6 +288,21 @@</div></template>+ <div v-if="showDatabase" class="mt-2 sm:col-span-1 sm:col-start-1">+ <label for="database" class="textlabel block">+ {{ $t("common.database") }}+ </label>+ <input+ id="database"+ v-model="state.instance.database"+ name="database"+ type="text"+ class="textfield mt-1 w-full"+ :disabled="!allowEdit"+ :placeholder="$t('common.database')"+ />+ </div>+<div v-if="showSSL" class="mt-2 sm:col-span-3 sm:col-start-1"><div class="flex flex-row items-center"><label for="password" class="textlabel block">@@ -465,8 +480,9 @@ const connectionInfoChanged = computed(() => {}return (- state.instance.host != state.originalInstance.host ||- state.instance.port != state.originalInstance.port ||+ state.instance.host !== state.originalInstance.host ||+ state.instance.port !== state.originalInstance.port ||+ state.instance.database !== state.originalInstance.database ||!isEqual(state.originalInstance.dataSourceList,state.instance.dataSourceList@@ -524,6 +540,13 @@ const instanceLink = (instance: Instance): string => {return instance.host;};+const showDatabase = computed((): boolean => {+ return (+ state.instance.engine === "POSTGRES" &&+ currentDataSource.value.type === "ADMIN"+ );+});+const showSSL = computed((): boolean => {return state.instance.engine === "CLICKHOUSE";});@@ -754,6 +777,10 @@ const doUpdate = () => {patchedInstance.port = state.instance.port;instanceInfoChanged = true;}+ if (state.instance.database !== state.originalInstance.database) {+ patchedInstance.database = state.instance.database;+ instanceInfoChanged = true;+ }if (!isEqual(@@ -863,6 +890,7 @@ const testConnection = () => {useEmptyPassword: dataSource.useEmptyPassword,host: connectionHost,port: connectionPort,+ database: instance.database,instanceId: instance.id,};diff --git a/frontend/src/types/common.ts b/frontend/src/types/common.tsindex eb7410f936..b442cb77f3 100644--- a/frontend/src/types/common.ts+++ b/frontend/src/types/common.ts@@ -261,6 +261,7 @@ const makeUnknown = (type: ResourceType) => {engine: "MYSQL",engineVersion: "",host: "",+ database: "",};const UNKNOWN_DATABASE: Database = {@@ -712,6 +713,7 @@ const makeEmpty = (type: ResourceType) => {engine: "MYSQL",engineVersion: "",host: "",+ database: "",};const EMPTY_DATABASE: Database = {diff --git a/frontend/src/types/instance.ts b/frontend/src/types/instance.tsindex 3781e6d109..90f297ebea 100644--- a/frontend/src/types/instance.ts+++ b/frontend/src/types/instance.ts@@ -61,6 +61,7 @@ export type Instance = {engine: EngineType;engineVersion: string;externalLink?: string;+ database: string;host: string;port?: string;};@@ -75,6 +76,7 @@ export type InstanceCreate = {externalLink?: string;host: string;port?: string;+ database?: string;// In mysql, username can be empty which means anonymous userusername?: string;password?: string;@@ -92,6 +94,7 @@ export type InstancePatch = {externalLink?: string;host?: string;port?: string;+ database?: string;};export type MigrationSchemaStatus = "UNKNOWN" | "OK" | "NOT_EXIST";diff --git a/frontend/src/types/sql.ts b/frontend/src/types/sql.tsindex 5a2db5880e..5b97890172 100644--- a/frontend/src/types/sql.ts+++ b/frontend/src/types/sql.ts@@ -9,6 +9,7 @@ export type ConnectionInfo = {username?: string;password?: string;useEmptyPassword: boolean;+ database?: string;// Instance detail page has a Test Connection button, if user doesn't input new password, we// want the connection to use the existing password to test the connection, however, we do// not transfer the password back to client, thus we here pass the instanceId so the server