Skip to content

Commit

Permalink
chore(popx): code simplification and refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
zepatrik authored and aeneasr committed Oct 31, 2024
1 parent 934758e commit 8004c2c
Show file tree
Hide file tree
Showing 13 changed files with 69 additions and 474 deletions.
30 changes: 0 additions & 30 deletions pkgerx/file.go

This file was deleted.

187 changes: 0 additions & 187 deletions pkgerx/migration_box.go

This file was deleted.

43 changes: 0 additions & 43 deletions pkgerx/migration_box_test.go

This file was deleted.

22 changes: 0 additions & 22 deletions pkgerx/sql_template_funcs.go

This file was deleted.

Empty file.
Empty file.
9 changes: 5 additions & 4 deletions popx/migration_box_gomigration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package popx_test
import (
"context"
"database/sql"
"github.com/ory/x/dbal"
"math/rand"
"testing"
"time"
Expand Down Expand Up @@ -78,7 +79,7 @@ func TestGoMigrations(t *testing.T) {
called = make([]time.Time, len(goMigrations))

c, err := pop.NewConnection(&pop.ConnectionDetails{
URL: "sqlite://file::memory:?_fk=true",
URL: dbal.NewSQLiteTestDatabase(t),
})
require.NoError(t, err)
require.NoError(t, c.Open())
Expand All @@ -101,7 +102,7 @@ func TestGoMigrations(t *testing.T) {

t.Run("tc=errs_on_missing_down_migration", func(t *testing.T) {
c, err := pop.NewConnection(&pop.ConnectionDetails{
URL: "sqlite://file::memory:?_fk=true",
URL: dbal.NewSQLiteTestDatabase(t),
})
require.NoError(t, err)
require.NoError(t, c.Open())
Expand All @@ -112,7 +113,7 @@ func TestGoMigrations(t *testing.T) {

t.Run("tc=runs everything in one transaction", func(t *testing.T) {
c, err := pop.NewConnection(&pop.ConnectionDetails{
URL: "sqlite://file::memory:?_fk=true",
URL: dbal.NewSQLiteTestDatabase(t),
})
require.NoError(t, err)
require.NoError(t, c.Open())
Expand Down Expand Up @@ -223,7 +224,7 @@ func TestIncompatibleRunners(t *testing.T) {

func TestNoTransaction(t *testing.T) {
c, err := pop.NewConnection(&pop.ConnectionDetails{
URL: "sqlite://file::memory:",
URL: dbal.NewSQLiteTestDatabase(t),
})
require.NoError(t, err)
require.NoError(t, c.Open())
Expand Down
4 changes: 2 additions & 2 deletions popx/migration_box_template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import (
"testing"

"github.com/gobuffalo/pop/v6"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/ory/x/dbal"
"github.com/ory/x/logrusx"
)

Expand All @@ -27,7 +27,7 @@ func TestMigrationBoxTemplating(t *testing.T) {
require.NoError(t, err)

c, err := pop.NewConnection(&pop.ConnectionDetails{
URL: "sqlite://file::memory:?_fk=true",
URL: dbal.NewSQLiteTestDatabase(t),
})
require.NoError(t, err)
require.NoError(t, c.Open())
Expand Down
5 changes: 3 additions & 2 deletions popx/migration_box_testdata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/ory/x/dbal"
"github.com/ory/x/logrusx"
"github.com/ory/x/popx"
)
Expand All @@ -34,7 +35,7 @@ type testdata struct {

func TestMigrationBoxWithTestdata(t *testing.T) {
c, err := pop.NewConnection(&pop.ConnectionDetails{
URL: "sqlite://file::memory:?_fk=true",
URL: dbal.NewSQLiteTestDatabase(t),
})
require.NoError(t, err)
require.NoError(t, c.Open())
Expand Down Expand Up @@ -78,7 +79,7 @@ func TestMigrationBoxWithoutTransaction(t *testing.T) {

func TestMigrationBox_CheckNoErr(t *testing.T) {
c, err := pop.NewConnection(&pop.ConnectionDetails{
URL: "sqlite://file::memory:?_fk=true",
URL: dbal.NewSQLiteTestDatabase(t),
})
require.NoError(t, err)
require.NoError(t, c.Open())
Expand Down
5 changes: 3 additions & 2 deletions popx/migration_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,11 @@ func (mfs Migrations) Swap(i, j int) {
func (mfs Migrations) SortAndFilter(dialect string, modifiers ...func(sort.Interface) sort.Interface) Migrations {
// We need to sort mfs in order to push the dbType=="all" migrations
// to the back.
m := append(Migrations{}, mfs...)
m := make(Migrations, len(mfs))
copy(m, mfs)
sort.Sort(m)

vsf := make(Migrations, 0)
vsf := make(Migrations, 0, len(m))
for k, v := range m {
if v.DBType == "all" {
// Add "all" only if we can not find a more specific migration for the dialect.
Expand Down
Loading

0 comments on commit 8004c2c

Please sign in to comment.