Files
tasks/tools/sql/conn.go
Alex ShtinandGitHub 8e8f1b0f7c Remove license header from every file (#7689)
## What changed?
<!-- Describe what has changed in this PR -->
Remove license header from every file. Because it is really hard to
follow in this PR here is the summary:
1. License header is removed from all `.go` and `.proto` files
:fireworks::fireworks:🎆.
2. `LICENSE` file in the root directory has only Temporal and Uber
copyrights.
3. 5 other `LICENSE` files added to the packages which have copyrights
different from Temporal and Uber: Datadog, Xargin, "Mat Ryer, Tyler
Bunnell and contributors".
4. `license_file` flag is removed from all code generation tools.
5. `copyright_file` flag is removed from `go:generate mockgen`
directive.
6. All copyright related targets are removed from `Makefile`.
7. Updated Temporal copyright year to 2025 everywhere.

## Why?
<!-- Tell your future self why have you made these changes -->
I double checked with legal department that it is not needed to have
license header in every file. One file per repo is enough. I put all
copyrights to the root `LICENSE` file and removed header from all other
files. Also updated tools and `Makefile`.
2025-05-01 18:50:21 -07:00

111 lines
2.9 KiB
Go

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
func NewConnection(cfg *config.SQL, logger log.Logger) (*Connection, error) {
db, err := sql.NewSQLAdminDB(sqlplugin.DbKindUnknown, cfg, resolver.NewNoopResolver(), logger, metrics.NoopMetricsHandler)
if err != nil {
return nil, err
}
return &Connection{
adminDb: db,
dbName: cfg.DatabaseName,
}, nil
}
// CreateSchemaVersionTables sets up the schema version tables
func (c *Connection) CreateSchemaVersionTables() error {
return c.adminDb.CreateSchemaVersionTables()
}
// ReadSchemaVersion returns the current schema version for the keyspace
func (c *Connection) ReadSchemaVersion() (string, error) {
return c.adminDb.ReadSchemaVersion(c.dbName)
}
// UpdateSchemaVersion updates the schema version for the keyspace
func (c *Connection) UpdateSchemaVersion(newVersion string, minCompatibleVersion string) error {
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 {
return c.adminDb.WriteSchemaUpdateLog(oldVersion, newVersion, manifestMD5, desc)
}
// Exec executes a sql statement
func (c *Connection) Exec(stmt string, args ...interface{}) error {
return c.adminDb.Exec(stmt, args...)
}
// ListTables returns a list of tables in this database
func (c *Connection) ListTables() ([]string, error) {
return c.adminDb.ListTables(c.dbName)
}
// DropTable drops a given table from the database
func (c *Connection) DropTable(name string) error {
return c.adminDb.DropTable(name)
}
// DropAllTables drops all tables from this database
func (c *Connection) DropAllTables() error {
tables, err := c.ListTables()
if err != nil {
return err
}
for _, tab := range tables {
if err := c.DropTable(tab); err != nil {
return err
}
}
return nil
}
// CreateDatabase creates a database if it doesn't exist
func (c *Connection) CreateDatabase(name string) error {
return c.adminDb.CreateDatabase(name)
}
// DropDatabase drops a database
func (c *Connection) DropDatabase(name string) error {
return c.adminDb.DropDatabase(name)
}
// Close closes the sql client
func (c *Connection) Close() {
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
}