Skip to content

Generation of cockroachdb models and tables adds random comments #528

@jnicholsonwasabi

Description

@jnicholsonwasabi

When generating tables and models from a cockroach database, jet appears to add random comments ( that appear to be builtin cockroach functions ) to tables that do not have any user specified comments.

Environment:

  • OS: macosx
  • Database: cockroachdb
  • Database driver: n/a
  • Jet generator v2.13.0

Code snippet

# start a cockroachdb container ( any version will do )
$ docker run --rm -d -p 26257:26257 --name crdb cockroachdb/cockroach:v24.1.25 start-single-node --insecure
# add some tables
$ docker exec -it crdb bash -c 'cockroach sql --insecure'
#
# Welcome to the CockroachDB SQL shell.
# All statements must be terminated by a semicolon.
# To exit, type: \q.
#
# Server version: CockroachDB CCL v24.1.25 (aarch64-unknown-linux-gnu, built 2025/10/15 10:35:53, go1.22.12 X:nocoverageredesign) (same version as client)
# Cluster ID: 64d5580d-88d6-4b38-ae32-635df50a0396
#
# Enter \? for a brief introduction.
#
root@localhost:26257/defaultdb> CREATE TABLE users (
  id INT PRIMARY KEY,
  name STRING,
  email STRING UNIQUE
);

CREATE TABLE

Time: 13ms total (execution 10ms / network 4ms)

root@localhost:26257/defaultdb> \q
# generate the table in with jet
$ jet -source=cockroach -host=localhost -port=26257 -dbname=defaultdb -user=root -schema=public -path=gen/
Connecting to postgres database...
Retrieving schema information...
        FOUND 1 table(s), 0 view(s), 0 enum(s)
Destination directory: gen/defaultdb/public
Cleaning up destination directory...
Generating table model files...
Generating table sql builder files
# inspect the model
$ cat gen/defaultdb/public/model/users.go
//
// Code generated by go-jet DO NOT EDIT.
//
// WARNING: Changes to this file may cause incorrect behavior
// and will be lost if the code is regenerated
//

package model

// Calculates y-intercept of the least-squares-fit linear equation determined by the (X, Y) pairs.
type Users struct {
        ID    int64 `sql:"primary_key"`
        Name  *string
        Email *string
}
# inspect the generated table
$ head -n 20 gen/defaultdb/public/table/users.go
//
// Code generated by go-jet DO NOT EDIT.
//
// WARNING: Changes to this file may cause incorrect behavior
// and will be lost if the code is regenerated
//

package table

import (
        "github.com/go-jet/jet/v2/postgres"
)

var Users = newUsersTable("public", "users", "")

// Calculates y-intercept of the least-squares-fit linear equation determined by the (X, Y) pairs.
type usersTable struct {
        postgres.Table

        // Columns

The offending line is

// Calculates y-intercept of the least-squares-fit linear equation determined by the (X, Y) pairs.

You'll notice the comment above the table and model appear to be picking from one of these functions: https://www.cockroachlabs.com/docs/stable/functions-and-operators.

As you add more tables, different functions' comments appear above them.

If you add a comment to the table, there is no issue and does what is expected.

# add a comment to the table
$ docker exec -it crdb bash -c 'cockroach sql --insecure'
#
# Welcome to the CockroachDB SQL shell.
# All statements must be terminated by a semicolon.
# To exit, type: \q.
#
# Server version: CockroachDB CCL v24.1.25 (aarch64-unknown-linux-gnu, built 2025/10/15 10:35:53, go1.22.12 X:nocoverageredesign) (same version as client)
# Cluster ID: 64d5580d-88d6-4b38-ae32-635df50a0396
#
# Enter \? for a brief introduction.
#
root@localhost:26257/defaultdb> COMMENT ON TABLE users IS 'look a custom table comment';
COMMENT ON TABLE

Time: 20ms total (execution 19ms / network 0ms)

root@localhost:26257/defaultdb> \q
# regenerate with jet
$ jet -source=cockroach -host=localhost -port=26257 -dbname=defaultdb -user=root -schema=public -path=gen/
Connecting to postgres database...
Retrieving schema information...
        FOUND 1 table(s), 0 view(s), 0 enum(s)
Destination directory: gen/defaultdb/public
Cleaning up destination directory...
Generating table model files...
Generating table sql builder files
# check the generated code
$  cat gen/defaultdb/public/model/users.go
//
// Code generated by go-jet DO NOT EDIT.
//
// WARNING: Changes to this file may cause incorrect behavior
// and will be lost if the code is regenerated
//

package model

// look a custom table comment
type Users struct {
        ID    int64 `sql:"primary_key"`
        Name  *string
        Email *string
}

Expected behavior

If a table has no comment it should not have any comment proceeding the generated model and table.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinggood first issueGood for newcomers

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions