Skip to content

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

chore: support AlloyDB (#8319)

Danny Xu133d28fa9453
diff --git a/backend/api/v1/instance_service.go b/backend/api/v1/instance_service.go
index 060535ef02..abde755aad 100644
--- a/backend/api/v1/instance_service.go
+++ b/backend/api/v1/instance_service.go
@@ -306,7 +306,7 @@ func (s *InstanceService) syncSlowQueriesImpl(ctx context.Context, project *stor
if database.SyncState != api.OK {
continue
}
- if _, exists := pg.ExcludedDatabaseList[database.DatabaseName]; exists {
+ if pg.IsSystemDatabase(database.DatabaseName) {
continue
}
if err := func() error {
diff --git a/backend/api/v1/sql_service.go b/backend/api/v1/sql_service.go
index 9aea3c80a0..5b009bb93f 100644
--- a/backend/api/v1/sql_service.go
+++ b/backend/api/v1/sql_service.go
@@ -1333,21 +1333,13 @@ func allPostgresSystemObjects(statement string) bool {
slog.Debug("Failed to extract resource list from statement", slog.String("statement", statement), log.BBError(err))
return false
}
- systemSchemas := make(map[string]bool)
- for _, schema := range pg.SystemSchemaList {
- systemSchemas[schema] = true
- }
- systemTables := make(map[string]bool)
- for _, table := range pg.SystemTableList {
- systemTables[table] = true
- }
for _, resource := range resources {
- if systemSchemas[resource.Schema] {
+ if pg.IsSystemSchema(resource.Schema) {
continue
}
// If schema is not specified, user can access the pg_catalog schema if the table is pg_catalog's system table.
// So we need to check this case.
- if resource.Schema == "" && systemTables[resource.Table] {
+ if resource.Schema == "" && pg.IsSystemTable(resource.Table) {
continue
}
return false
diff --git a/backend/plugin/db/pg/dump.go b/backend/plugin/db/pg/dump.go
index bf60cf3ab7..83fa3ce856 100644
--- a/backend/plugin/db/pg/dump.go
+++ b/backend/plugin/db/pg/dump.go
@@ -49,7 +49,7 @@ func (driver *Driver) Dump(ctx context.Context, out io.Writer, schemaOnly bool)
dumpableDbNames = []string{driver.databaseName}
} else {
for _, n := range databases {
- if ExcludedDatabaseList[n.Name] {
+ if IsSystemDatabase(n.Name) {
continue
}
dumpableDbNames = append(dumpableDbNames, n.Name)
diff --git a/backend/plugin/db/pg/pg.go b/backend/plugin/db/pg/pg.go
index d465e64898..941a3c3e83 100644
--- a/backend/plugin/db/pg/pg.go
+++ b/backend/plugin/db/pg/pg.go
@@ -31,22 +31,6 @@ import (
)
var (
- // ExcludedDatabaseList is the list of system or internal databases.
- 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,
- }
-
// driverName is the driver name that our driver dependence register, now is "pgx".
driverName = "pgx"
diff --git a/backend/plugin/db/pg/role.go b/backend/plugin/db/pg/role.go
index 5674e5fc64..d6b09cada4 100644
--- a/backend/plugin/db/pg/role.go
+++ b/backend/plugin/db/pg/role.go
@@ -362,6 +362,9 @@ func (driver *Driver) getInstanceRoles(ctx context.Context) ([]*storepb.Instance
); err != nil {
return nil, err
}
+ if IsSystemUser(role) {
+ continue
+ }
var attributes []string
if super {
diff --git a/backend/plugin/db/pg/sync.go b/backend/plugin/db/pg/sync.go
index 87253e367b..8b9c2a992b 100644
--- a/backend/plugin/db/pg/sync.go
+++ b/backend/plugin/db/pg/sync.go
@@ -5,7 +5,6 @@ import (
"database/sql"
"fmt"
"regexp"
- "sort"
"strings"
"time"
@@ -23,110 +22,6 @@ import (
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
)
-// SystemSchemaList is the list of system schemas that we will exclude from the schema sync.
-var SystemSchemaList = []string{
- "information_schema",
- "pg_catalog",
- "pg_toast",
- "_timescaledb_cache",
- "_timescaledb_catalog",
- "_timescaledb_internal",
- "_timescaledb_config",
- "timescaledb_information",
- "timescaledb_experimental",
-}
-
-// SystemTableList is the list of system tables that we will exclude from the schema sync.
-var SystemTableList = []string{
- "pg_aggregate",
- "pg_am",
- "pg_amop",
- "pg_amproc",
- "pg_attrdef",
- "pg_attribute",
- "pg_authid",
- "pg_auth_members",
- "pg_cast",
- "pg_class",
- "pg_collation",
- "pg_constraint",
- "pg_conversion",
- "pg_database",
- "pg_db_role_setting",
- "pg_default_acl",
- "pg_depend",
- "pg_description",
- "pg_enum",
- "pg_event_trigger",
- "pg_extension",
- "pg_foreign_data_wrapper",
- "pg_foreign_server",
- "pg_foreign_table",
- "pg_index",
- "pg_inherits",
- "pg_init_privs",
- "pg_language",
- "pg_largeobject",
- "pg_largeobject_metadata",
- "pg_namespace",
- "pg_opclass",
- "pg_operator",
- "pg_opfamily",
- "pg_parameter_acl",
- "pg_partitioned_table",
- "pg_policy",
- "pg_proc",
- "pg_publication",
- "pg_publication_namespace",
- "pg_publication_rel",
- "pg_range",
- "pg_replication_origin",
- "pg_rewrite",
- "pg_seclabel",
- "pg_sequence",
- "pg_shdepend",
- "pg_shdescription",
- "pg_shseclabel",
- "pg_statistic",
- "pg_statistic_ext",
- "pg_statistic_ext_data",
- "pg_subscription",
- "pg_subscription_rel",
- "pg_tablespace",
- "pg_transform",
- "pg_trigger",
- "pg_ts_config",
- "pg_ts_config_map",
- "pg_ts_dict",
- "pg_ts_parser",
- "pg_ts_template",
- "pg_type",
- "pg_user_mapping",
- "pg_stat_activity",
- "pg_stat_replication",
- "pg_stat_replication_slots",
- "pg_stat_wal_receiver",
- "pg_stat_recovery_prefetch",
- "pg_stat_subscription",
- "pg_stat_subscription_stats",
- "pg_stat_ssl",
- "pg_stat_gssapi",
- "pg_stat_archiver",
- "pg_stat_bgwriter",
- "pg_stat_wal",
- "pg_stat_database",
- "pg_stat_database_conflicts",
- "pg_stat_all_tables",
- "pg_stat_all_indexes",
- "pg_statio_all_tables",
- "pg_statio_all_indexes",
- "pg_statio_all_sequences",
- "pg_stat_user_functions",
- "pg_stat_slru",
-}
-
-const systemSchemas = "'information_schema', 'pg_catalog', 'pg_toast', '_timescaledb_cache', '_timescaledb_catalog', '_timescaledb_internal', '_timescaledb_config', 'timescaledb_information', 'timescaledb_experimental'"
-
// SyncInstance syncs the instance.
func (driver *Driver) SyncInstance(ctx context.Context) (*db.InstanceMetadata, error) {
version, err := driver.getVersion(ctx)
@@ -148,7 +43,7 @@ func (driver *Driver) SyncInstance(ctx context.Context) (*db.InstanceMetadata, e
var filteredDatabases []*storepb.DatabaseSchemaMetadata
for _, database := range databases {
// Skip all system databases
- if _, ok := ExcludedDatabaseList[database.Name]; ok {
+ if IsSystemDatabase(database.Name) {
continue
}
filteredDatabases = append(filteredDatabases, database)
@@ -186,7 +81,7 @@ func (driver *Driver) SyncDBSchema(ctx context.Context) (*storepb.DatabaseSchema
}
defer txn.Rollback()
- schemaList, err := getSchemas(txn)
+ schemas, err := getSchemas(txn)
if err != nil {
return nil, errors.Wrapf(err, "failed to get schemas from database %q", driver.databaseName)
}
@@ -212,22 +107,7 @@ func (driver *Driver) SyncDBSchema(ctx context.Context) (*storepb.DatabaseSchema
return nil, err
}
- schemaNameMap := make(map[string]bool)
- for _, schemaName := range schemaList {
- schemaNameMap[schemaName] = true
- }
- for schemaName := range tableMap {
- schemaNameMap[schemaName] = true
- }
- for schemaName := range viewMap {
- schemaNameMap[schemaName] = true
- }
- var schemaNames []string
- for schemaName := range schemaNameMap {
- schemaNames = append(schemaNames, schemaName)
- }
- sort.Strings(schemaNames)
- for _, schemaName := range schemaNames {
+ for _, schemaName := range schemas {
var tables []*storepb.TableMetadata
var views []*storepb.ViewMetadata
var functions []*storepb.FunctionMetadata
@@ -270,7 +150,7 @@ FROM
WHERE
n.nspname NOT IN(%s)
AND c.contype = 'f'
-ORDER BY fk_schema, fk_table, fk_name;`, systemSchemas)
+ORDER BY fk_schema, fk_table, fk_name;`, systemSchemaWhereClause)
func getForeignKeys(txn *sql.Tx) (map[db.TableKey][]*storepb.ForeignKeyMetadata, error) {
foreignKeysMap := make(map[db.TableKey][]*storepb.ForeignKeyMetadata)
@@ -388,7 +268,7 @@ var listSchemaQuery = fmt.Sprintf(`
SELECT nspname
FROM pg_catalog.pg_namespace
WHERE nspname NOT IN (%s);
-`, systemSchemas)
+`, systemSchemaWhereClause)
func getSchemas(txn *sql.Tx) ([]string, error) {
rows, err := txn.Query(listSchemaQuery)
@@ -403,6 +283,9 @@ func getSchemas(txn *sql.Tx) ([]string, error) {
if err := rows.Scan(&schemaName); err != nil {
return nil, err
}
+ if IsSystemSchema(schemaName) {
+ continue
+ }
result = append(result, schemaName)
}
if err := rows.Err(); err != nil {
@@ -421,7 +304,7 @@ SELECT tbl.schemaname, tbl.tablename,
FROM pg_catalog.pg_tables tbl
LEFT JOIN pg_class as pc ON pc.oid = format('%s.%s', quote_ident(tbl.schemaname), quote_ident(tbl.tablename))::regclass` + fmt.Sprintf(`
WHERE tbl.schemaname NOT IN (%s)
-ORDER BY tbl.schemaname, tbl.tablename;`, systemSchemas)
+ORDER BY tbl.schemaname, tbl.tablename;`, systemSchemaWhereClause)
// getTables gets all tables of a database.
func getTables(txn *sql.Tx) (map[string][]*storepb.TableMetadata, error) {
@@ -447,12 +330,14 @@ func getTables(txn *sql.Tx) (map[string][]*storepb.TableMetadata, error) {
for rows.Next() {
table := &storepb.TableMetadata{}
- // var tbl tableSchema
var schemaName string
var comment sql.NullString
if err := rows.Scan(&schemaName, &table.Name, &table.DataSize, &table.IndexSize, &table.RowCount, &comment); err != nil {
return nil, err
}
+ if IsSystemTable(table.Name) {
+ continue
+ }
if comment.Valid {
table.Comment = comment.String
}
@@ -485,7 +370,7 @@ SELECT
pg_catalog.col_description(format('%s.%s', quote_ident(table_schema), quote_ident(table_name))::regclass, cols.ordinal_position::int) as column_comment
FROM INFORMATION_SCHEMA.COLUMNS AS cols` + fmt.Sprintf(`
WHERE cols.table_schema NOT IN (%s)
-ORDER BY cols.table_schema, cols.table_name, cols.ordinal_position;`, systemSchemas)
+ORDER BY cols.table_schema, cols.table_name, cols.ordinal_position;`, systemSchemaWhereClause)
// getTableColumns gets the columns of a table.
func getTableColumns(txn *sql.Tx) (map[db.TableKey][]*storepb.ColumnMetadata, error) {
@@ -531,7 +416,7 @@ func getTableColumns(txn *sql.Tx) (map[db.TableKey][]*storepb.ColumnMetadata, er
var listViewQuery = `
SELECT schemaname, viewname, definition, obj_description(format('%s.%s', quote_ident(schemaname), quote_ident(viewname))::regclass) FROM pg_catalog.pg_views` + fmt.Sprintf(`
-WHERE schemaname NOT IN (%s);`, systemSchemas)
+WHERE schemaname NOT IN (%s);`, systemSchemaWhereClause)
// getViews gets all views of a database.
func getViews(txn *sql.Tx) (map[string][]*storepb.ViewMetadata, error) {
@@ -549,6 +434,11 @@ func getViews(txn *sql.Tx) (map[string][]*storepb.ViewMetadata, error) {
if err := rows.Scan(&schemaName, &view.Name, &def, &comment); err != nil {
return nil, err
}
+ // Skip system views.
+ if IsSystemView(view.Name) {
+ continue
+ }
+
// Return error on NULL view definition.
// https://github.com/bytebase/bytebase/issues/343
if !def.Valid {
@@ -637,9 +527,13 @@ func getExtensions(txn *sql.Tx) ([]*storepb.ExtensionMetadata, error) {
defer rows.Close()
for rows.Next() {
e := &storepb.ExtensionMetadata{}
- if err := rows.Scan(&e.Name, &e.Version, &e.Schema, &e.Description); err != nil {
+ var description sql.NullString
+ if err := rows.Scan(&e.Name, &e.Version, &e.Schema, &description); err != nil {
return nil, err
}
+ if description.Valid {
+ e.Description = description.String
+ }
extensions = append(extensions, e)
}
if err := rows.Err(); err != nil {
@@ -659,7 +553,7 @@ SELECT idx.schemaname, idx.tablename, idx.indexname, idx.indexdef, (SELECT 1
AND constraint_type = 'PRIMARY KEY') AS primary,
obj_description(format('%s.%s', quote_ident(idx.schemaname), quote_ident(idx.indexname))::regclass) AS comment` + fmt.Sprintf(`
FROM pg_indexes AS idx WHERE idx.schemaname NOT IN (%s)
-ORDER BY idx.schemaname, idx.tablename, idx.indexname;`, systemSchemas)
+ORDER BY idx.schemaname, idx.tablename, idx.indexname;`, systemSchemaWhereClause)
// getIndexes gets all indices of a database.
func getIndexes(txn *sql.Tx) (map[db.TableKey][]*storepb.IndexMetadata, error) {
@@ -731,7 +625,7 @@ left join pg_namespace n on p.pronamespace = n.oid
left join pg_language l on p.prolang = l.oid
left join pg_type t on t.oid = p.prorettype ` + fmt.Sprintf(`
where n.nspname not in (%s)
-order by function_schema, function_name;`, systemSchemas)
+order by function_schema, function_name;`, systemSchemaWhereClause)
// getFunctions gets all functions of a database.
func getFunctions(txn *sql.Tx) (map[string][]*storepb.FunctionMetadata, error) {
@@ -749,7 +643,7 @@ func getFunctions(txn *sql.Tx) (map[string][]*storepb.FunctionMetadata, error) {
return nil, err
}
// Skip internal functions.
- if strings.Contains(function.Definition, "$libdir/timescaledb") {
+ if IsSystemFunctions(function.Name, function.Definition) {
continue
}
diff --git a/backend/plugin/db/pg/system_objects.go b/backend/plugin/db/pg/system_objects.go
new file mode 100644
index 0000000000..6f2d62fce2
--- /dev/null
+++ b/backend/plugin/db/pg/system_objects.go
@@ -0,0 +1,197 @@
+package pg
+
+import (
+ "fmt"
+ "strings"
+)
+
+var (
+ // systemDatabases is the list of system or internal databases.
+ systemDatabases = 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,
+ "alloydbadmin": true,
+ // system templates.
+ "template0": true,
+ "template1": true,
+ }
+
+ // systemSchemas is the list of system schemas that we will exclude from the schema sync.
+ systemSchemas = map[string]bool{
+ "information_schema": true,
+ "pg_catalog": true,
+ "pg_toast": true,
+ "_timescaledb_cache": true,
+ "_timescaledb_catalog": true,
+ "_timescaledb_internal": true,
+ "_timescaledb_config": true,
+ "timescaledb_information": true,
+ "timescaledb_experimental": true,
+ }
+
+ // systemTables is the list of system tables that we will exclude from the schema sync.
+ systemTables = map[string]bool{
+ "pg_aggregate": true,
+ "pg_am": true,
+ "pg_amop": true,
+ "pg_amproc": true,
+ "pg_attrdef": true,
+ "pg_attribute": true,
+ "pg_authid": true,
+ "pg_auth_members": true,
+ "pg_cast": true,
+ "pg_class": true,
+ "pg_collation": true,
+ "pg_constraint": true,
+ "pg_conversion": true,
+ "pg_database": true,
+ "pg_db_role_setting": true,
+ "pg_default_acl": true,
+ "pg_depend": true,
+ "pg_description": true,
+ "pg_enum": true,
+ "pg_event_trigger": true,
+ "pg_extension": true,
+ "pg_foreign_data_wrapper": true,
+ "pg_foreign_server": true,
+ "pg_foreign_table": true,
+ "pg_index": true,
+ "pg_inherits": true,
+ "pg_init_privs": true,
+ "pg_language": true,
+ "pg_largeobject": true,
+ "pg_largeobject_metadata": true,
+ "pg_namespace": true,
+ "pg_opclass": true,
+ "pg_operator": true,
+ "pg_opfamily": true,
+ "pg_parameter_acl": true,
+ "pg_partitioned_table": true,
+ "pg_policy": true,
+ "pg_proc": true,
+ "pg_publication": true,
+ "pg_publication_namespace": true,
+ "pg_publication_rel": true,
+ "pg_range": true,
+ "pg_replication_origin": true,
+ "pg_rewrite": true,
+ "pg_seclabel": true,
+ "pg_sequence": true,
+ "pg_shdepend": true,
+ "pg_shdescription": true,
+ "pg_shseclabel": true,
+ "pg_statistic": true,
+ "pg_statistic_ext": true,
+ "pg_statistic_ext_data": true,
+ "pg_subscription": true,
+ "pg_subscription_rel": true,
+ "pg_tablespace": true,
+ "pg_transform": true,
+ "pg_trigger": true,
+ "pg_ts_config": true,
+ "pg_ts_config_map": true,
+ "pg_ts_dict": true,
+ "pg_ts_parser": true,
+ "pg_ts_template": true,
+ "pg_type": true,
+ "pg_user_mapping": true,
+ "pg_stat_activity": true,
+ "pg_stat_replication": true,
+ "pg_stat_replication_slots": true,
+ "pg_stat_wal_receiver": true,
+ "pg_stat_recovery_prefetch": true,
+ "pg_stat_subscription": true,
+ "pg_stat_subscription_stats": true,
+ "pg_stat_ssl": true,
+ "pg_stat_gssapi": true,
+ "pg_stat_archiver": true,
+ "pg_stat_bgwriter": true,
+ "pg_stat_wal": true,
+ "pg_stat_database": true,
+ "pg_stat_database_conflicts": true,
+ "pg_stat_all_tables": true,
+ "pg_stat_all_indexes": true,
+ "pg_statio_all_tables": true,
+ "pg_statio_all_indexes": true,
+ "pg_statio_all_sequences": true,
+ "pg_stat_user_functions": true,
+ "pg_stat_slru": true,
+ }
+
+ systemSchemaWhereClause = func() string {
+ var schemas []string
+ for schema := range systemSchemas {
+ schemas = append(schemas, fmt.Sprintf("'%s'", schema))
+ }
+ return strings.Join(schemas, ",")
+ }()
+)
+
+func IsSystemUser(user string) bool {
+ return strings.HasPrefix(user, "alloydb")
+}
+
+func IsSystemDatabase(database string) bool {
+ _, ok := systemDatabases[database]
+ return ok
+}
+
+func IsSystemSchema(schema string) bool {
+ _, ok := systemSchemas[schema]
+ return ok
+}
+func IsSystemTable(table string) bool {
+ _, ok := systemTables[table]
+ return ok
+}
+
+func IsSystemView(view string) bool {
+ if strings.HasPrefix(view, "g_columnar_") {
+ return true
+ }
+ if strings.HasPrefix(view, "google_db_advisor_") {
+ return true
+ }
+ if strings.HasPrefix(view, "g_agg_stat_") {
+ return true
+ }
+ if strings.HasPrefix(view, "g_agg_stat_") {
+ return true
+ }
+ if strings.HasPrefix(view, "hypopg") {
+ return true
+ }
+ return false
+}
+
+func IsSystemFunctions(function, definition string) bool {
+ if strings.HasPrefix(function, "g_columnar_") {
+ return true
+ }
+ if strings.HasPrefix(function, "google_columnar_") {
+ return true
+ }
+ if strings.HasPrefix(function, "google_db_advisor_") {
+ return true
+ }
+ if strings.HasPrefix(function, "g_agg_stat_") {
+ return true
+ }
+ if strings.HasPrefix(function, "hypopg") {
+ return true
+ }
+ if function == "pg_stat_statements_wrapper" {
+ return true
+ }
+ if strings.Contains(definition, "$libdir/timescaledb") {
+ return true
+ }
+ return false
+}
diff --git a/backend/plugin/parser/sql/differ/pg/differ.go b/backend/plugin/parser/sql/differ/pg/differ.go
index 5f5c3fd606..c51df8632b 100644
--- a/backend/plugin/parser/sql/differ/pg/differ.go
+++ b/backend/plugin/parser/sql/differ/pg/differ.go
@@ -17,8 +17,7 @@ import (
)
var (
- _ differ.SchemaDiffer = (*SchemaDiffer)(nil)
- systemSchemas map[string]bool
+ _ differ.SchemaDiffer = (*SchemaDiffer)(nil)
)
func init() {
@@ -234,7 +233,7 @@ func newTypeInfo(id int, createType *ast.CreateTypeStmt) *typeInfo {
}
func (m schemaMap) addTable(id int, table *ast.CreateTableStmt) error {
- if _, exists := systemSchemas[table.Name.Schema]; exists {
+ if pg.IsSystemSchema(table.Name.Schema) {
return nil
}
schema, exists := m[table.Name.Schema]
@@ -254,7 +253,7 @@ func (m schemaMap) getTable(schemaName string, tableName string) *tableInfo {
}
func (m schemaMap) addConstraint(id int, addConstraint *ast.AddConstraintStmt) error {
- if _, exists := systemSchemas[addConstraint.Table.Schema]; exists {
+ if pg.IsSystemSchema(addConstraint.Table.Schema) {
return nil
}
schema, exists := m[addConstraint.Table.Schema]
@@ -286,7 +285,7 @@ func (m schemaMap) getConstraint(schemaName string, tableName string, constraint
}
func (m schemaMap) addExtension(id int, extension *ast.CreateExtensionStmt) error {
- if _, exists := systemSchemas[extension.Schema]; exists {
+ if pg.IsSystemSchema(extension.Schema) {
return nil
}
schema, exists := m[extension.Schema]
@@ -306,7 +305,7 @@ func (m schemaMap) getExtension(schemaName string, extensionName string) *extens
}
func (m schemaMap) addFunction(id int, function *ast.CreateFunctionStmt) error {
- if _, exists := systemSchemas[function.Function.Schema]; exists {
+ if pg.IsSystemSchema(function.Function.Schema) {
return nil
}
schema, exists := m[function.Function.Schema]
@@ -330,7 +329,7 @@ func (m schemaMap) getFunction(schemaName string, signature string) *functionInf
}
func (m schemaMap) addIndex(id int, index *ast.CreateIndexStmt) error {
- if _, exists := systemSchemas[index.Index.Table.Schema]; exists {
+ if pg.IsSystemSchema(index.Index.Table.Schema) {
return nil
}
schema, exists := m[index.Index.Table.Schema]
@@ -350,7 +349,7 @@ func (m schemaMap) getIndex(schemaName string, indexName string) *indexInfo {
}
func (m schemaMap) addSequence(id int, sequence *ast.CreateSequenceStmt) error {
- if _, exists := systemSchemas[sequence.SequenceDef.SequenceName.Schema]; exists {
+ if pg.IsSystemSchema(sequence.SequenceDef.SequenceName.Schema) {
return nil
}
schema, exists := m[sequence.SequenceDef.SequenceName.Schema]
@@ -370,7 +369,7 @@ func (m schemaMap) getSequence(schemaName string, sequenceName string) *sequence
}
func (m schemaMap) addTrigger(id int, trigger *ast.CreateTriggerStmt) error {
- if _, exists := systemSchemas[trigger.Trigger.Table.Schema]; exists {
+ if pg.IsSystemSchema(trigger.Trigger.Table.Schema) {
return nil
}
schema, exists := m[trigger.Trigger.Table.Schema]
@@ -398,7 +397,7 @@ func (m schemaMap) getTrigger(schemaName string, tableName string, triggerName s
}
func (m schemaMap) addType(id int, createType *ast.CreateTypeStmt) error {
- if _, exists := systemSchemas[createType.Type.TypeName().Schema]; exists {
+ if pg.IsSystemSchema(createType.Type.TypeName().Schema) {
return nil
}
schema, exists := m[createType.Type.TypeName().Schema]
@@ -439,7 +438,7 @@ func (m schemaMap) addSequenceOwnedBy(id int, alterStmt *ast.AlterSequenceStmt)
return errors.Errorf("expect OwnedBy only, but found %v", alterStmt)
}
- if _, exists := systemSchemas[alterStmt.Name.Schema]; exists {
+ if pg.IsSystemSchema(alterStmt.Name.Schema) {
return nil
}
schema, exists := m[alterStmt.Name.Schema]
@@ -548,10 +547,6 @@ func (*SchemaDiffer) SchemaDiff(oldStmt, newStmt string, _ bool) (string, error)
if err != nil {
return "", errors.Wrapf(err, "failed to and preprocess new statements %q", newStmt)
}
- systemSchemas = make(map[string]bool)
- for _, schema := range pg.SystemSchemaList {
- systemSchemas[schema] = true
- }
oldSchemaMap := make(schemaMap)
oldSchemaMap["public"] = newSchemaInfo(-1, &ast.CreateSchemaStmt{Name: "public"})
oldSchemaMap["public"].existsInNew = true
@@ -644,7 +639,7 @@ func (*SchemaDiffer) SchemaDiff(oldStmt, newStmt string, _ bool) (string, error)
if _, exists := newPartitionMap[fmt.Sprintf("%s.%s", stmt.Name.Schema, stmt.Name.Name)]; exists {
continue
}
- if _, exists := systemSchemas[stmt.Name.Schema]; exists {
+ if pg.IsSystemSchema(stmt.Name.Schema) {
continue
}
oldTable := oldSchemaMap.getTable(stmt.Name.Schema, stmt.Name.Name)
@@ -659,7 +654,7 @@ func (*SchemaDiffer) SchemaDiff(oldStmt, newStmt string, _ bool) (string, error)
return "", err
}
case *ast.CreateSchemaStmt:
- if _, exists := systemSchemas[stmt.Name]; exists {
+ if pg.IsSystemSchema(stmt.Name) {
continue
}
schema, hasSchema := oldSchemaMap[stmt.Name]
@@ -673,7 +668,7 @@ func (*SchemaDiffer) SchemaDiff(oldStmt, newStmt string, _ bool) (string, error)
if _, exists := newPartitionMap[fmt.Sprintf("%s.%s", stmt.Table.Schema, stmt.Table.Name)]; exists {
continue
}
- if _, exists := systemSchemas[stmt.Table.Schema]; exists {
+ if pg.IsSystemSchema(stmt.Table.Schema) {
continue
}
for _, alterItem := range stmt.AlterItemList {
@@ -713,7 +708,7 @@ func (*SchemaDiffer) SchemaDiff(oldStmt, newStmt string, _ bool) (string, error)
if _, exists := newPartitionMap[fmt.Sprintf("%s.%s", stmt.Index.Table.Schema, stmt.Index.Table.Name)]; exists {
continue
}
- if _, exists := systemSchemas[stmt.Index.Table.Schema]; exists {
+ if pg.IsSystemSchema(stmt.Index.Table.Schema) {
continue
}
oldIndex := oldSchemaMap.getIndex(stmt.Index.Table.Schema, stmt.Index.Name)
@@ -728,7 +723,7 @@ func (*SchemaDiffer) SchemaDiff(oldStmt, newStmt string, _ bool) (string, error)
return "", err
}
case *ast.CreateSequenceStmt:
- if _, exists := systemSchemas[stmt.SequenceDef.SequenceName.Schema]; exists {
+ if pg.IsSystemSchema(stmt.SequenceDef.SequenceName.Schema) {
continue
}
oldSequence := oldSchemaMap.getSequence(stmt.SequenceDef.SequenceName.Schema, stmt.SequenceDef.SequenceName.Name)
@@ -746,7 +741,7 @@ func (*SchemaDiffer) SchemaDiff(oldStmt, newStmt string, _ bool) (string, error)
if !onlySetOwnedBy(stmt) {
return "", errors.Errorf("expect OwnedBy only, but found %v", stmt)
}
- if _, exists := systemSchemas[stmt.Name.Schema]; exists {
+ if pg.IsSystemSchema(stmt.Name.Schema) {
continue
}
oldSequence := oldSchemaMap.getSequence(stmt.Name.Schema, stmt.Name.Name)
@@ -760,7 +755,7 @@ func (*SchemaDiffer) SchemaDiff(oldStmt, newStmt string, _ bool) (string, error)
return "", err
}
case *ast.CreateExtensionStmt:
- if _, exists := systemSchemas[stmt.Schema]; exists {
+ if pg.IsSystemSchema(stmt.Schema) {
continue
}
oldExtension := oldSchemaMap.getExtension(stmt.Schema, stmt.Name)
@@ -775,7 +770,7 @@ func (*SchemaDiffer) SchemaDiff(oldStmt, newStmt string, _ bool) (string, error)
return "", err
}
case *ast.CreateFunctionStmt:
- if _, exists := systemSchemas[stmt.Function.Schema]; exists {
+ if pg.IsSystemSchema(stmt.Function.Schema) {
continue
}
signature, err := functionSignature(stmt.Function)
@@ -794,7 +789,7 @@ func (*SchemaDiffer) SchemaDiff(oldStmt, newStmt string, _ bool) (string, error)
return "", err
}
case *ast.CreateTriggerStmt:
- if _, exists := systemSchemas[stmt.Trigger.Table.Schema]; exists {
+ if pg.IsSystemSchema(stmt.Trigger.Table.Schema) {
continue
}
oldTrigger := oldSchemaMap.getTrigger(stmt.Trigger.Table.Schema, stmt.Trigger.Table.Name, stmt.Trigger.Name)
@@ -809,7 +804,7 @@ func (*SchemaDiffer) SchemaDiff(oldStmt, newStmt string, _ bool) (string, error)
return "", err
}
case *ast.CreateTypeStmt:
- if _, exists := systemSchemas[stmt.Type.TypeName().Schema]; exists {
+ if pg.IsSystemSchema(stmt.Type.TypeName().Schema) {
continue
}
oldType := oldSchemaMap.getType(stmt.Type.TypeName().Schema, stmt.Type.TypeName().Name)
diff --git a/backend/runner/slowquerysync/syncer.go b/backend/runner/slowquerysync/syncer.go
index bd89eaae4c..82fb5d644e 100644
--- a/backend/runner/slowquerysync/syncer.go
+++ b/backend/runner/slowquerysync/syncer.go
@@ -154,7 +154,7 @@ func (s *Syncer) syncPostgreSQLSlowQuery(ctx context.Context, instance *store.In
if database.SyncState != api.OK {
continue
}
- if _, exists := pg.ExcludedDatabaseList[database.DatabaseName]; exists {
+ if pg.IsSystemDatabase(database.DatabaseName) {
continue
}
if err := func() error {