Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

chore: fix PG overriding the shared excludedDatabaseList (#2464)

Danny Xud0abedfd24c8
diff --git a/plugin/db/pg/dump.go b/plugin/db/pg/dump.go
index ac6bfe86fa..9252ddd90f 100644
--- a/plugin/db/pg/dump.go
+++ b/plugin/db/pg/dump.go
@@ -41,7 +41,7 @@ func (driver *Driver) Dump(ctx context.Context, database string, out io.Writer,
dumpableDbNames = []string{database}
} else {
for _, n := range databases {
- if systemDatabases[n.name] {
+ if excludedDatabaseList[n.name] {
continue
}
dumpableDbNames = append(dumpableDbNames, n.name)
diff --git a/plugin/db/pg/pg.go b/plugin/db/pg/pg.go
index 7ce5d0466d..3143732e16 100644
--- a/plugin/db/pg/pg.go
+++ b/plugin/db/pg/pg.go
@@ -19,10 +19,21 @@ import (
)
var (
- systemDatabases = map[string]bool{
+ excludedDatabaseList = map[string]bool{
+ // Skip our internal "bytebase" database
+ "bytebase": true,
+ // Skip internal databases from cloud service providers
+ // see https://github.com/bytebase/bytebase/issues/30
+ // aws
+ "rdsadmin": true,
+ // gcp
+ "cloudsql": true,
+ "cloudsqladmin": true,
+ // system templates.
"template0": true,
"template1": true,
}
+
createBytebaseDatabaseStmt = "CREATE DATABASE bytebase;"
// driverName is the driver name that our driver dependence register, now is "pgx".
diff --git a/plugin/db/pg/sync.go b/plugin/db/pg/sync.go
index e7c5c42dfc..624591e044 100644
--- a/plugin/db/pg/sync.go
+++ b/plugin/db/pg/sync.go
@@ -15,20 +15,6 @@ import (
"github.com/bytebase/bytebase/plugin/db/util"
)
-var (
- excludedDatabaseList = map[string]bool{
- // Skip our internal "bytebase" database
- "bytebase": true,
- // Skip internal databases from cloud service providers
- // see https://github.com/bytebase/bytebase/issues/30
- // aws
- "rdsadmin": true,
- // gcp
- "cloudsql": true,
- "cloudsqladmin": true,
- }
-)
-
// pgDatabaseSchema describes a pg database schema.
type pgDatabaseSchema struct {
name string
@@ -105,10 +91,6 @@ func (driver *Driver) SyncInstance(ctx context.Context) (*db.InstanceMeta, error
return nil, err
}
- // Skip all system databases
- for k := range systemDatabases {
- excludedDatabaseList[k] = true
- }
// Query db info
databases, err := driver.getDatabases(ctx)
if err != nil {
@@ -117,6 +99,7 @@ func (driver *Driver) SyncInstance(ctx context.Context) (*db.InstanceMeta, error
var databaseList []db.DatabaseMeta
for _, database := range databases {
dbName := database.name
+ // Skip all system databases
if _, ok := excludedDatabaseList[dbName]; ok {
continue
}