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

Lazy open/parse of sql files #203

Open
KeiichiHirobe opened this issue Jan 12, 2022 · 3 comments
Open

Lazy open/parse of sql files #203

KeiichiHirobe opened this issue Jan 12, 2022 · 3 comments

Comments

@KeiichiHirobe
Copy link

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.

@rubenv
Copy link
Owner

rubenv commented Jan 12, 2022

@KeiichiHirobe hey yes that's a good suggestion, feel free to submit a PR!

@KeiichiHirobe
Copy link
Author

@rubenv
Thanks for the quick reply!
I'll send PR in 1-2 weeks.

@KeiichiHirobe KeiichiHirobe changed the title Lazy parse of sql files Lazy open/parse of sql files Jan 23, 2022
@KeiichiHirobe
Copy link
Author

@rubenv
Thank you for waiting, I have just submitted PR.
Please review #204.

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

No branches or pull requests

2 participants