Skip to content

Commit

Permalink
reduce diff
Browse files Browse the repository at this point in the history
  • Loading branch information
mfridman committed Nov 24, 2024
1 parent da8e21f commit c41b2b3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
6 changes: 3 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

- Store implementations can now **optionally** implement the `TableExists` method to provide
optimized table (#860) existence checks
- Default postgres implementation updated to use `pg_tables` system catalog, more to follow
- Store implementations can **optionally** implement the `TableExists` method to provide optimized
table existence checks (#860)
- Default postgres Store implementation updated to use `pg_tables` system catalog, more to follow
- Backward compatible change - existing implementations will continue to work without modification

```go
Expand Down
26 changes: 13 additions & 13 deletions database/dialect.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ const (
)

// NewStore returns a new [Store] implementation for the given dialect.
func NewStore(dialect Dialect, tableName string) (Store, error) {
if tableName == "" {
func NewStore(dialect Dialect, tablename string) (Store, error) {
if tablename == "" {
return nil, errors.New("table name must not be empty")
}
if dialect == "" {
Expand All @@ -52,40 +52,40 @@ func NewStore(dialect Dialect, tableName string) (Store, error) {
return nil, fmt.Errorf("unknown dialect: %q", dialect)
}
return &store{
tableName: tableName,
tablename: tablename,
querier: dialectquery.NewQueryController(querier),
}, nil
}

type store struct {
tableName string
tablename string
querier *dialectquery.QueryController
}

var _ Store = (*store)(nil)

func (s *store) Tablename() string {
return s.tableName
return s.tablename
}

func (s *store) CreateVersionTable(ctx context.Context, db DBTxConn) error {
q := s.querier.CreateTable(s.tableName)
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 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)
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)
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)
}
Expand All @@ -97,7 +97,7 @@ func (s *store) GetMigration(
db DBTxConn,
version int64,
) (*GetMigrationResult, error) {
q := s.querier.GetMigrationByVersion(s.tableName)
q := s.querier.GetMigrationByVersion(s.tablename)
var result GetMigrationResult
if err := db.QueryRowContext(ctx, q, version).Scan(
&result.Timestamp,
Expand All @@ -112,7 +112,7 @@ func (s *store) GetMigration(
}

func (s *store) GetLatestVersion(ctx context.Context, db DBTxConn) (int64, error) {
q := s.querier.GetLatestVersion(s.tableName)
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)
Expand All @@ -127,7 +127,7 @@ func (s *store) ListMigrations(
ctx context.Context,
db DBTxConn,
) ([]*ListMigrationsResult, error) {
q := s.querier.ListMigrations(s.tableName)
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)
Expand Down Expand Up @@ -158,7 +158,7 @@ func (s *store) ListMigrations(
//

func (s *store) TableExists(ctx context.Context, db DBTxConn) (bool, error) {
q := s.querier.TableExists(s.tableName)
q := s.querier.TableExists(s.tablename)
if q == "" {
return false, errors.ErrUnsupported
}
Expand Down

0 comments on commit c41b2b3

Please sign in to comment.