Skip to content
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

add feature: IntrospectDMMF & IntrospectSDL & migrate push SDK #771

Open
wants to merge 32 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
518d7b7
add learn example
AnsonCode Sep 18, 2022
09de970
add IntrospectDMMF and IntrospectSDL
AnsonCode Sep 18, 2022
7997116
add migrate push SDK
AnsonCode Sep 18, 2022
3cc5853
fied merge conflict
AnsonCode Sep 18, 2022
7a132e6
add introspect code
sx19990201 Sep 19, 2022
875b479
add prisma api
sx19990201 Sep 19, 2022
c2b5533
update prisma interface
sx19990201 Sep 23, 2022
e13a20b
update download code
sx19990201 Sep 23, 2022
cdce23d
update discoon
sx19990201 Sep 23, 2022
4e218ff
update reload
sx19990201 Sep 23, 2022
0963578
update discoon
sx19990201 Sep 23, 2022
71b04c7
update prisma
sx19990201 Sep 23, 2022
da4cbbe
update api
sx19990201 Sep 23, 2022
4622a95
update log
sx19990201 Sep 23, 2022
82a9398
update prisma
sx19990201 Sep 26, 2022
602e529
update pull code
sx19990201 Sep 26, 2022
ee6f5c6
update err msg
sx19990201 Sep 26, 2022
d73ed60
update reload engine
sx19990201 Sep 26, 2022
b6cad36
add engine code
sx19990201 Oct 11, 2022
1d8576f
update result code
sx19990201 Oct 11, 2022
9bfea2f
add manyquery code
sx19990201 Oct 12, 2022
2cc9282
update code
sx19990201 Oct 12, 2022
3d23e89
update pull func
sx19990201 Oct 18, 2022
65dfb11
kill child proess
sx19990201 Oct 24, 2022
96bee6a
update windows engine name
sx19990201 Nov 8, 2022
9d2d83f
update engine version
sx19990201 Nov 18, 2022
3552968
update prisma version and engine version
sx19990201 Dec 1, 2022
dbaf938
update path.join
sx19990201 Dec 12, 2022
11ec57c
update filepath
sx19990201 Dec 12, 2022
36fffa7
update path.join
sx19990201 Dec 12, 2022
774713e
add filepath.ToSlash
sx19990201 Dec 12, 2022
e1e2181
feat: Add support for mac m1
erguotou520 Jan 9, 2023
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
22 changes: 12 additions & 10 deletions binaries/binaries.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@ import (
)

// PrismaVersion is a hardcoded version of the Prisma CLI.
const PrismaVersion = "3.13.0"
//const PrismaVersion = "3.13.0"
var PrismaVersion = "3.13.0"

// EngineVersion is a hardcoded version of the Prisma Engine.
// The versions can be found under https://github.com/prisma/prisma-engines/commits/master
const EngineVersion = "efdf9b1183dddfd4258cd181a72125755215ab7b"
//const EngineVersion = "694eea289a8462c80264df36757e4fdc129b1b32"
var EngineVersion = "694eea289a8462c80264df36757e4fdc129b1b32"

// PrismaURL points to an S3 bucket URL where the CLI binaries are stored.
var PrismaURL = "https://prisma-photongo.s3-eu-west-1.amazonaws.com/%s-%s-%s-x64.gz"
Expand Down Expand Up @@ -63,19 +65,19 @@ func PrismaCLIName() string {
return fmt.Sprintf("prisma-cli-%s-x64", variation)
}

var baseDirName = path.Join("prisma", "binaries")
var baseDirName = filepath.Join("prisma", "binaries")

// GlobalTempDir returns the path of where the engines live
// internally, this is the global temp dir
func GlobalTempDir(version string) string {
temp := os.TempDir()
logger.Debug.Printf("temp dir: %s", temp)

return path.Join(temp, baseDirName, "engines", version)
return filepath.ToSlash(filepath.Join(temp, baseDirName, "engines", version))
}

func GlobalUnpackDir(version string) string {
return path.Join(GlobalTempDir(version), "unpacked", "v2")
return filepath.ToSlash(filepath.Join(GlobalTempDir(version), "unpacked", "v2"))
}

// GlobalCacheDir returns the path of where the CLI lives
Expand All @@ -88,13 +90,13 @@ func GlobalCacheDir() string {

logger.Debug.Printf("global cache dir: %s", cache)

return path.Join(cache, baseDirName, "cli", PrismaVersion)
return filepath.ToSlash(filepath.Join(cache, baseDirName, "cli", PrismaVersion))
}

func FetchEngine(toDir string, engineName string, binaryPlatformName string) error {
logger.Debug.Printf("checking %s...", engineName)

to := platform.CheckForExtension(binaryPlatformName, path.Join(toDir, EngineVersion, fmt.Sprintf("prisma-%s-%s", engineName, binaryPlatformName)))
to := platform.CheckForExtension(binaryPlatformName, filepath.ToSlash(filepath.Join(toDir, EngineVersion, fmt.Sprintf("prisma-%s-%s", engineName, binaryPlatformName))))

binaryPlatformRemoteName := binaryPlatformName
if binaryPlatformRemoteName == "linux" {
Expand Down Expand Up @@ -145,7 +147,7 @@ func FetchNative(toDir string) error {

func DownloadCLI(toDir string) error {
cli := PrismaCLIName()
to := platform.CheckForExtension(platform.Name(), path.Join(toDir, cli))
to := platform.CheckForExtension(platform.Name(), filepath.ToSlash(filepath.Join(toDir, cli)))
url := platform.CheckForExtension(platform.Name(), fmt.Sprintf(PrismaURL, "prisma-cli", PrismaVersion, platform.Name()))

logger.Debug.Printf("ensuring CLI %s from %s to %s", cli, to, url)
Expand All @@ -166,15 +168,15 @@ func DownloadCLI(toDir string) error {
}

func GetEnginePath(dir, engine, binaryName string) string {
return platform.CheckForExtension(binaryName, path.Join(dir, EngineVersion, fmt.Sprintf("prisma-%s-%s", engine, binaryName)))
return platform.CheckForExtension(binaryName, filepath.ToSlash(filepath.Join(dir, EngineVersion, fmt.Sprintf("prisma-%s-%s", engine, binaryName))))
}

func DownloadEngine(name string, toDir string) (file string, err error) {
binaryName := platform.BinaryPlatformName()

logger.Debug.Printf("checking %s...", name)

to := platform.CheckForExtension(binaryName, path.Join(toDir, EngineVersion, fmt.Sprintf("prisma-%s-%s", name, binaryName)))
to := platform.CheckForExtension(binaryName, filepath.ToSlash(filepath.Join(toDir, EngineVersion, fmt.Sprintf("prisma-%s-%s", name, binaryName))))

url := platform.CheckForExtension(binaryName, fmt.Sprintf(EngineURL, EngineVersion, binaryName, name))

Expand Down
17 changes: 17 additions & 0 deletions binaries/platform/platform.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,16 @@ func BinaryPlatformName() string {
}

platform := Name()
// Refer to https://github.dev/prisma/prisma/tree/main/packages/cli/src/utils
// Not well test for !win & !mac
arch := Arch()

if platform != "linux" {
if platform == "darwin" {
if arch == "arm64" {
return fmt.Sprintf("%s-%s", platform, arch)
}
}
return platform
}

Expand All @@ -33,6 +41,11 @@ func BinaryPlatformName() string {
ssl := getOpenSSL()

name := fmt.Sprintf("%s-openssl-%s", distro, ssl)
if arch == "arm64" {
name = fmt.Sprintf("%s--arm64-openssl-%s", distro, ssl)
} else if arch == "arm" {
name = fmt.Sprintf("%s-arm-openssl-%s", distro, ssl)
}

binaryNameWithSSLCache = name

Expand All @@ -44,6 +57,10 @@ func Name() string {
return runtime.GOOS
}

func Arch() string {
return runtime.GOARCH
}

// CheckForExtension adds a .exe extension on windows (e.g. .gz -> .exe.gz)
func CheckForExtension(platform, path string) string {
if platform == "windows" {
Expand Down
4 changes: 2 additions & 2 deletions binaries/unpack/unpack.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package unpack
import (
"fmt"
"os"
"path"
"path/filepath"
"time"

"github.com/prisma/prisma-client-go/binaries"
Expand All @@ -24,7 +24,7 @@ func Unpack(data []byte, name string, version string) {

tempDir := binaries.GlobalUnpackDir(version)

dir := platform.CheckForExtension(platform.Name(), path.Join(tempDir, file))
dir := platform.CheckForExtension(platform.Name(), filepath.ToSlash(filepath.ToSlash(filepath.Join(tempDir, file))))

if err := os.MkdirAll(tempDir, os.ModePerm); err != nil {
panic(fmt.Errorf("mkdirall failed: %w", err))
Expand Down
13 changes: 6 additions & 7 deletions cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@ package cli

import (
"fmt"
"os"
"os/exec"
"path"

"github.com/prisma/prisma-client-go/binaries"
"github.com/prisma/prisma-client-go/binaries/platform"
"github.com/prisma/prisma-client-go/logger"
"os"
"os/exec"
"path/filepath"
)

// Run the prisma CLI with given arguments
Expand All @@ -25,9 +24,9 @@ func Run(arguments []string, output bool) error {

prisma := binaries.PrismaCLIName()

logger.Debug.Printf("running %s %+v", path.Join(dir, prisma), arguments)
logger.Debug.Printf("running %s %+v", filepath.ToSlash(filepath.Join(dir, prisma)), arguments)

cmd := exec.Command(path.Join(dir, prisma), arguments...) //nolint:gosec
cmd := exec.Command(filepath.ToSlash(filepath.Join(dir, prisma)), arguments...) //nolint:gosec
binaryName := platform.CheckForExtension(platform.Name(), platform.BinaryPlatformName())

cmd.Env = os.Environ()
Expand All @@ -41,7 +40,7 @@ func Run(arguments []string, output bool) error {
logger.Debug.Printf("overriding %s to %s", engine.Name, env)
value = env
} else {
value = path.Join(dir, binaries.EngineVersion, fmt.Sprintf("prisma-%s-%s", engine.Name, binaryName))
value = filepath.ToSlash(filepath.Join(dir, binaries.EngineVersion, fmt.Sprintf("prisma-%s-%s", engine.Name, binaryName)))
}

cmd.Env = append(cmd.Env, fmt.Sprintf("%s=%s", engine.Env, value))
Expand Down
Loading