-
Notifications
You must be signed in to change notification settings - Fork 27
Added support for migrations with comments (mysql only) #25
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,6 +10,7 @@ import ( | |
| "os" | ||
| "path/filepath" | ||
| "sort" | ||
| "strings" | ||
| ) | ||
|
|
||
| type migrationType string | ||
|
|
@@ -238,6 +239,18 @@ func (m *Migrator) ApplyMigration(migration *Migration, mType migrationType) err | |
|
|
||
| // Perform the migration. | ||
| for _, cmd := range commands { | ||
| cmd = strings.ReplaceAll(cmd, "\n", "") // strip off leading whitespace | ||
| if strings.HasPrefix(cmd, "SELECT") && strings.HasSuffix(cmd, "AS comment") { | ||
| row := transaction.QueryRow(cmd) | ||
| var comment string | ||
| err = row.Scan(&comment) | ||
| if err != nil { | ||
| m.logger.Printf("Error executing query comment: %v", err) | ||
| return err | ||
| } | ||
| m.logger.Printf("Comment: %v", comment) | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure if I like the term "comment" to refer to this. Maybe "debug output" works best?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can see merit in that too, but would you prefer adding a new opt-in flag on the migrator to enable There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since the term comment is used in the ANSI/ISO SQL lexicon, I think calling it a comment is perfectly valid. Perhaps |
||
| continue | ||
| } | ||
| result, err := transaction.Exec(cmd) | ||
| if err != nil { | ||
| m.logger.Printf("Error executing migration: %v", err) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,11 +3,15 @@ CREATE TABLE test ( | |
| PRIMARY KEY (id) | ||
| ); | ||
|
|
||
| SELECT 'my comment' AS comment; | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perhaps any select should be printed out? I see no other reason to include selects in migrations.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I could see that being helpful, but in the migrate func I specifically chose to use the |
||
|
|
||
| CREATE TABLE test2 ( | ||
| id INT NOT NULL AUTO_INCREMENT, | ||
| PRIMARY KEY (id) | ||
| ); | ||
|
|
||
| SELECT 'my other comment' AS comment; | ||
|
|
||
| CREATE TABLE tt (c text NOT NULL); | ||
|
|
||
| INSERT INTO tt VALUES('a'); | ||
|
|
||
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.
Do we want to normalize the query here with
strings.ToLower?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'd say yes for any SQL keywords, but that would mess up the capitalization of other strings that we may not want to mess with.