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

Method Dump

backend/plugin/db/hive/dump.go:59–163  ·  view source on GitHub ↗
(ctx context.Context, out io.Writer, _ *storepb.DatabaseSchemaMetadata)

Source from the content-addressed store, hash-verified

57}
58
59func (d *Driver) Dump(ctx context.Context, out io.Writer, _ *storepb.DatabaseSchemaMetadata) error {
60 if d.db == nil {
61 return errors.New("connection not initialized")
62 }
63
64 var builder strings.Builder
65
66 databaseName := d.config.ConnectionContext.DatabaseName
67 database, err := d.SyncDBSchema(ctx)
68 if err != nil {
69 return err
70 }
71 if len(database.Schemas) == 0 {
72 return errors.New("database schemas is empty")
73 }
74 schema := database.Schemas[0]
75
76 // Set current database
77 if _, err := d.db.ExecContext(ctx, fmt.Sprintf("USE %s", databaseName)); err != nil {
78 return errors.Wrap(err, "failed to set database")
79 }
80
81 // Dump managed tables
82 for _, table := range schema.GetTables() {
83 tableDDL, err := d.showCreateDDL(ctx, "TABLE", table.Name)
84 if err != nil {
85 return errors.Wrapf(err, "failed to dump table %s", table.Name)
86 }
87
88 // Dump indexes
89 for _, index := range table.GetIndexes() {
90 indexDDL, err := genIndexDDL(&IndexDDLOptions{
91 databaseName: databaseName,
92 indexName: index.Name,
93 tableName: table.Name,
94 indexType: index.Type,
95 colNames: index.Expressions,
96 isWithDeferredRebuild: true,
97 idxProperties: nil,
98 indexTableName: "",
99 rowFmt: "",
100 storedAs: "",
101 storedBy: "",
102 location: "",
103 tableProperties: nil,
104 comment: index.Comment,
105 })
106 if err != nil {
107 return errors.Wrapf(err, "failed to generate DDL for index %s", index.Name)
108 }
109
110 _, _ = fmt.Fprintf(&builder, schemaStmtFmt, "INDEX", fmt.Sprintf("`%s`", index.Name), indexDDL)
111 }
112 _, _ = builder.WriteString(tableDDL)
113 }
114
115 // Dump external tables
116 for _, extTable := range schema.GetExternalTables() {

Callers

nothing calls this directly

Implementers 15

MockDriverbackend/plugin/advisor/utils_for_tests
Driverbackend/plugin/db/bigquery/bigquery.go
Driverbackend/plugin/db/mongodb/mongodb.go
Driverbackend/plugin/db/trino/trino.go
Driverbackend/plugin/db/redshift/redshift.go
Driverbackend/plugin/db/oracle/oracle.go
Driverbackend/plugin/db/dynamodb/dynamodb.go
Driverbackend/plugin/db/cosmosdb/cosmosdb.go
Driverbackend/plugin/db/spanner/spanner.go
Driverbackend/plugin/db/mssql/mssql.go
Driverbackend/plugin/db/mysql/mysql.go
Driverbackend/plugin/db/pg/pg.go

Calls 10

SyncDBSchemaMethod · 0.95
showCreateDDLMethod · 0.95
genIndexDDLFunction · 0.85
genMaterializedViewDDLFunction · 0.70
StringMethod · 0.65
GetTablesMethod · 0.45
GetIndexesMethod · 0.45
GetExternalTablesMethod · 0.45
GetViewsMethod · 0.45
GetMaterializedViewsMethod · 0.45

Tested by

no test coverage detected