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: Implement backup and restore of dev-server database #488

Merged
merged 22 commits into from
Feb 6, 2025

Conversation

dmashuda
Copy link
Contributor

@dmashuda dmashuda commented Feb 5, 2025

Requirements

Allows for exporting a backup and restoring a backup of the underlying sqlite3 database.

Downloading a backup db

curl --output backup.db localhost:8765/dev/backup

Restoring a backup db

curl --data-binary @backup.db http://localhost:8765/dev/backup
  • I have added test coverage for new or changed functionality
  • I have followed the repository's pull request submission guidelines
  • [] I have validated my changes against all supported platform versions

Related issues

Provide links to any issues in this repository or elsewhere relating to this pull request.

Describe the solution you've provided

Provide a clear and concise description of what you expect to happen.

Describe alternatives you've considered

Provide a clear and concise description of any alternative solutions or features you've considered.

Additional context

Add any other context about the pull request here.

@dmashuda dmashuda changed the title Danielmashuda/fun 554 implement persistence feat: Implement backup and restore Feb 5, 2025
@@ -35,7 +40,7 @@ func (s Sqlite) GetDevProjectKeys(ctx context.Context) ([]string, error) {
return keys, nil
}

func (s Sqlite) GetDevProject(ctx context.Context, key string) (*model.Project, error) {
func (s *Sqlite) GetDevProject(ctx context.Context, key string) (*model.Project, error) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

converted to pointer so that s.database can be updated after db restore

if err != nil {
return "", errors.Wrap(err, "unable to close database before restoring backup")
}
err = os.Rename(filepath, s.dbPath)
Copy link
Contributor Author

@dmashuda dmashuda Feb 6, 2025

Choose a reason for hiding this comment

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

idol-switch

@dmashuda dmashuda changed the title feat: Implement backup and restore feat: Implement backup and restore of dev-server database Feb 6, 2025
@dmashuda dmashuda requested review from mike-zorn and a team February 6, 2025 16:07
@dmashuda dmashuda marked this pull request as ready for review February 6, 2025 16:07
conns []*sqllite.SQLiteConn
}

func NewManager(dbPath string, dbName string, backupFilePattern string, restoreFilePattern string) *Manager {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we need a comment here to indicate the expected lifecycle of the managers. It looks like each one gets its own unique file name space so you could run multiple managers at the same time, but you also need to use care to not reuse the same one?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done:

  • The manager is safe to create multiple instances
  • Each instance can only run 1 backup/restore at a time

@dmashuda dmashuda requested a review from mike-zorn February 6, 2025 18:22
return "", errors.Wrap(err, "open backup database")
}

defer func(sourceDb *sql.DB) {
Copy link
Contributor

Choose a reason for hiding this comment

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

unused param

Copy link
Contributor

@mike-zorn mike-zorn left a comment

Choose a reason for hiding this comment

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

Exciting stuff!

@dmashuda dmashuda merged commit f0dd661 into main Feb 6, 2025
9 checks passed
@dmashuda dmashuda deleted the danielmashuda/FUN-554-implement-persistence branch February 6, 2025 20:27
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.

3 participants