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

[WIP] - Adding a provider #378

Closed
wants to merge 20 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ dist:
GOOS=windows GOARCH=386 go build -o ./bin/goose-windows386.exe ./cmd/goose

test-packages:
go test -v $$(go list ./... | grep -v -e /tests -e /bin -e /cmd -e /examples)
go test -race -v $$(go list ./... | grep -v -e /tests -e /bin -e /cmd -e /examples)

test-e2e: test-e2e-postgres test-e2e-mysql

test-e2e-postgres:
go test -v ./tests/e2e -dialect=postgres
go test -race -v ./tests/e2e -dialect=postgres

test-e2e-mysql:
go test -v ./tests/e2e -dialect=mysql
go test -race -v ./tests/e2e -dialect=mysql

test-clickhouse:
go test -timeout=10m -count=1 -race -v ./tests/clickhouse -test.short
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ import (
"database/sql"
"embed"

"github.com/pressly/goose/v3"
"github.com/pressly/goose/v4"
)

//go:embed migrations/*.sql
Expand Down Expand Up @@ -308,7 +308,7 @@ package migrations
import (
"database/sql"

"github.com/pressly/goose/v3"
"github.com/pressly/goose/v4"
)

func init() {
Expand Down
31 changes: 31 additions & 0 deletions cmd/debug/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package main

import (
"context"
"database/sql"
"fmt"
"log"
"os"

"github.com/pressly/goose/v4"
_ "github.com/pressly/goose/v4/cmd/debug/migrations"

// _ "github.com/pressly/goose/v4/cmd/debug/migrationsb"
_ "modernc.org/sqlite"
)

func main() {
ctx := context.Background()
db, err := sql.Open("sqlite", "cmd/debug/test.db")
if err != nil {
log.Fatal(err)
}
p, err := goose.NewProvider(goose.DialectSqlite, db, "cmd/debug/migrations", nil)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
if err := p.Up(ctx); err != nil {
log.Fatal(err)
}
}
14 changes: 14 additions & 0 deletions cmd/debug/migrations/00001_create_users_table.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
-- +goose Up
CREATE TABLE users (
id int NOT NULL PRIMARY KEY,
username text,
name text,
surname text
);

INSERT INTO users VALUES
(0, 'root', '', ''),
(1, 'vojtechvitek', 'Vojtech', 'Vitek');

-- +goose Down
DROP TABLE users;
9 changes: 9 additions & 0 deletions cmd/debug/migrations/00002_rename_root.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
-- +goose Up
-- +goose StatementBegin
UPDATE users SET username='admin' WHERE username='root';
-- +goose StatementEnd

-- +goose Down
-- +goose StatementBegin
UPDATE users SET username='root' WHERE username='admin';
-- +goose StatementEnd
11 changes: 11 additions & 0 deletions cmd/debug/migrations/00003_no_transaction.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
-- +goose NO TRANSACTION
-- +goose Up
CREATE TABLE post (
id int NOT NULL,
title text,
body text,
PRIMARY KEY(id)
);

-- +goose Down
DROP TABLE post;
19 changes: 19 additions & 0 deletions cmd/debug/migrations/00004_foo.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package migrations

import (
"database/sql"

"github.com/pressly/goose/v4"
)

func init() {
goose.Register(Up00002, Down00002)
}

func Up00002(tx *sql.Tx) error {
return nil
}

func Down00002(tx *sql.Tx) error {
return nil
}
19 changes: 19 additions & 0 deletions cmd/debug/migrationsb/00001_foo.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package migrations

import (
"database/sql"

"github.com/pressly/goose/v4"
)

func init() {
goose.Register(Up00002, Down00002)
}

func Up00002(tx *sql.Tx) error {
return nil
}

func Down00002(tx *sql.Tx) error {
return nil
}
Binary file not shown.
Loading