-
Notifications
You must be signed in to change notification settings - Fork 535
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
193 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,32 @@ | ||
package gomigrations | ||
|
||
import ( | ||
"context" | ||
"database/sql" | ||
"fmt" | ||
|
||
"github.com/pressly/goose/v3" | ||
"github.com/pressly/goose/v3/database" | ||
) | ||
|
||
func init() { | ||
goose.AddMigration(up001, down001) | ||
} | ||
|
||
func up001(tx *sql.Tx) error { | ||
q := "CREATE TABLE foo (id INT, subid INT, name TEXT)" | ||
_, err := tx.Exec(q) | ||
return err | ||
return createTable(tx, "alpha") | ||
} | ||
|
||
func down001(tx *sql.Tx) error { | ||
q := "DROP TABLE IF EXISTS foo" | ||
_, err := tx.Exec(q) | ||
return dropTable(tx, "alpha") | ||
} | ||
|
||
func createTable(db database.DBTxConn, name string) error { | ||
_, err := db.ExecContext(context.Background(), fmt.Sprintf("CREATE TABLE %s (id INTEGER)", name)) | ||
return err | ||
} | ||
|
||
func dropTable(db database.DBTxConn, name string) error { | ||
_, err := db.ExecContext(context.Background(), fmt.Sprintf("DROP TABLE %s", name)) | ||
return err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,5 +5,5 @@ import ( | |
) | ||
|
||
func init() { | ||
goose.AddMigration(nil, nil) | ||
goose.AddMigrationNoTx(nil, nil) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package gomigrations | ||
|
||
import ( | ||
"context" | ||
"database/sql" | ||
|
||
"github.com/pressly/goose/v3" | ||
) | ||
|
||
func init() { | ||
goose.AddMigrationContext(up009, down009) | ||
} | ||
|
||
func up009(ctx context.Context, tx *sql.Tx) error { | ||
return createTable(tx, "echo") | ||
} | ||
|
||
func down009(ctx context.Context, tx *sql.Tx) error { | ||
return dropTable(tx, "echo") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package gomigrations | ||
|
||
import ( | ||
"context" | ||
"database/sql" | ||
|
||
"github.com/pressly/goose/v3" | ||
) | ||
|
||
func init() { | ||
goose.AddMigrationContext(up010, nil) | ||
} | ||
|
||
func up010(ctx context.Context, tx *sql.Tx) error { | ||
return createTable(tx, "foxtrot") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package gomigrations | ||
|
||
import ( | ||
"context" | ||
"database/sql" | ||
|
||
"github.com/pressly/goose/v3" | ||
) | ||
|
||
func init() { | ||
goose.AddMigrationContext(nil, down011) | ||
} | ||
|
||
func down011(ctx context.Context, tx *sql.Tx) error { | ||
return dropTable(tx, "foxtrot") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package gomigrations | ||
|
||
import ( | ||
"github.com/pressly/goose/v3" | ||
) | ||
|
||
func init() { | ||
goose.AddMigrationContext(nil, nil) | ||
} |
20 changes: 20 additions & 0 deletions
20
tests/gomigrations/success/testdata/013_up_down_no_tx_ctx.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package gomigrations | ||
|
||
import ( | ||
"context" | ||
"database/sql" | ||
|
||
"github.com/pressly/goose/v3" | ||
) | ||
|
||
func init() { | ||
goose.AddMigrationNoTxContext(up013, down013) | ||
} | ||
|
||
func up013(ctx context.Context, db *sql.DB) error { | ||
return createTable(db, "golf") | ||
} | ||
|
||
func down013(ctx context.Context, db *sql.DB) error { | ||
return dropTable(db, "golf") | ||
} |
16 changes: 16 additions & 0 deletions
16
tests/gomigrations/success/testdata/014_up_only_no_tx_ctx.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package gomigrations | ||
|
||
import ( | ||
"context" | ||
"database/sql" | ||
|
||
"github.com/pressly/goose/v3" | ||
) | ||
|
||
func init() { | ||
goose.AddMigrationNoTxContext(up014, nil) | ||
} | ||
|
||
func up014(ctx context.Context, db *sql.DB) error { | ||
return createTable(db, "hotel") | ||
} |
16 changes: 16 additions & 0 deletions
16
tests/gomigrations/success/testdata/015_down_only_no_tx_ctx.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package gomigrations | ||
|
||
import ( | ||
"context" | ||
"database/sql" | ||
|
||
"github.com/pressly/goose/v3" | ||
) | ||
|
||
func init() { | ||
goose.AddMigrationNoTxContext(nil, down015) | ||
} | ||
|
||
func down015(ctx context.Context, db *sql.DB) error { | ||
return dropTable(db, "hotel") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package gomigrations | ||
|
||
import ( | ||
"github.com/pressly/goose/v3" | ||
) | ||
|
||
func init() { | ||
goose.AddMigrationNoTxContext(nil, nil) | ||
} |