Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(experimental): add migration logic with tests #617

Merged
merged 2 commits into from
Oct 17, 2023
Merged

Conversation

mfridman
Copy link
Collaborator

@mfridman mfridman commented Oct 17, 2023

This PR adds the migration logic to the goose.Provider and implements all the methods. In future PRs would like to clean the TODOs, and start thinking how to make this public while ensuring this is a sane (and maintainable) project organization.

func (p *Provider) ApplyVersion(ctx context.Context, version int64, direction bool) (*MigrationResult, error) {}
func (p *Provider) Close() error {}
func (p *Provider) Down(ctx context.Context) ([]*MigrationResult, error) {}
func (p *Provider) DownTo(ctx context.Context, version int64) ([]*MigrationResult, error) {}
func (p *Provider) GetDBVersion(ctx context.Context) (int64, error) {}
func (p *Provider) ListSources() []*Source {}
func (p *Provider) Ping(ctx context.Context) error {}
func (p *Provider) Status(ctx context.Context) ([]*MigrationStatus, error) {}
func (p *Provider) Up(ctx context.Context) ([]*MigrationResult, error) {}
func (p *Provider) UpByOne(ctx context.Context) ([]*MigrationResult, error) {}
func (p *Provider) UpTo(ctx context.Context, version int64) ([]*MigrationResult, error) {}

There are a few new types that may interest folks:

type MigrationStatus struct {
	State     State
	AppliedAt time.Time
	Source    Source
}

type MigrationResult struct {
	Source    Source
	Duration  time.Duration
	Direction string
	Empty     bool
	Error     error
}

type Source struct {
	Type MigrationType
	Fullpath string
	Version int64
}

Testing

  1. 83% coverage provider running -test.short. All tests use sqlite to test the underlying behaviour
┌─────────────────────────────────────────────────────────────────────────────────────────────────┐
│  STATUS │ ELAPSED │                    PACKAGE                    │ COVER │ PASS │ FAIL │ SKIP  │
│─────────┼─────────┼───────────────────────────────────────────────┼───────┼──────┼──────┼───────│
│  PASS   │  1.56s  │ github.com/pressly/goose/v3/internal/provider │ 83.0% │  55  │  0   │  1    │
└─────────────────────────────────────────────────────────────────────────────────────────────────┘
  1. 85.5% coverage running all the above tests and the postgres session locker
┌─────────────────────────────────────────────────────────────────────────────────────────────────┐
│  STATUS │ ELAPSED │                    PACKAGE                    │ COVER │ PASS │ FAIL │ SKIP  │
│─────────┼─────────┼───────────────────────────────────────────────┼───────┼──────┼──────┼───────│
│  PASS   │ 14.91s  │ github.com/pressly/goose/v3/internal/provider │ 85.5% │  60  │  0   │  0    │
└─────────────────────────────────────────────────────────────────────────────────────────────────┘

Note, that the end goal is not to get 100% coverage but to cover all the important business logic and features.

@mfridman mfridman merged commit 257b523 into master Oct 17, 2023
8 checks passed
@mfridman mfridman deleted the gh-379-4 branch October 17, 2023 02:08
@mfridman mfridman mentioned this pull request Oct 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant