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

Move sqlite to woodpecker #438

Closed
wants to merge 3 commits into from
Closed

Conversation

jolheiser
Copy link
Member

Moves the sqlite file to woodpecker and attempts to migrate legacy drone sqlite files.

Note that if the CLI explicitly sets the datasource to drone.sqlite the migration will not run, as it is assumed the user has explicitly set it for a reason.

Signed-off-by: jolheiser <john.olheiser@gmail.com>
@anbraten anbraten added breaking will break existing installations if no manual action happens refactor delete or replace old code labels Oct 13, 2021
@anbraten anbraten added this to the 0.15.0 milestone Oct 13, 2021
Copy link
Member

@anbraten anbraten left a comment

Choose a reason for hiding this comment

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

Note: This PR has to be merged before #431

return datastore.New(
c.String("driver"),
c.String("datasource"),
)
}

// TODO Remove this once we are sure users aren't attempting to migrate from Drone to Woodpecker (possibly never)
func checkSqliteFile() error {
_, err := os.Stat("drone.sqlite")
Copy link
Member

Choose a reason for hiding this comment

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

This works only for binary installations. For docker installations the path set via WOODPECKER_DATABASE_DATASOURCE would be /var/lib/drone/woodpecker.sqlite. Maybe something like the suggestion in combination with removing if !c.IsSet("datasource") { would work. 🤔

Suggested change
_, err := os.Stat("drone.sqlite")
_, err := os.Stat(fmt.Sprintf("%s/drone.sqlite", filepath.Dir(c.String("datasource"))))

}
return err
}
return os.Rename("drone.sqlite", "woodpecker.sqlite")
Copy link
Member

Choose a reason for hiding this comment

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

Would probably need absolute paths version as well.

@jolheiser
Copy link
Member Author

@anbraten I'm not sure about the docker paths, because they use env variables.
It would be hard to discern who copied the configuration and who explicitly set it that way.

imo this should only migrate if the user had made no other effort to change from default (that is, no env variable and no flag set)

@anbraten
Copy link
Member

@jolheiser We currently have ENV WOODPECKER_DATABASE_DATASOURCE=/var/lib/drone/drone.sqlite in the Dockerfile. So that was the default path for most users. As we know that path it shouldn't be to hard to check if a file at that path exists and if so move it to the new path. Maybe we should move this change back into #431 to be able to create a single migration 🙈. As far as I know there currently is only the sqlite file and XDG_CACHE_HOME under /var/lib/drone.

@jolheiser
Copy link
Member Author

@anbraten I understand that it's the default, but only because we had it set that way.
In the case of the flag, the default occurred because the user never set anything.
In the case of the docker file, although the user may have copied/pasted it's still being explicitly set.

The current migration is a single check and then no-op after.
The part that worries me is people who look in their docker file, expect to know where the db is, but then find it's been "magically" changed.
With the flag, since I check for it being set, anyone who had it set will find it hasn't changed, if they set "--datasource drone.sqlite" it will honor it still.

I can change it, but it seems (imo) to be a slightly different case than an unused flag.

@jolheiser
Copy link
Member Author

Superseded by #494

@jolheiser jolheiser closed this Oct 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking will break existing installations if no manual action happens refactor delete or replace old code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants