-
Notifications
You must be signed in to change notification settings - Fork 280
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 and parse files lazily #204
base: master
Are you sure you want to change the base?
Conversation
migrate.go
Outdated
type Migration struct { | ||
Id string | ||
Up []string | ||
Down []string | ||
|
||
type MigrationData struct { | ||
Up []string | ||
Down []string | ||
DisableTransactionUp bool | ||
DisableTransactionDown bool | ||
} | ||
|
||
type migrationFile struct { | ||
dir http.FileSystem | ||
root string | ||
baseName string | ||
} | ||
|
||
type Migration struct { | ||
Id string | ||
|
||
// data may be nil if not parsed yet. | ||
data *MigrationData | ||
// file is information of migration file, which is used to parse later. | ||
// file may be nil if migration file has already been parsed when Migration is initialized. | ||
file *migrationFile | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a problem really. It changes the external API of the library, which means it may break peoples code. And I'd rather not do that.
Unless we find a way to do this without breaking the API, I'm afraid this won't be an option.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This reverts commit 859f73b.
…le to be loaded only when needed.
ca2e507
to
14223b2
Compare
Current implementation always parse all of sql files, so may require a lot of time and memory if there are too many files or too big files in directory. But, in most of cases, we only need to parse 1~3 files because sort
byId
does not need content of files, it needs only the name of files.So, I think it is better to parse sql files only when we need content of files.
Some migration sources are not supported to open/parse lazily in this PR.
HttpFileSystemMigrationSource
,FileMigrationSource
andEmbedFileSystemMigrationSource
are supported,MemoryMigrationSource
,AssetMigrationSource
andPackrBox
are not supported.I don't think that's a problem because I guess most users don't use the latter migration sources.
I believe lazy loading should be the default behavior, but I made it optional with
SetLazyLoad(true)
to keep backward compatibility.ref: #203