MCPcopy Create free account
hub / github.com/bytebase/bytebase / writeSchemaRules

Function writeSchemaRules

backend/plugin/schema/pg/get_database_definition.go:1667–1690  ·  view source on GitHub ↗

writeSchemaRules writes the rules of every table and the non-SELECT rules of every view in the schema (SELECT rules are part of the view definition). Rules on tables without column metadata are skipped; their definitions can reference the missing columns.

(out io.Writer, schema *storepb.SchemaMetadata)

Source from the content-addressed store, hash-verified

1665// definition). Rules on tables without column metadata are skipped; their
1666// definitions can reference the missing columns.
1667func writeSchemaRules(out io.Writer, schema *storepb.SchemaMetadata) error {
1668 for _, table := range schema.Tables {
1669 if len(table.Rules) > 0 && !tableMissingColumnMetadata(table) {
1670 if err := writeRules(out, schema.Name, table.Name, table.Rules); err != nil {
1671 return err
1672 }
1673 }
1674 }
1675
1676 for _, view := range schema.Views {
1677 var nonSelectRules []*storepb.RuleMetadata
1678 for _, rule := range view.Rules {
1679 if rule.Event != "SELECT" {
1680 nonSelectRules = append(nonSelectRules, rule)
1681 }
1682 }
1683 if len(nonSelectRules) > 0 {
1684 if err := writeRules(out, schema.Name, view.Name, nonSelectRules); err != nil {
1685 return err
1686 }
1687 }
1688 }
1689 return nil
1690}
1691
1692// writeSchemaForeignKeys writes the foreign keys of every table in the
1693// schema, skipping foreign keys touching a table without column metadata on

Callers 2

GetDatabaseDefinitionFunction · 0.85
GetSchemaDefinitionFunction · 0.85

Calls 2

writeRulesFunction · 0.85

Tested by

no test coverage detected