Skip to content

Migrate database up before serving using opm#100

Closed
anik120 wants to merge 1 commit into
operator-framework:masterfrom
anik120:migration
Closed

Migrate database up before serving using opm#100
anik120 wants to merge 1 commit into
operator-framework:masterfrom
anik120:migration

Conversation

@anik120
Copy link
Copy Markdown
Member

@anik120 anik120 commented Oct 22, 2019

Description of the change:

  • Add wrapper around Up migration
  • Call wrapper before serving database using opm cli

Merge before #99

Reviewer Checklist

  • Implementation matches the proposed design, or proposal is updated to match implementation
  • Sufficient unit test coverage
  • Sufficient end-to-end test coverage
  • Docs updated or added to /docs
  • Commit messages sensible and descriptive

@openshift-ci-robot openshift-ci-robot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Oct 22, 2019
Copy link
Copy Markdown
Member

@kevinrizza kevinrizza left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a few comments, otherwise this looks good to me.

Comment thread cmd/opm/registry/serve.go Outdated
return nil
}

func migrateToLatest(db *sql.DB) error {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is the right place for this function. If we want to reuse it in other places (like when we add other commands to opm registry, maybe we should move it into the sqlite package? Otherwise we should just leave it in line.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kevinrizza this is a stop gap measure till we have the migrate command available with the opm cli. Once we have that this function can be removed and the corresponding function from the registry package should be used here

Comment thread pkg/sqlite/query.go Outdated
Comment thread pkg/sqlite/migrator.go Outdated
// looks at the currently active migration version and will
// migrate all the way up (applying all up migrations).
func (m *SQLMigrator) MigrateUp() error {
instance, err := sqlite3.WithInstance(m.db, &sqlite3.Config{})
Copy link
Copy Markdown
Member

@ecordell ecordell Oct 22, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will make the migrator sqlite-only.

If we change

type SQLMigrator struct {
	db             *sql.DB
	migrationsPath string
	generated bool
}

to

type SQLMigrator struct {
	db             database.Driver
	migrationsPath string
	generated bool
}

then we can use the migrator for any db?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can make this change, but the golang-migrate needs that instance object to understand which database and explicitly support it. IMO we should probably revisit this later if we want to abstract the migrator to understand multiple database types.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 with Kevin.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

golang-migrate needs that instance object to understand which database and explicitly support it.

I don't think this is the case, but we can revisit it in the future.

I do think we should be careful to pass in a DatabaseName to sqlite3.Config, right?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do think we should be careful to pass in a DatabaseName to sqlite3.Config, right?

@ecordell I've updated the PR to pass in a DatabaseName. Why do you say careful though? I didn't seem to find any "best practice guide" around passing the database name in the docs so was curious.

- Add wrapper around Up migration
- Call wrapper before serving database using opm cli
@openshift-ci-robot
Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: anik120
To complete the pull request process, please assign njhale
You can assign the PR to them by writing /assign @njhale in a comment when ready.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@anik120
Copy link
Copy Markdown
Member Author

anik120 commented Oct 23, 2019

/retest

@anik120
Copy link
Copy Markdown
Member Author

anik120 commented Oct 25, 2019

Closing in favor or #101

@anik120 anik120 closed this Oct 25, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/M Denotes a PR that changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants