10000 Add new command `convert` to convert SQL migrations to pgroll operations by kvch · Pull Request #685 · xataio/pgroll · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Add new command convert to convert SQL migrations to pgroll operations #685

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

Merged
merged 3 commits into from
Feb 18, 2025
Merged
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
11 changes: 11 additions & 0 deletions cli-definition.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,17 @@
"subcommands": [],
"args": []
},
{
"name": "convert",
"short": "Convert SQL statements to pgroll operations from SQL",
"use": "convert <path to file with migrations>",
"example": "",
"flags": [],
"subcommands": [],
"args": [
"migration-file"
]
},
{
"name": "init",
"short": "Initialize pgroll in the target database",
Expand Down
44 changes: 44 additions & 0 deletions cmd/convert.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// SPDX-License-Identifier: Apache-2.0

package cmd

import (
"fmt"
"io"
"os"

"github.com/spf13/cobra"
)

func convertCmd() *cobra.Command {
convertCmd := &cobra.Command{
Use: "convert <path to file with migrations>",
Short: "Convert SQL statements to pgroll operations from SQL",
Args: cobra.MaximumNArgs(1),
ValidArgs: []string{"migration-file"},
Hidden: true,
RunE: func(cmd *cobra.Command, args []string) error {
reader, err := openSQLReader(args)
if err != nil {
return fmt.Errorf("open SQL migration: %w", err)
}
defer reader.Close()

_, err = scanSQLStatements(reader)
return err
},
}

return convertCmd
}

func openSQLReader(args []string) (io.ReadCloser, error) {
if len(args) == 0 {
return os.Stdin, nil
}
return os.Open(args[0])
}

func scanSQLStatements(reader io.Reader) ([]string, error) {
panic("not implemented")
}
1 change: 1 addition & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ func Prepare() *cobra.Command {
rootCmd.AddCommand(pullCmd())
rootCmd.AddCommand(latestCmd())
rootCmd.AddCommand(sqlCmd())
rootCmd.AddCommand(convertCmd())

return rootCmd
}
Expand Down
0