Skip to content

Commit bcbf8b5

Browse files
authored
Merge pull request #200 from cloudspannerecosystem/deprecated-gen-information-schema
Deprecate generation from Information Schema
2 parents 9c95b38 + 3e29405 commit bcbf8b5

4 files changed

Lines changed: 59 additions & 28 deletions

File tree

README.md

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@
33
`yo` is a command-line tool to generate Go code for [Google Cloud Spanner](https://cloud.google.com/spanner/),
44
forked from [xo](https://github.com/xo/xo) :rose:.
55

6-
`yo` uses database schema to generate code by using [Information Schema](https://cloud.google.com/spanner/docs/information-schema). `yo` runs SQL queries against tables in `INFORMATION_SCHEMA` to fetch metadata for a database, and applies the metadata to Go templates to generate code/models to access Cloud Spanner.
6+
`yo` can generate code from database schema using either DDL files or [Information Schema](https://cloud.google.com/spanner/docs/information-schema).
7+
8+
**⚠️ Note: Using Information Schema for code generation is now deprecated due to column ordering issues (see [#154](https://github.com/cloudspannerecosystem/yo/issues/154)). Please use DDL files for reliable code generation instead.**
9+
10+
When using Information Schema, `yo` runs SQL queries against tables in `INFORMATION_SCHEMA` to fetch metadata for a database. When using DDL files (recommended), `yo` parses the DDL directly. In both cases, the metadata is applied to Go templates to generate code/models to access Cloud Spanner.
711

812
Please feel free to report issues and send pull requests, but note that this
913
application is not officially supported as part of the Cloud Spanner product.
@@ -24,14 +28,24 @@ go get -u go.mercari.io/yo
2428

2529
The following is a quick overview of using `yo` on the command-line:
2630

31+
**Recommended: Generate from DDL file**
2732
```sh
2833
# change to project directory
2934
$ cd $GOPATH/src/path/to/project
3035

3136
# make an output directory
3237
$ mkdir -p models
3338

34-
# generate code for a schema
39+
# generate code from DDL file (recommended)
40+
$ yo generate schema.sql --from-ddl -o models
41+
```
42+
43+
**⚠️ Deprecated: Generate from Information Schema**
44+
```sh
45+
# make an output directory
46+
$ mkdir -p models
47+
48+
# generate code from Information Schema (deprecated - see issue #154)
3549
$ yo $SPANNER_PROJECT_NAME $SPANNER_INSTANCE_NAME $SPANNER_DATABASE_NAME -o models
3650
```
3751

@@ -47,16 +61,16 @@ Usage:
4761
yo PROJECT_NAME INSTANCE_NAME DATABASE_NAME [flags]
4862

4963
Examples:
50-
# Generate models from DDL under the models directory
51-
yo generate schame.sql --from-ddl -o models
52-
53-
# Generate models from DDL under the models directory with custom types
54-
yo generate schame.sql --from-ddl -o models --custom-types-file custom_column_types.yml
55-
56-
# Generate models under models directory
64+
# Generate models from DDL under the models directory (recommended)
65+
yo generate schema.sql --from-ddl -o models
66+
67+
# Generate models from DDL under the models directory with custom types (recommended)
68+
yo generate schema.sql --from-ddl -o models --custom-types-file custom_column_types.yml
69+
70+
# Generate models under models directory (deprecated - see issue #154)
5771
yo $SPANNER_PROJECT_NAME $SPANNER_INSTANCE_NAME $SPANNER_DATABASE_NAME -o models
5872

59-
# Generate models under models directory with custom types
73+
# Generate models under models directory with custom types (deprecated - see issue #154)
6074
yo $SPANNER_PROJECT_NAME $SPANNER_INSTANCE_NAME $SPANNER_DATABASE_NAME -o models --custom-types-file custom_column_types.yml
6175

6276
Flags:

cmd/generate.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ package cmd
2121

2222
import (
2323
"fmt"
24+
"os"
2425

2526
"github.com/spf13/cobra"
2627
"go.mercari.io/yo/generator"
@@ -39,16 +40,16 @@ var (
3940
}
4041
return nil
4142
},
42-
Example: ` # Generate models from ddl under models directory
43+
Example: ` # Generate models from ddl under models directory (recommended)
4344
yo generate schema.sql --from-ddl -o models
4445
45-
# Generate models from ddl under models directory with custom types
46+
# Generate models from ddl under models directory with custom types (recommended)
4647
yo generate schema.sql --from-ddl -o models --custom-types-file custom_column_types.yml
4748
48-
# Generate models under models directory
49+
# Generate models under models directory (deprecated - see issue #154)
4950
yo generate $SPANNER_PROJECT_NAME $SPANNER_INSTANCE_NAME $SPANNER_DATABASE_NAME -o models
5051
51-
# Generate models under models directory with custom types
52+
# Generate models under models directory with custom types (deprecated - see issue #154)
5253
yo generate $SPANNER_PROJECT_NAME $SPANNER_INSTANCE_NAME $SPANNER_DATABASE_NAME -o models --custom-types-file custom_column_types.yml
5354
`,
5455
RunE: func(cmd *cobra.Command, args []string) error {
@@ -68,6 +69,7 @@ var (
6869
}
6970
loader = internal.NewTypeLoader(spannerLoader, inflector)
7071
} else {
72+
fmt.Fprintf(os.Stderr, "Warning: Using Information Schema for code generation is deprecated due to column ordering issues (see https://github.com/cloudspannerecosystem/yo/issues/154). Please use DDL files for reliable code generation instead.\n")
7173
spannerClient, err := connectSpanner(&rootOpts)
7274
if err != nil {
7375
return fmt.Errorf("error: %v", err)

v2/README.md

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@
33
`yo` is a command-line tool to generate Go code for [Google Cloud Spanner](https://cloud.google.com/spanner/),
44
forked from [xo](https://github.com/xo/xo) :rose:.
55

6-
`yo` uses database schema to generate code by using [Information Schema](https://cloud.google.com/spanner/docs/information-schema). `yo` runs SQL queries against tables in `INFORMATION_SCHEMA` to fetch metadata for a database and applies the metadata to Go templates to generate code/models to access Cloud Spanner.
6+
`yo` can generate code from database schema using either DDL files or [Information Schema](https://cloud.google.com/spanner/docs/information-schema).
7+
8+
**⚠️ Note: Using Information Schema for code generation is now deprecated due to column ordering issues (see [#154](https://github.com/cloudspannerecosystem/yo/issues/154)). Please use DDL files for reliable code generation instead.**
9+
10+
When using Information Schema, `yo` runs SQL queries against tables in `INFORMATION_SCHEMA` to fetch metadata for a database. When using DDL files (recommended), `yo` parses the DDL directly. In both cases, the metadata is applied to Go templates to generate code/models to access Cloud Spanner.
711

812
Please feel free to report issues and send pull requests, but note that this
913
application is not officially supported as part of the Cloud Spanner product.
@@ -18,14 +22,24 @@ $ go get -u go.mercari.io/yo/v2
1822

1923
The following is a quick overview of using `yo` on the command line:
2024

25+
**Recommended: Generate from DDL file**
2126
```sh
2227
# change to the project directory
2328
$ cd $GOPATH/src/path/to/project
2429

2530
# make an output directory
2631
$ mkdir -p models
2732

28-
# generate code for a schema
33+
# generate code from DDL file (recommended)
34+
$ yo generate schema.sql --from-ddl -o models
35+
```
36+
37+
**⚠️ Deprecated: Generate from Information Schema**
38+
```sh
39+
# make an output directory
40+
$ mkdir -p models
41+
42+
# generate code from Information Schema (deprecated - see issue #154)
2943
$ yo generate $SPANNER_PROJECT_NAME $SPANNER_INSTANCE_NAME $SPANNER_DATABASE_NAME -o models
3044
```
3145

@@ -38,17 +52,17 @@ The `generate` command generates the Go code from DDL.
3852
#### Examples
3953

4054
```sh
41-
# Generate models from DDL under the models directory
55+
# Generate models from DDL under the models directory (recommended)
4256
yo generate schema.sql --from-ddl -o models
4357

44-
# Generate models from DDL under the models directory with custom types
45-
yo generate schema.sql --from-ddl -o models --custom-types-file custom_column_types.yml
58+
# Generate models from DDL under the models directory with custom types (recommended)
59+
yo generate schema.sql --from-ddl -o models --config config.yml
4660

47-
# Generate models under the models directory
61+
# Generate models under the models directory (deprecated - see issue #154)
4862
yo generate $SPANNER_PROJECT_NAME $SPANNER_INSTANCE_NAME $SPANNER_DATABASE_NAME -o models
4963

50-
# Generate models under the models directory with custom types
51-
yo generate $SPANNER_PROJECT_NAME $SPANNER_INSTANCE_NAME $SPANNER_DATABASE_NAME -o models --custom-types-file custom_column_types.yml
64+
# Generate models under the models directory with custom types (deprecated - see issue #154)
65+
yo generate $SPANNER_PROJECT_NAME $SPANNER_INSTANCE_NAME $SPANNER_DATABASE_NAME -o models --config config.yml
5266
```
5367

5468
#### Flags

v2/cmd/generate.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -112,17 +112,17 @@ var (
112112
}
113113
return nil
114114
},
115-
Example: ` # Generate models from DDL under the models directory
115+
Example: ` # Generate models from DDL under the models directory (recommended)
116116
yo generate schema.sql --from-ddl -o models
117117
118-
# Generate models from DDL under the models directory with custom types
119-
yo generate schema.sql --from-ddl -o models --custom-types-file custom_column_types.yml
118+
# Generate models from DDL under the models directory with custom types (recommended)
119+
yo generate schema.sql --from-ddl -o models --config config.yml
120120
121-
# Generate models under the models directory
121+
# Generate models under the models directory (deprecated - see issue #154)
122122
yo generate $SPANNER_PROJECT_NAME $SPANNER_INSTANCE_NAME $SPANNER_DATABASE_NAME -o models
123123
124-
# Generate models under the models directory with custom types
125-
yo generate $SPANNER_PROJECT_NAME $SPANNER_INSTANCE_NAME $SPANNER_DATABASE_NAME -o models --custom-types-file custom_column_types.yml
124+
# Generate models under the models directory with custom types (deprecated - see issue #154)
125+
yo generate $SPANNER_PROJECT_NAME $SPANNER_INSTANCE_NAME $SPANNER_DATABASE_NAME -o models --config config.yml
126126
`,
127127
RunE: func(cmd *cobra.Command, args []string) error {
128128
ctx, cancel := context.WithTimeout(context.Background(), 60*time.Second)
@@ -149,6 +149,7 @@ var (
149149
return fmt.Errorf("failed to create spanner loader: %v", err)
150150
}
151151
} else {
152+
fmt.Fprintf(os.Stderr, "Warning: Using Information Schema for code generation is deprecated due to column ordering issues (see https://github.com/cloudspannerecosystem/yo/issues/154). Please use DDL files for reliable code generation instead.\n")
152153
spannerClient, err := connectSpanner(ctx, generateCmdOpts.Project, generateCmdOpts.Instance, generateCmdOpts.Database)
153154
if err != nil {
154155
return fmt.Errorf("failed to connect spanner: %v", err)

0 commit comments

Comments
 (0)