Skip to content

feat(generate): support yml extension #2828

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 5 commits into from
Oct 12, 2023
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
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/BUG_REPORT.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ body:
id: config
attributes:
label: Configuration
description: Please include the sqlc.yaml or sqlc.json file you using in your project. This will be automatically formatted, so no need for backticks.
description: Please include the sqlc.(yaml|yml) or sqlc.json file you using in your project. This will be automatically formatted, so no need for backticks.
render: yaml
- type: input
id: playground
Expand Down
2 changes: 1 addition & 1 deletion docs/reference/config.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Configuration

The `sqlc` tool is configured via a `sqlc.yaml` or `sqlc.json` file. This
The `sqlc` tool is configured via a `sqlc.(yaml|yml)` or `sqlc.json` file. This
file must be in the directory where the `sqlc` command is run.

## Version 2
Expand Down
2 changes: 1 addition & 1 deletion docs/tutorials/getting-started-mysql.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Initialize a new Go module named `tutorial.sql.dev/app`
go mod init tutorial.sqlc.dev/app
```

sqlc looks for either a `sqlc.yaml` or `sqlc.json` file in the current
sqlc looks for either a `sqlc.(yaml|yml)` or `sqlc.json` file in the current
directory. In our new directory, create a file named `sqlc.yaml` with the
following contents:

Expand Down
4 changes: 2 additions & 2 deletions docs/tutorials/getting-started-postgresql.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Getting started with PostgreSQL
# Getting started with PostgreSQL

This tutorial assumes that the latest version of sqlc is
[installed](../overview/install.md) and ready to use.
Expand All @@ -11,7 +11,7 @@ Initialize a new Go module named `tutorial.sqlc.dev/app`
go mod init tutorial.sqlc.dev/app
```

sqlc looks for either a `sqlc.yaml` or `sqlc.json` file in the current
sqlc looks for either a `sqlc.(yaml|yml)` or `sqlc.json` file in the current
directory. In our new directory, create a file named `sqlc.yaml` with the
following contents:

Expand Down
2 changes: 1 addition & 1 deletion docs/tutorials/getting-started-sqlite.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Initialize a new Go module named `tutorial.sql.dev/app`
go mod init tutorial.sqlc.dev/app
```

sqlc looks for either a `sqlc.yaml` or `sqlc.json` file in the current
sqlc looks for either a `sqlc.(yaml|yml)` or `sqlc.json` file in the current
directory. In our new directory, create a file named `sqlc.yaml` with the
following contents:

Expand Down
26 changes: 18 additions & 8 deletions internal/cmd/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,9 @@ func readConfig(stderr io.Writer, dir, filename string) (string, *config.Config,
if filename != "" {
configPath = filepath.Join(dir, filename)
} else {
var yamlMissing, jsonMissing bool
var yamlMissing, jsonMissing, ymlMissing bool
yamlPath := filepath.Join(dir, "sqlc.yaml")
ymlPath := filepath.Join(dir, "sqlc.yml")
jsonPath := filepath.Join(dir, "sqlc.json")

if _, err := os.Stat(yamlPath); os.IsNotExist(err) {
Expand All @@ -87,18 +88,27 @@ func readConfig(stderr io.Writer, dir, filename string) (string, *config.Config,
jsonMissing = true
}

if yamlMissing && jsonMissing {
fmt.Fprintln(stderr, "error parsing configuration files. sqlc.yaml or sqlc.json: file does not exist")
if _, err := os.Stat(ymlPath); os.IsNotExist(err) {
ymlMissing = true
}

if yamlMissing && ymlMissing && jsonMissing {
fmt.Fprintln(stderr, "error parsing configuration files. sqlc.(yaml|yml) or sqlc.json: file does not exist")
return "", nil, errors.New("config file missing")
}

if !yamlMissing && !jsonMissing {
fmt.Fprintln(stderr, "error: both sqlc.json and sqlc.yaml files present")
return "", nil, errors.New("sqlc.json and sqlc.yaml present")
if (!yamlMissing || !ymlMissing) && !jsonMissing {
fmt.Fprintln(stderr, "error: both sqlc.json and sqlc.(yaml|yml) files present")
return "", nil, errors.New("sqlc.json and sqlc.(yaml|yml) present")
}

configPath = yamlPath
if yamlMissing {
if jsonMissing {
if yamlMissing {
configPath = ymlPath
} else {
configPath = yamlPath
}
} else {
configPath = jsonPath
}
}
Expand Down
2 changes: 1 addition & 1 deletion internal/endtoend/ddl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func TestValidSchema(t *testing.T) {
if err != nil {
return err
}
if filepath.Base(path) == "sqlc.json" || filepath.Base(path) == "sqlc.yaml" {
if filepath.Base(path) == "sqlc.json" || filepath.Base(path) == "sqlc.yaml" || filepath.Base(path) == "sqlc.yml" {
stderr := filepath.Join(filepath.Dir(path), "stderr.txt")
if _, err := os.Stat(stderr); !os.IsNotExist(err) {
return nil
Expand Down
4 changes: 2 additions & 2 deletions internal/endtoend/endtoend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func TestReplay(t *testing.T) {
if err != nil {
return err
}
if info.Name() == "sqlc.json" || info.Name() == "sqlc.yaml" {
if info.Name() == "sqlc.json" || info.Name() == "sqlc.yaml" || info.Name() == "sqlc.yml" {
dirs = append(dirs, filepath.Dir(path))
return filepath.SkipDir
}
Expand Down Expand Up @@ -251,7 +251,7 @@ func BenchmarkReplay(b *testing.B) {
if err != nil {
return err
}
if info.Name() == "sqlc.json" || info.Name() == "sqlc.yaml" {
if info.Name() == "sqlc.json" || info.Name() == "sqlc.yaml" || info.Name() == "sqlc.yml" {
dirs = append(dirs, filepath.Dir(path))
return filepath.SkipDir
}
Expand Down
2 changes: 1 addition & 1 deletion scripts/regenerate/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func regenerate(dir string) error {
if info.IsDir() {
return nil
}
if strings.HasSuffix(path, "sqlc.json") || strings.HasSuffix(path, "sqlc.yaml") {
if strings.HasSuffix(path, "sqlc.json") || strings.HasSuffix(path, "sqlc.yaml") || strings.HasSuffix(path, "sqlc.yml") {
cwd := filepath.Dir(path)
command, err := parseExecCommand(cwd)
if err != nil {
Expand Down