go.temporal.io/server/tools/sql/conn.go
110 LOC · 44 covered · 66 uncovered · 16 ranges · 55 concepts · 4 introducers · 27 tests
File neighbourhood
The centred file is linked to every concept that introduces one of its ranges, every test that runs code from the file, and the gray connector concepts standing between those tests and the file's own introducer concepts. Undirected links join concepts to every file where they introduce source and concepts to the tests they introduce; arrows show specialization between the displayed concepts and bridge only concepts omitted from this view. Concept colors match the source ranges below; connector concepts have no source color and are shown in gray.
Focused file, its introducer and connector concepts, their introduced files, and tests that run code from the file
In the embedded map, ordinary wheel input scrolls the page; use the visible controls to zoom and drag to pan. Open the full-screen map for canvas navigation: wheel pans, Ctrl/Command plus wheel zooms, and arrow keys pan when this region is focused. On touch screens, open the full-screen map to pan or pinch. If JavaScript or WebGL is unavailable, use the related-file, concept, and source links on this page.
Graph controls are ready.
Interactive rendering requires JavaScript and WebGL. Use the related-file, concept, and source links on this page while the interactive map is unavailable.
package sql
import (
"go.temporal.io/server/common/config"
"go.temporal.io/server/common/log"
"go.temporal.io/server/common/metrics"
"go.temporal.io/server/common/persistence/sql"
"go.temporal.io/server/common/persistence/sql/sqlplugin"
"go.temporal.io/server/common/resolver"
"go.temporal.io/server/tools/common/schema"
)
type (
// Connection is the connection to database
Connection struct {
dbName string
adminDb sqlplugin.AdminDB
}
)
const dbType = "sql"
var _ schema.DB = (*Connection)(nil)
// NewConnection creates a new connection to database
db, err := sql.NewSQLAdminDB(sqlplugin.DbKindUnknown, cfg, resolver.NewNoopResolver(), logger, metrics.NoopMetricsHandler)
if err != nil {
return nil, err
}
adminDb: db,
dbName: cfg.DatabaseName,
}, nil
}
// CreateSchemaVersionTables sets up the schema version tables
return c.adminDb.CreateSchemaVersionTables()
}
// ReadSchemaVersion returns the current schema version for the keyspace
return c.adminDb.ReadSchemaVersion(c.dbName)
}
// UpdateSchemaVersion updates the schema version for the keyspace
func (c *Connection) UpdateSchemaVersion(newVersion string, minCompatibleVersion string) error {
conn.go ×8
return c.adminDb.UpdateSchemaVersion(c.dbName, newVersion, minCompatibleVersion)
}
// WriteSchemaUpdateLog adds an entry to the schema update history table
func (c *Connection) WriteSchemaUpdateLog(oldVersion string, newVersion string, manifestMD5 string, desc string) error {
conn.go ×8
return c.adminDb.WriteSchemaUpdateLog(oldVersion, newVersion, manifestMD5, desc)
}
// Exec executes a sql statement
return c.adminDb.Exec(stmt, args...)
}
// ListTables returns a list of tables in this database
return c.adminDb.ListTables(c.dbName)
}
// DropTable drops a given table from the database
return c.adminDb.DropTable(name)
}
// DropAllTables drops all tables from this database
tables, err := c.ListTables()
if err != nil {
return err
}
return err
}
}
}
// CreateDatabase creates a database if it doesn't exist
return c.adminDb.CreateDatabase(name)
}
// DropDatabase drops a database
return c.adminDb.DropDatabase(name)
}
// Close closes the sql client
if c.adminDb != nil {
err := c.adminDb.Close()
if err != nil {
panic("cannot close connection")
}
}
}
// Type gives the type of db
func (c *Connection) Type() string {
return dbType
}