-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert "Remove
pgroll sql
subcommand (#515)"
This reverts commit 358c6c6.
- Loading branch information
1 parent
97b0bed
commit 7f8da80
Showing
2 changed files
with
40 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package cmd | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"os" | ||
|
||
"github.com/spf13/cobra" | ||
"github.com/xataio/pgroll/pkg/sql2pgroll" | ||
) | ||
|
||
func sqlCmd() *cobra.Command { | ||
sqlCmd := &cobra.Command{ | ||
Use: "sql <sql statement>", | ||
Short: "Convert SQL statements to pgroll operations", | ||
Args: cobra.ExactArgs(1), | ||
Hidden: true, | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
sql := args[0] | ||
|
||
ops, err := sql2pgroll.Convert(sql) | ||
if err != nil { | ||
return fmt.Errorf("failed to convert SQL statement: %w", err) | ||
} | ||
|
||
enc := json.NewEncoder(os.Stdout) | ||
enc.SetIndent("", " ") | ||
if err := enc.Encode(ops); err != nil { | ||
return fmt.Errorf("failed to encode operations: %w", err) | ||
} | ||
|
||
return nil | ||
}, | ||
} | ||
|
||
return sqlCmd | ||
} |