-
Notifications
You must be signed in to change notification settings - Fork 84
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
migrations: add missing index creating migration #1460
base: main
Are you sure you want to change the base?
Conversation
case ms == nil, len(ms) == 1: | ||
continue | ||
case len(ms) == 2: | ||
migrations = append(migrations, path.Clean(string(ms[1]))) |
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.
filepath
? I guess it is always /
, though
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.
I will change it but yeah
sort.Strings(files) | ||
|
||
// Check referenced files exist and existing files are referenced. | ||
if !cmp.Equal(migrations, files) { |
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.
I believe this will fail on Windows machines due to the \
? If so, is that ok?
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.
We don't support running on Windows so I think it's ok
var migrations, files []string | ||
|
||
// Get referenced migrations | ||
migrationLine, err := regexp.Compile(`runFile\(\"(.*)\"\)`) |
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 feels brittle. An idea can be to create a base slice like
const indexerMigrations = []string{
"filename1",
"filename2",
...
}
and then have
func init() {
for i, migration := range indexerMigrations {
IndexerMigrations = append(IndexerMigrations, {
ID: i+1,
Up: runFile(migration),
})
}
}
something like that so we can just ensure indexerMigrations
lists all the files
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.
I think one thing we'd want to keep is the ID being explicitly associated with the migration file so a user can check their DB migration version and know which was the last file being run (without having to work it out).
It is brittle in the sense that the runFile might change, but the proposed solution doesn't address fact that a sql file might exist on the FS but not be referenced in the go code, maybe this isn't actually an issue if you aren't forgetful (like myself) and remember to reference the migration. The reason this case was slightly different was that there was an admin command added to clairctl
to pre-create the index so when testing the code in stage and production the index was already created and hence, it didn't look like anything was missing.
While the sql command was added to claircore (and the admin command was added to clairctl) to create an index it was never actually reference in the migrations. This should be a no-op for all instances that ran the associated clairctl admin command. Also, added a test to try and avoid this in the future. Signed-off-by: crozzy <[email protected]>
31f43b0
to
e816c4f
Compare
While the sql command was added to claircore (and the admin command was added to clairctl) to create an index it was never actually reference in the migrations. This should be a no-op for all instances that ran the associated clairctl admin command. Also, added a test to try and avoid this in the future.