Skip to content

DiscoverSQLMigrationsFromFilesystem: assume underlaying fs use '/' as… #108

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

Open
wants to merge 1 commit into
base: v8
Choose a base branch
from

Conversation

bearsh
Copy link

@bearsh bearsh commented Apr 15, 2021

… separator

when DiscoverSQLMigrations() is called, a 'os nativ' fs is assumed, so
convert the path to slash. when opening a file on such a fs, convert to
back from slash to native separator.

#107

… separator

when DiscoverSQLMigrations() is called, a 'os nativ' fs is assumed, so
convert the path to slash. when opening a file on such a fs, convert to
back from slash to native separator.

go-pg#107
@landru29
Copy link

As there's nothing new since 2021, I propose a workaround:

import (
	"net/http"
	"path"
)

type fsMove struct {
	folder     string
	originalFS http.FileSystem
}

func newFSMove(originalFS http.FileSystem, folder string) http.FileSystem {
	return fsMove{
		folder:     folder,
		originalFS: originalFS,
	}
}

func (f fsMove) Open(name string) (http.File, error) {
	return f.originalFS.Open(path.Join(f.folder, name))
}

Then, you can use it with:

collection := migrations.NewCollection()
if err := collection.DiscoverSQLMigrationsFromFilesystem(
    newFSMove(migrationFS, "where/are/located/my/embed/files"),
    "",
); err != nil {
	panic(err)
}

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.

2 participants