Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
chore: cleanup the existing sample instance logic (#4642)
Tianzhou (天舟)4105578fa213
diff --git a/backend/server/acl_casbin_policy_owner.csv b/backend/server/acl_casbin_policy_owner.csvindex 0d0368d0cd..72d3679163 100644--- a/backend/server/acl_casbin_policy_owner.csv+++ b/backend/server/acl_casbin_policy_owner.csv@@ -53,7 +53,7 @@ p, OWNER, /instance/{instanceID}/role/{roleName}, GETp, OWNER, /instance/{instanceID}/role/{roleName}, PATCHp, OWNER, /instance/{instanceID}/role/{roleName}, DELETEp, OWNER, /instances/{instanceName}/databases/{database}, PATCH-p, OWNER, /instance/new-embedded-pg, POST+p, OWNER, /instance/sample-pg, GETp, OWNER, /database, GETp, OWNER, /database/{databaseID}, GETp, OWNER, /database/{databaseID}, PATCHdiff --git a/backend/server/instance.go b/backend/server/instance.goindex 88177d29b8..4f25754f34 100644--- a/backend/server/instance.go+++ b/backend/server/instance.go@@ -4,7 +4,6 @@ import ("context""fmt""net/http"- "os""strconv""strings"@@ -490,28 +489,12 @@ func (s *Server) registerInstanceRoutes(g *echo.Group) {return nil})- // Initial and start an embedded postgres instance and there should be only one currently.- // Its port and dataDir are fixed values.- g.POST("/instance/new-embedded-pg", func(c echo.Context) error {- pgUser := "postgres"- port := 23333- dataDir := fmt.Sprintf("%s/%s", s.profile.DataDir, "tmp-pgdata")-- // If the data dir does not exist, then we will start a PostgreSQL instance with a fixed port temporarily.- if _, err := os.Stat(dataDir); os.IsNotExist(err) {- if err := postgres.InitDB(s.pgBinDir, dataDir, pgUser); err != nil {- return echo.NewHTTPError(http.StatusInternalServerError, "Failed to init embedded postgres database").SetInternal(err)- }-- if err := postgres.Start(port, s.pgBinDir, dataDir, false /* serverLog */); err != nil {- return echo.NewHTTPError(http.StatusInternalServerError, "Failed to start embedded postgres instance").SetInternal(err)- }- }-+ // Returns the sample embedded postgres instance connection info.+ g.GET("/instance/sample-pg", func(c echo.Context) error {return c.JSON(http.StatusOK, pgConnectionInfo{Host: common.GetPostgresSocketDir(),- Port: port,- Username: pgUser,+ Port: s.profile.SampleDatabasePort,+ Username: postgres.SampleUser,})})}diff --git a/frontend/src/components/CreateInstanceForm.vue b/frontend/src/components/CreateInstanceForm.vueindex 3f0a2886db..a37cf54d71 100644--- a/frontend/src/components/CreateInstanceForm.vue+++ b/frontend/src/components/CreateInstanceForm.vue@@ -336,9 +336,7 @@:ok-text="warningModalOkText":title="$t('instance.connection-info-seems-to-be-incorrect')":description="state.createInstanceWarning"- :in-progress="- shouldShowCreateEmbeddedPostgresButton && isCreatingEmbeddedInstance- "+ :in-progress="shouldShowAddSamplePostgresButton && isAddingSampleInstance":progress-text="$t('common.creating')"@ok="handleWarningModalOkClick"@cancel="state.showCreateInstanceWarningModal = false"@@ -431,9 +429,9 @@ const state = reactive<LocalState>({const mongodbConnectionStringSchemaList = ["mongodb://", "mongodb+srv://"];-const isCreatingEmbeddedInstance = ref(false);+const isAddingSampleInstance = ref(false);// For creating database onboarding guide, we only try to start our embedded sample postgres instance once.-const embeddedPostgresInstance = ref<Partial<InstanceCreate>>();+const samplePostgresInstance = ref<Partial<InstanceCreate>>();const allowCreate = computed(() => {if (state.instance.engine === "SPANNER") {@@ -489,8 +487,8 @@ const isInOnboaringCreateDatabaseGuide = computed(() => {return guideName === "create-database";});-const shouldShowCreateEmbeddedPostgresButton = computed(() => {- const tempInstance = embeddedPostgresInstance.value;+const shouldShowAddSamplePostgresButton = computed(() => {+ const tempInstance = samplePostgresInstance.value;return (isInOnboaringCreateDatabaseGuide.value &&(!tempInstance ||@@ -503,7 +501,7 @@ const shouldShowCreateEmbeddedPostgresButton = computed(() => {});const warningModalOkText = computed(() => {- if (shouldShowCreateEmbeddedPostgresButton.value) {+ if (shouldShowAddSamplePostgresButton.value) {return t("instance.add-a-postgresql-sample-instance");} else {return t("instance.ignore-and-create");@@ -603,13 +601,12 @@ const updateInstance = (field: string, value: string | boolean) => {};const handleWarningModalOkClick = async () => {- // When user get the warning of incorrect instance info in creating database onboarding guide,- // we'd like to display the `create an embedded PostgreSQL database` button instead of `ignore and create`.- if (shouldShowCreateEmbeddedPostgresButton.value) {- isCreatingEmbeddedInstance.value = true;- const connectionInfo =- await useInstanceStore().createEmbeddedPostgresInstance();- embeddedPostgresInstance.value = {+ // When user gets the warning of incorrect instance info in creating database onboarding guide,+ // we'd like to display the `add a sample PostgreSQL database` button instead of `ignore and create`.+ if (shouldShowAddSamplePostgresButton.value) {+ isAddingSampleInstance.value = true;+ const connectionInfo = await useInstanceStore().getSamplePostgresInstance();+ samplePostgresInstance.value = {engine: "POSTGRES",host: connectionInfo.host,port: String(connectionInfo.port),@@ -618,14 +615,14 @@ const handleWarningModalOkClick = async () => {};state.instance = {...state.instance,- ...embeddedPostgresInstance.value,+ ...samplePostgresInstance.value,};- isCreatingEmbeddedInstance.value = false;+ isAddingSampleInstance.value = false;pushNotification({module: "bytebase",style: "SUCCESS",title: t("common.success"),- description: t("instance.successfully-created-postgresql-instance"),+ description: t("instance.successfully-added-postgresql-instance"),// This is a bit magic to the user, so do not auto dismiss the notification.manualHide: true,});diff --git a/frontend/src/locales/en-US.json b/frontend/src/locales/en-US.jsonindex 8f32445155..9a7ab85bca 100644--- a/frontend/src/locales/en-US.json+++ b/frontend/src/locales/en-US.json@@ -771,7 +771,7 @@"test-connection": "Test Connection","ignore-and-create": "Ignore and create","add-a-postgresql-sample-instance": "Add a PostgreSQL sample instance instead",- "successfully-created-postgresql-instance": "Successfully created a PostgreSQL sample instance and filled connection info.",+ "successfully-added-postgresql-instance": "Successfully added a PostgreSQL sample instance and filled connection info.","connection-info-seems-to-be-incorrect": "Connection info seems to be incorrect","new-instance": "New Instance","unable-to-connect": "Bytebase is unable to connect the instance. We recommend you to review the connection info again. But it's OK to ignore this warning for now. You can still fix the connection info from the instance detail page after creation.\n\nError detail: {0}",diff --git a/frontend/src/locales/zh-CN.json b/frontend/src/locales/zh-CN.jsonindex fff06cfcd2..fde0130b32 100644--- a/frontend/src/locales/zh-CN.json+++ b/frontend/src/locales/zh-CN.json@@ -769,8 +769,8 @@"password-write-only": "YOUR_DB_PWD - 仅写入","test-connection": "测试连接","ignore-and-create": "忽略并创建",- "add-a-postgresql-sample-instance": "创建一个 PostgreSQL 样本实例",- "successfully-created-postgresql-instance": "成功创建了 PostgreSQL 样本实例。并且填好了连接信息。",+ "add-a-postgresql-sample-instance": "添加一个 PostgreSQL 样本实例",+ "successfully-added-postgresql-instance": "成功添加了 PostgreSQL 样本实例。并且填好了连接信息。","connection-info-seems-to-be-incorrect": "连接信息似乎错误","new-instance": "新实例","unable-to-connect": "Bytebase 无法连接到实例。我们推荐您再检查一遍连接信息。但也可以暂时忽略此警告。您在创建后仍能在实例详细页里修复连接信息。\n\n错误详情:{0}",diff --git a/frontend/src/store/modules/instance.ts b/frontend/src/store/modules/instance.tsindex 5c4d7bdbfe..582d966425 100644--- a/frontend/src/store/modules/instance.ts+++ b/frontend/src/store/modules/instance.ts@@ -453,13 +453,13 @@ export const useInstanceStore = defineStore("instance", {return historyList;},- async createEmbeddedPostgresInstance() {+ async getSamplePostgresInstance() {const data = (- await axios.post<{+ await axios.get<{host: string;port: number;username: string;- }>("/api/instance/new-embedded-pg")+ }>("/api/instance/sample-pg")).data;return data;