volatiletech / sqlboiler

Generate a Go ORM tailored to your database schema.
BSD 3-Clause "New" or "Revised" License
6.66k stars 539 forks source link

NO_TESTS env var ignore and field duplication #1176

Open andrei-dascalu opened 2 years ago

andrei-dascalu commented 2 years ago

If you're having a generation problem please answer these questions before submitting your issue. Thanks!

What version of SQLBoiler are you using (sqlboiler --version)?

SQLBoiler v4.12.0

What is your database and version (eg. Postgresql 10)

mySQL 5.7.33

If this happened at generation time what was the full SQLBoiler command you used to generate your models? (if not applicable leave blank)

sqlboiler mysql

Please provide a relevant database schema so we can replicate your issue (Provided you are comfortable sharing this)

Will work on providing something relevant, if needed

Further information. What did you do, what did you expect?

I have encountered 2 issues:

  1. I've set environment variables (for db config prefixed with MYSQL), as follows
OUTPUT="src/models"
WIPE=true
NO_TESTS=true
ADD_ENUM_TYPES="true"

Although I've tried both with quotes and without quotes, NO_TESTS seems to be ignored all the time (all other config work as expected). Tests are always generated.

  1. For some entities, I get some strange field duplications:
var NewsletterSendResultColumns = struct {
    ID               string
    NewsletterId     string
    ClientId         string
    Email            string
    NewsletterStatus string
    ID               string
    RejectReason     string
    Timestamp        string
}{
    ID:               "Id",
    NewsletterId:     "NewsletterId",
    ClientId:         "ClientId",
    Email:            "Email",
    NewsletterStatus: "NewsletterStatus",
    ID:               "_id",
    RejectReason:     "Reject_Reason",
    Timestamp:        "Timestamp",
}

Ok, so there is a field called _id which technically is different and has a different name. I'm not sure if this a case that you'd considering handling differently, perhaps via some override parameters or some preset rules on handling potential conflicts. One such way would be to move the stripped character to a suffix (eg ID_ which is valid)

stephenafamo commented 2 years ago

I'll check out the issue with the NO_TESTS env variable. In the meantime, perhaps you can add the flag --no-tests whenever you run the command.

For the _id field. Your best option will be to use an alias. In most cases, a table will not have both id and _id and it is better for the user experience if _id is just id. Ideally, SQLBoiler will check all other columns and maybe add the suffix instead of the duplication you are facing now.

Since this is a rare scenario that can easily be solved by adding an alias in your config, I doubt if we would change this behaviour.