volatiletech / sqlboiler

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

mediumint unsinged out of range error #247

Closed Dexus closed 6 years ago

Dexus commented 6 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)?

last 2.6.0

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

go generate

If this happened at runtime what code produced the issue? (if not applicable leave blank)

What is the output of the command above with the -d flag added to it? (Provided you are comfortable sharing this, it contains a blueprint of your schema)

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

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

When I use smallint or int all is fine and works like excepted but for mediumint it generates a to big int for the random upsert

...
    // Attempt the UPDATE side of an UPSERT
    if err = randomize.Struct(seed, &island, islandDBTypes, false, islandPrimaryKeyColumns...); err != nil {
        t.Errorf("Unable to randomize Island struct: %s", err)
    }

    if err = island.Upsert(tx, nil); err != nil {
        t.Errorf("Unable to upsert Island: %s", err)
    }
...

The randomized medium int is here 1519643615 which will be a bit to long for a mediumint(8) which have default: 16777215 maximum...

aarondl commented 6 years ago

Hey @Dexus. This is pretty strange since we have code specifically for medium int stuff.

https://github.com/volatiletech/sqlboiler/blob/master/randomize/randomize.go#L247 https://github.com/volatiletech/sqlboiler/blob/master/randomize/randomize.go#L324

I took a pass at randomize in v3, I wonder if it got fixed by miracle since my changes were so pervasive.

Anything else you can tell me about this? Maybe what the Column looks like in --debug? I don't need the entire output, just that one column.

Dexus commented 6 years ago

Give me the next weekend, so i can check it. Currently i'm on a workshop and dont have access to the source.