Skip to content

Commit

Permalink
feat: supabase deploy -> supabase db push
Browse files Browse the repository at this point in the history
  • Loading branch information
soedirgo committed Nov 25, 2021
1 parent 1adcf57 commit 051ba8f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 26 deletions.
10 changes: 10 additions & 0 deletions cmd/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"github.com/spf13/cobra"
"github.com/supabase/cli/internal/db/changes"
"github.com/supabase/cli/internal/db/commit"
"github.com/supabase/cli/internal/db/push"
"github.com/supabase/cli/internal/db/reset"
)

Expand Down Expand Up @@ -31,6 +32,14 @@ var (
},
}

dbPushCmd = &cobra.Command{
Use: "push",
Short: "Push new migrations to the remote database.",
RunE: func(cmd *cobra.Command, args []string) error {
return push.Run()
},
}

dbResetCmd = &cobra.Command{
Use: "reset",
Short: "Resets the local database to reflect current migrations. Any changes on the local database that is not committed will be lost.",
Expand All @@ -46,6 +55,7 @@ func init() {

dbCmd.AddCommand(dbChangesCmd)
dbCmd.AddCommand(dbCommitCmd)
dbCmd.AddCommand(dbPushCmd)
dbCmd.AddCommand(dbResetCmd)
rootCmd.AddCommand(dbCmd)
}
18 changes: 0 additions & 18 deletions cmd/deploy.go

This file was deleted.

18 changes: 10 additions & 8 deletions internal/deploy/deploy.go → internal/db/push/push.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package deploy
package push

import (
"context"
Expand All @@ -10,12 +10,12 @@ import (
pgx "github.com/jackc/pgx/v4"
)

var ctx = context.TODO()
var ctx = context.Background()

func Deploy() error {
url := os.Getenv("SUPABASE_DEPLOY_DB_URL")
func Run() error {
url := os.Getenv("SUPABASE_REMOTE_DB_URL")
if url == "" {
return errors.New("❌ SUPABASE_DEPLOY_DB_URL is not set.")
return errors.New("SUPABASE_REMOTE_DB_URL is not set.")
}

conn, err := pgx.Connect(ctx, url)
Expand All @@ -24,9 +24,11 @@ func Deploy() error {
}
defer conn.Close(context.Background())

// `schema_migrations` must be a "prefix" of `supabase/migrations`.

rows, err := conn.Query(ctx, "SELECT version FROM supabase_migrations.schema_migrations ORDER BY version")
if err != nil {
return errors.New("supabase_migrations.schema_migrations table does not exist.")
return errors.New("supabase_migrations.schema_migrations table does not exist.")
}

versions := []string{}
Expand All @@ -44,7 +46,7 @@ func Deploy() error {
}

conflictErr := errors.New(
"supabase_migrations.schema_migrations table conflicts with the contents of `migrations` directory.",
"supabase_migrations.schema_migrations table conflicts with the contents of `migrations` directory.",
)

if len(versions) > len(migrations) {
Expand Down Expand Up @@ -81,7 +83,7 @@ func Deploy() error {
}
}

fmt.Println("Finished supabase deploy.")
fmt.Println("Finished `supabase db push`.")

return nil
}

0 comments on commit 051ba8f

Please sign in to comment.