Skip to content

Commit 20156eb

Browse files
authored
Fix sql tool error in windows (#7519)
## What changed? Use `path.Join()` instead of `filepath.Join()` ## Why? #7454 ## How did you test it? Tested locally ## Potential risks <!-- Assuming the worst case, what can be broken when deploying this change to production? --> None ## Documentation <!-- Have you made sure this change doesn't falsify anything currently stated in `docs/`? If significant new behavior is added, have you described that in `docs/`? --> None ## Is hotfix candidate? <!-- Is this PR a hotfix candidate or does it require a notification to be sent to the broader community? (Yes/No) --> No
1 parent 722e086 commit 20156eb

File tree

3 files changed

+11
-24
lines changed

3 files changed

+11
-24
lines changed

schema/embed.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ func PathsByDir(dbSubDir string) []string {
5252
}
5353
if d.IsDir() {
5454
if d.Name() == "versioned" {
55-
dirs = append(dirs, filepath.Dir(path))
55+
dirs = append(dirs, filepath.ToSlash(filepath.Dir(path)))
5656
return fs.SkipDir
5757
}
5858
}

tools/common/schema/updatetask.go

+4-20
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,13 @@ import (
3030
// should not be used for anything more important (password hashes etc.). Marking it as #nosec because of how it's
3131
// being used.
3232
"crypto/md5" // #nosec
33-
"embed"
3433
"encoding/hex"
3534
"encoding/json"
3635
"fmt"
3736
"io"
3837
"io/fs"
3938
"os"
4039
"path"
41-
"path/filepath"
4240
"regexp"
4341
"sort"
4442
"strings"
@@ -216,12 +214,7 @@ func (task *UpdateTask) buildChangeSet(currVer string) ([]changeSet, error) {
216214
var result []changeSet
217215

218216
for _, vd := range verDirs {
219-
var dirPath string
220-
if _, ok := fsys.(embed.FS); ok {
221-
dirPath = path.Join(dir, vd)
222-
} else {
223-
dirPath = filepath.Join(dir, vd)
224-
}
217+
dirPath := path.Join(dir, vd)
225218

226219
m, e := readManifest(fsys, dirPath)
227220
if e != nil {
@@ -259,12 +252,7 @@ func (task *UpdateTask) parseSQLStmts(fsys fs.FS, dir string, manifest *manifest
259252
result := make([]string, 0, 4)
260253

261254
for _, file := range manifest.SchemaUpdateCqlFiles {
262-
var schemaPath string
263-
if _, ok := fsys.(embed.FS); ok {
264-
schemaPath = path.Join(dir, file)
265-
} else {
266-
schemaPath = filepath.Join(dir, file)
267-
}
255+
schemaPath := path.Join(dir, file)
268256
task.logger.Info("Processing schema file: " + schemaPath)
269257
schemaBuf, err := fs.ReadFile(fsys, schemaPath)
270258
if err != nil {
@@ -302,12 +290,8 @@ func validateCQLStmts(stmts []string) error {
302290

303291
// readManifest reads the json manifest at dirPath into a manifest struct.
304292
func readManifest(fsys fs.FS, dirPath string) (*manifest, error) {
305-
var manifestPath string
306-
if _, ok := fsys.(embed.FS); ok {
307-
manifestPath = path.Join(dirPath, manifestFileName)
308-
} else {
309-
manifestPath = filepath.Join(dirPath, manifestFileName)
310-
}
293+
manifestPath := path.Join(dirPath, manifestFileName)
294+
311295
jsonBlob, err := fs.ReadFile(fsys, manifestPath)
312296
if err != nil {
313297
return nil, err

tools/sql/README.md

+6-3
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ SQL_USER=$USERNAME SQL_PASSWORD=$PASSWD make install-schema-mysql
1717
- For other SQL database, you can add it easily as we do for MySQL/Postgres following our code in sql-extensions
1818

1919
### Do one time database creation and schema setup for a new cluster
20-
- All command below are taking MySQL as example. For postgres, simply use with "--plugin postgres12"
20+
21+
- All command below are taking MySQL as example. For postgres, simply use with "--plugin postgres12" and "--schema-name postgresql/v12/temporal" & "--schema-name postgresql/v12/visibility"
2122

2223
```
2324
./temporal-sql-tool --ep $SQL_HOST -p $port --db temporal --plugin mysql8 create
@@ -26,10 +27,12 @@ SQL_USER=$USERNAME SQL_PASSWORD=$PASSWD make install-schema-mysql
2627

2728
```
2829
./temporal-sql-tool --ep $SQL_HOST -p $port --plugin mysql8 --db temporal setup-schema -v 0.0 -- this sets up just the schema version tables with initial version of 0.0
29-
./temporal-sql-tool --ep $SQL_HOST -p $port --plugin mysql8 --db temporal update-schema -d ./schema/mysql/v8/temporal/versioned -- upgrades your schema to the latest version
30+
./temporal-sql-tool --ep $SQL_HOST -p $port --plugin mysql8 --db temporal update-schema --schema-name mysql/v8/temporal -- upgrades your schema with the embedded schema
31+
./temporal-sql-tool --ep $SQL_HOST -p $port --plugin mysql8 --db temporal update-schema -d ./schema/mysql/v8/temporal/versioned -- Or upgrades your schema by providing your schema
3032
3133
./temporal-sql-tool --ep $SQL_HOST -p $port --plugin mysql8 --db temporal_visibility setup-schema -v 0.0 -- this sets up just the schema version tables with initial version of 0.0 for visibility
32-
./temporal-sql-tool --ep $SQL_HOST -p $port --plugin mysql8 --db temporal_visibility update-schema -d ./schema/mysql/v8/visibility/versioned -- upgrades your schema to the latest version for visibility
34+
./temporal-sql-tool --ep $SQL_HOST -p $port --plugin mysql8 --db temporal update-schema --schema-name mysql/v8/visibility -- upgrades your schema with the embedded schema for visibility
35+
./temporal-sql-tool --ep $SQL_HOST -p $port --plugin mysql8 --db temporal_visibility update-schema -d ./schema/mysql/v8/visibility/versioned -- Or upgrades your schema by providing your schema for visibility
3336
```
3437

3538
### Update schema as part of a release

0 commit comments

Comments
 (0)