Add vendor directory and update vendorHash to null
This commit is contained in:
parent
523831cb8d
commit
1e5424c844
778 changed files with 407919 additions and 1 deletions
25
vendor/github.com/pressly/goose/v3/database/dialect/querier.go
generated
vendored
Normal file
25
vendor/github.com/pressly/goose/v3/database/dialect/querier.go
generated
vendored
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
package dialect
|
||||
|
||||
// Querier is the interface that wraps the basic methods to create a dialect specific query.
|
||||
//
|
||||
// It is intended tio be using with [database.NewStoreFromQuerier] to create a new [database.Store]
|
||||
// implementation based on a custom querier.
|
||||
type Querier interface {
|
||||
// CreateTable returns the SQL query string to create the db version table.
|
||||
CreateTable(tableName string) string
|
||||
// InsertVersion returns the SQL query string to insert a new version into the db version table.
|
||||
InsertVersion(tableName string) string
|
||||
// DeleteVersion returns the SQL query string to delete a version from the db version table.
|
||||
DeleteVersion(tableName string) string
|
||||
// GetMigrationByVersion returns the SQL query string to get a single migration by version.
|
||||
//
|
||||
// The query should return the timestamp and is_applied columns.
|
||||
GetMigrationByVersion(tableName string) string
|
||||
// ListMigrations returns the SQL query string to list all migrations in descending order by id.
|
||||
//
|
||||
// The query should return the version_id and is_applied columns.
|
||||
ListMigrations(tableName string) string
|
||||
// GetLatestVersion returns the SQL query string to get the last version_id from the db version
|
||||
// table. Returns a nullable int64 value.
|
||||
GetLatestVersion(tableName string) string
|
||||
}
|
||||
22
vendor/github.com/pressly/goose/v3/database/dialect/querier_extended.go
generated
vendored
Normal file
22
vendor/github.com/pressly/goose/v3/database/dialect/querier_extended.go
generated
vendored
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
package dialect
|
||||
|
||||
// QuerierExtender extends the [Querier] interface with optional database-specific optimizations.
|
||||
// While not required, implementing these methods can improve performance.
|
||||
//
|
||||
// IMPORTANT: This interface may be expanded in future versions. Implementors must be prepared to
|
||||
// update their implementations when new methods are added.
|
||||
//
|
||||
// Example compile-time check:
|
||||
//
|
||||
// var _ QuerierExtender = (*CustomQuerierExtended)(nil)
|
||||
//
|
||||
// In short, it's exported to allow implementors to have a compile-time check that they are
|
||||
// implementing the interface correctly.
|
||||
type QuerierExtender interface {
|
||||
Querier
|
||||
|
||||
// TableExists returns a database-specific SQL query to check if a table exists. For example,
|
||||
// implementations might query system catalogs like pg_tables or sqlite_master. Return empty
|
||||
// string if not supported.
|
||||
TableExists(tableName string) string
|
||||
}
|
||||
212
vendor/github.com/pressly/goose/v3/database/dialects.go
generated
vendored
Normal file
212
vendor/github.com/pressly/goose/v3/database/dialects.go
generated
vendored
Normal file
|
|
@ -0,0 +1,212 @@
|
|||
package database
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/pressly/goose/v3/database/dialect"
|
||||
"github.com/pressly/goose/v3/internal/dialects"
|
||||
)
|
||||
|
||||
// Dialect is the type of database dialect.
|
||||
type Dialect string
|
||||
|
||||
const (
|
||||
DialectCustom Dialect = ""
|
||||
DialectClickHouse Dialect = "clickhouse"
|
||||
DialectAuroraDSQL Dialect = "dsql"
|
||||
DialectMSSQL Dialect = "mssql"
|
||||
DialectMySQL Dialect = "mysql"
|
||||
DialectPostgres Dialect = "postgres"
|
||||
DialectRedshift Dialect = "redshift"
|
||||
DialectSQLite3 Dialect = "sqlite3"
|
||||
DialectStarrocks Dialect = "starrocks"
|
||||
DialectTiDB Dialect = "tidb"
|
||||
DialectTurso Dialect = "turso"
|
||||
DialectYdB Dialect = "ydb"
|
||||
|
||||
// DEPRECATED: Vertica support is deprecated and will be removed in a future release.
|
||||
DialectVertica Dialect = "vertica"
|
||||
)
|
||||
|
||||
// NewStore returns a new [Store] implementation for the given dialect.
|
||||
func NewStore(d Dialect, tableName string) (Store, error) {
|
||||
if d == DialectCustom {
|
||||
return nil, errors.New("custom dialect is not supported")
|
||||
}
|
||||
lookup := map[Dialect]dialect.Querier{
|
||||
DialectClickHouse: dialects.NewClickhouse(),
|
||||
DialectAuroraDSQL: dialects.NewAuroraDSQL(),
|
||||
DialectMSSQL: dialects.NewSqlserver(),
|
||||
DialectMySQL: dialects.NewMysql(),
|
||||
DialectPostgres: dialects.NewPostgres(),
|
||||
DialectRedshift: dialects.NewRedshift(),
|
||||
DialectSQLite3: dialects.NewSqlite3(),
|
||||
DialectStarrocks: dialects.NewStarrocks(),
|
||||
DialectTiDB: dialects.NewTidb(),
|
||||
DialectTurso: dialects.NewTurso(),
|
||||
DialectVertica: dialects.NewVertica(),
|
||||
DialectYdB: dialects.NewYDB(),
|
||||
}
|
||||
querier, ok := lookup[d]
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("unknown dialect: %q", d)
|
||||
}
|
||||
return NewStoreFromQuerier(tableName, querier)
|
||||
}
|
||||
|
||||
// NewStoreFromQuerier returns a new [Store] implementation for the given querier.
|
||||
//
|
||||
// Most of the time you should use [NewStore] instead of this function, as it will automatically
|
||||
// create a dialect-specific querier for you. This function is useful if you want to use a custom
|
||||
// querier that is not part of the standard dialects.
|
||||
func NewStoreFromQuerier(tableName string, querier dialect.Querier) (Store, error) {
|
||||
if tableName == "" {
|
||||
return nil, errors.New("table name must not be empty")
|
||||
}
|
||||
if querier == nil {
|
||||
return nil, errors.New("querier must not be nil")
|
||||
}
|
||||
return &store{
|
||||
tableName: tableName,
|
||||
querier: newQueryController(querier),
|
||||
}, nil
|
||||
}
|
||||
|
||||
type store struct {
|
||||
tableName string
|
||||
querier *queryController
|
||||
}
|
||||
|
||||
var _ Store = (*store)(nil)
|
||||
|
||||
func (s *store) Tablename() string {
|
||||
return s.tableName
|
||||
}
|
||||
|
||||
func (s *store) CreateVersionTable(ctx context.Context, db DBTxConn) error {
|
||||
q := s.querier.CreateTable(s.tableName)
|
||||
if _, err := db.ExecContext(ctx, q); err != nil {
|
||||
return fmt.Errorf("failed to create version table %q: %w", s.tableName, err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *store) Insert(ctx context.Context, db DBTxConn, req InsertRequest) error {
|
||||
q := s.querier.InsertVersion(s.tableName)
|
||||
if _, err := db.ExecContext(ctx, q, req.Version, true); err != nil {
|
||||
return fmt.Errorf("failed to insert version %d: %w", req.Version, err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *store) Delete(ctx context.Context, db DBTxConn, version int64) error {
|
||||
q := s.querier.DeleteVersion(s.tableName)
|
||||
if _, err := db.ExecContext(ctx, q, version); err != nil {
|
||||
return fmt.Errorf("failed to delete version %d: %w", version, err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *store) GetMigration(
|
||||
ctx context.Context,
|
||||
db DBTxConn,
|
||||
version int64,
|
||||
) (*GetMigrationResult, error) {
|
||||
q := s.querier.GetMigrationByVersion(s.tableName)
|
||||
var result GetMigrationResult
|
||||
if err := db.QueryRowContext(ctx, q, version).Scan(
|
||||
&result.Timestamp,
|
||||
&result.IsApplied,
|
||||
); err != nil {
|
||||
if errors.Is(err, sql.ErrNoRows) {
|
||||
return nil, fmt.Errorf("%w: %d", ErrVersionNotFound, version)
|
||||
}
|
||||
return nil, fmt.Errorf("failed to get migration %d: %w", version, err)
|
||||
}
|
||||
return &result, nil
|
||||
}
|
||||
|
||||
func (s *store) GetLatestVersion(ctx context.Context, db DBTxConn) (int64, error) {
|
||||
q := s.querier.GetLatestVersion(s.tableName)
|
||||
var version sql.NullInt64
|
||||
if err := db.QueryRowContext(ctx, q).Scan(&version); err != nil {
|
||||
return -1, fmt.Errorf("failed to get latest version: %w", err)
|
||||
}
|
||||
if !version.Valid {
|
||||
return -1, fmt.Errorf("latest %w", ErrVersionNotFound)
|
||||
}
|
||||
return version.Int64, nil
|
||||
}
|
||||
|
||||
func (s *store) ListMigrations(
|
||||
ctx context.Context,
|
||||
db DBTxConn,
|
||||
) ([]*ListMigrationsResult, error) {
|
||||
q := s.querier.ListMigrations(s.tableName)
|
||||
rows, err := db.QueryContext(ctx, q)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to list migrations: %w", err)
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
var migrations []*ListMigrationsResult
|
||||
for rows.Next() {
|
||||
var result ListMigrationsResult
|
||||
if err := rows.Scan(&result.Version, &result.IsApplied); err != nil {
|
||||
return nil, fmt.Errorf("failed to scan list migrations result: %w", err)
|
||||
}
|
||||
migrations = append(migrations, &result)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return migrations, nil
|
||||
}
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
// Additional methods that are not part of the core Store interface, but are extended by the
|
||||
// [controller.StoreController] type.
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
func (s *store) TableExists(ctx context.Context, db DBTxConn) (bool, error) {
|
||||
q := s.querier.TableExists(s.tableName)
|
||||
if q == "" {
|
||||
return false, errors.ErrUnsupported
|
||||
}
|
||||
var exists bool
|
||||
// Note, we do not pass the table name as an argument to the query, as the query should be
|
||||
// pre-defined by the dialect.
|
||||
if err := db.QueryRowContext(ctx, q).Scan(&exists); err != nil {
|
||||
return false, fmt.Errorf("failed to check if table exists: %w", err)
|
||||
}
|
||||
return exists, nil
|
||||
}
|
||||
|
||||
var _ dialect.Querier = (*queryController)(nil)
|
||||
|
||||
type queryController struct{ dialect.Querier }
|
||||
|
||||
// newQueryController returns a new QueryController that wraps the given Querier.
|
||||
func newQueryController(querier dialect.Querier) *queryController {
|
||||
return &queryController{Querier: querier}
|
||||
}
|
||||
|
||||
// Optional methods
|
||||
|
||||
// TableExists returns the SQL query string to check if the version table exists. If the Querier
|
||||
// does not implement this method, it will return an empty string.
|
||||
//
|
||||
// Returns a boolean value.
|
||||
func (c *queryController) TableExists(tableName string) string {
|
||||
if t, ok := c.Querier.(interface{ TableExists(string) string }); ok {
|
||||
return t.TableExists(tableName)
|
||||
}
|
||||
return ""
|
||||
}
|
||||
14
vendor/github.com/pressly/goose/v3/database/doc.go
generated
vendored
Normal file
14
vendor/github.com/pressly/goose/v3/database/doc.go
generated
vendored
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
// Package database defines a generic [Store] interface for goose to use when interacting with the
|
||||
// database. It is meant to be generic and not tied to any specific database technology.
|
||||
//
|
||||
// At a high level, a [Store] is responsible for:
|
||||
// - Creating a version table
|
||||
// - Inserting and deleting a version
|
||||
// - Getting a specific version
|
||||
// - Listing all applied versions
|
||||
//
|
||||
// Use the [NewStore] function to create a [Store] for one of the supported dialects.
|
||||
//
|
||||
// For more advanced use cases, it's possible to implement a custom [Store] for a database that
|
||||
// goose does not support.
|
||||
package database
|
||||
23
vendor/github.com/pressly/goose/v3/database/sql_extended.go
generated
vendored
Normal file
23
vendor/github.com/pressly/goose/v3/database/sql_extended.go
generated
vendored
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
package database
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
)
|
||||
|
||||
// DBTxConn is a thin interface for common methods that is satisfied by *sql.DB, *sql.Tx and
|
||||
// *sql.Conn.
|
||||
//
|
||||
// There is a long outstanding issue to formalize a std lib interface, but alas. See:
|
||||
// https://github.com/golang/go/issues/14468
|
||||
type DBTxConn interface {
|
||||
ExecContext(ctx context.Context, query string, args ...any) (sql.Result, error)
|
||||
QueryContext(ctx context.Context, query string, args ...any) (*sql.Rows, error)
|
||||
QueryRowContext(ctx context.Context, query string, args ...any) *sql.Row
|
||||
}
|
||||
|
||||
var (
|
||||
_ DBTxConn = (*sql.DB)(nil)
|
||||
_ DBTxConn = (*sql.Tx)(nil)
|
||||
_ DBTxConn = (*sql.Conn)(nil)
|
||||
)
|
||||
66
vendor/github.com/pressly/goose/v3/database/store.go
generated
vendored
Normal file
66
vendor/github.com/pressly/goose/v3/database/store.go
generated
vendored
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
package database
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"time"
|
||||
)
|
||||
|
||||
var (
|
||||
// ErrVersionNotFound must be returned by [GetMigration] or [GetLatestVersion] when a migration
|
||||
// does not exist.
|
||||
ErrVersionNotFound = errors.New("version not found")
|
||||
|
||||
// ErrNotImplemented must be returned by methods that are not implemented.
|
||||
ErrNotImplemented = errors.New("not implemented")
|
||||
)
|
||||
|
||||
// Store is an interface that defines methods for tracking and managing migrations. It is used by
|
||||
// the goose package to interact with a database. By defining a Store interface, multiple
|
||||
// implementations can be created to support different databases without reimplementing the
|
||||
// migration logic.
|
||||
//
|
||||
// This package provides several dialects that implement the Store interface. While most users won't
|
||||
// need to create their own Store, if you need to support a database that isn't currently supported,
|
||||
// you can implement your own!
|
||||
type Store interface {
|
||||
// Tablename is the name of the version table. This table is used to record applied migrations
|
||||
// and must not be an empty string.
|
||||
Tablename() string
|
||||
// CreateVersionTable creates the version table, which is used to track migrations.
|
||||
CreateVersionTable(ctx context.Context, db DBTxConn) error
|
||||
// Insert a version id into the version table.
|
||||
Insert(ctx context.Context, db DBTxConn, req InsertRequest) error
|
||||
// Delete a version id from the version table.
|
||||
Delete(ctx context.Context, db DBTxConn, version int64) error
|
||||
// GetMigration retrieves a single migration by version id. If the query succeeds, but the
|
||||
// version is not found, this method must return [ErrVersionNotFound].
|
||||
GetMigration(ctx context.Context, db DBTxConn, version int64) (*GetMigrationResult, error)
|
||||
// GetLatestVersion retrieves the last applied migration version. If no migrations exist, this
|
||||
// method must return [ErrVersionNotFound].
|
||||
GetLatestVersion(ctx context.Context, db DBTxConn) (int64, error)
|
||||
// ListMigrations retrieves all migrations sorted in descending order by id or timestamp. If
|
||||
// there are no migrations, return empty slice with no error. Typically this method will return
|
||||
// at least one migration, because the initial version (0) is always inserted into the version
|
||||
// table when it is created.
|
||||
ListMigrations(ctx context.Context, db DBTxConn) ([]*ListMigrationsResult, error)
|
||||
}
|
||||
|
||||
type InsertRequest struct {
|
||||
Version int64
|
||||
|
||||
// TODO(mf): in the future, we maybe want to expand this struct so implementors can store
|
||||
// additional information. See the following issues for more information:
|
||||
// - https://github.com/pressly/goose/issues/422
|
||||
// - https://github.com/pressly/goose/issues/288
|
||||
}
|
||||
|
||||
type GetMigrationResult struct {
|
||||
Timestamp time.Time
|
||||
IsApplied bool
|
||||
}
|
||||
|
||||
type ListMigrationsResult struct {
|
||||
Version int64
|
||||
IsApplied bool
|
||||
}
|
||||
33
vendor/github.com/pressly/goose/v3/database/store_extended.go
generated
vendored
Normal file
33
vendor/github.com/pressly/goose/v3/database/store_extended.go
generated
vendored
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
package database
|
||||
|
||||
import "context"
|
||||
|
||||
// StoreExtender is an extension of the Store interface that provides optional optimizations and
|
||||
// database-specific features. While not required by the core goose package, implementing these
|
||||
// methods can improve performance and functionality for specific databases.
|
||||
//
|
||||
// IMPORTANT: This interface may be expanded in future versions. Implementors MUST be prepared to
|
||||
// update their implementations when new methods are added, either by implementing the new
|
||||
// functionality or returning [errors.ErrUnsupported].
|
||||
//
|
||||
// The goose package handles these extended capabilities through a [controller.StoreController],
|
||||
// which automatically uses optimized methods when available while falling back to default behavior
|
||||
// when they're not implemented.
|
||||
//
|
||||
// Example usage to verify implementation:
|
||||
//
|
||||
// var _ StoreExtender = (*CustomStoreExtended)(nil)
|
||||
//
|
||||
// In short, it's exported to allows implementors to have a compile-time check that they are
|
||||
// implementing the interface correctly.
|
||||
type StoreExtender interface {
|
||||
Store
|
||||
|
||||
// TableExists checks if the migrations table exists in the database. Implementing this method
|
||||
// allows goose to optimize table existence checks by using database-specific system catalogs
|
||||
// (e.g., pg_tables for PostgreSQL, sqlite_master for SQLite) instead of generic SQL queries.
|
||||
//
|
||||
// Return [errors.ErrUnsupported] if the database does not provide an efficient way to check
|
||||
// table existence.
|
||||
TableExists(ctx context.Context, db DBTxConn) (bool, error)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue