Add hook support
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 3.4k
- Forks
- 292
- PR merge metrics
- No merged PRs in 30d
Description
Today the package already know some special comments, I'm proposing to add hook points as special comments where plain Go code could execute along the migration. This is very useful during transformations caused by the migration.
-- +migrate Up
ALTER TABLE users ADD COLUMN confirmation BOOLEAN;
-- +hook addConfirmation
-- +migrate Down
ALTER TABLE users DROP COLUMN confirmation BOOLEAN;
Using the standalone cli, don't know how this could work, but, using the library is kinda easy:
type hook func(db *sql.DB, tx *sql.Tx) error
migrations := &migrate.MemoryMigrationSource{
Migrations: []*migrate.Migration{
&migrate.Migration{
Id: "123",
Up: []string{"CREATE TABLE people (id int)"},
Down: []string{"DROP TABLE people"},
Hook: map[string]hook{"addConfirmation": addConfirmation},
},
},
}
func addConfirmation(db *sql.DB, tx *sql.Tx) error {
// custom logic here
return nil
}
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 the library parses existing special comments and executes migrations, then compare that path with the standalone CLI path. Define how named hooks are registered and invoked for both directions, and how errors and transaction state are handled; the work is done when the proposed hook example works without leaving the CLI behavior undefined.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go, sql
- Domain
- databases
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100