Skip to content

Commit 0fc9fd0

Browse files
committed
chore: update unit tests for shadow migrate
1 parent 988ad61 commit 0fc9fd0

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

internal/db/diff/migra_test.go

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package diff
33
import (
44
"context"
55
"errors"
6+
"fmt"
67
"io"
78
"net/http"
89
"os"
@@ -16,6 +17,7 @@ import (
1617
"github.com/stretchr/testify/assert"
1718
"github.com/stretchr/testify/require"
1819
"github.com/supabase/cli/internal/db/reset"
20+
"github.com/supabase/cli/internal/migration/repair"
1921
"github.com/supabase/cli/internal/testing/apitest"
2022
"github.com/supabase/cli/internal/testing/pgtest"
2123
"github.com/supabase/cli/internal/utils"
@@ -235,6 +237,9 @@ At statement 0: create schema public`)
235237
t.Run("throws error on failure to diff target", func(t *testing.T) {
236238
// Setup in-memory fs
237239
fsys := afero.NewMemMapFs()
240+
path := filepath.Join(utils.MigrationsDir, "0_test.sql")
241+
sql := "create schema test"
242+
require.NoError(t, afero.WriteFile(fsys, path, []byte(sql), 0644))
238243
// Setup mock docker
239244
require.NoError(t, apitest.MockDocker(utils.Docker))
240245
defer gock.OffAll()
@@ -255,7 +260,19 @@ At statement 0: create schema public`)
255260
conn.Query(utils.GlobalsSql).
256261
Reply("CREATE SCHEMA").
257262
Query(utils.InitialSchemaSql).
258-
Reply("CREATE SCHEMA")
263+
Reply("CREATE SCHEMA").
264+
Query(repair.CREATE_VERSION_SCHEMA).
265+
Reply("CREATE SCHEMA").
266+
Query(repair.CREATE_VERSION_TABLE).
267+
Reply("CREATE TABLE").
268+
Query(repair.ADD_STATEMENTS_COLUMN).
269+
Reply("ALTER TABLE").
270+
Query(repair.ADD_NAME_COLUMN).
271+
Reply("ALTER TABLE").
272+
Query(sql).
273+
Reply("CREATE SCHEMA").
274+
Query(repair.INSERT_MIGRATION_VERSION, "0", "test", fmt.Sprintf("{%s}", sql)).
275+
Reply("INSERT 0 1")
259276
// Run test
260277
diff, err := DiffDatabase(context.Background(), []string{"public"}, dbConfig, io.Discard, fsys, conn.Intercept)
261278
// Check error

0 commit comments

Comments
 (0)