Lazy open/parse of sql files
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 3.4k
- Forks
- 292
- PR merge metrics
- No merged PRs in 30d
Description
This is not a bug report, but a feature request.
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.
It seems to me that the best way to achieve this would be as follows
type Migration struct {
Id string
// private field from here
up []string
down []string
disableTransactionUp bool
disableTransactionDown bool
path string
parsed bool
}
func (m *Migration) Up() []string {
if !m.parsed {
// call sqlparse.ParseMigration(r) and save results.
m.parsed = true
}
return m.up
}
If it's okay, I can send PR.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by tracing how Migration values are created and how sqlparse.ParseMigration is called, especially the Up method and the byId sorting path mentioned in the issue. Confirm that sorting can avoid parsing file contents and that content is parsed only when Up or Down is needed, while preserving the existing migration results.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go, sql
- Domain
- database
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100