-
Notifications
You must be signed in to change notification settings - Fork 39
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
Factories generate ID's outside the int32 range #158
Comments
I've managed to temporarily get around this issue by supplying my own mod that implements the EmployeeMod interface. So others can also benefit from this workaround I'll supply the solution below:
The generation slightly changes to:
Hope this helps anyone facing this issue until a solution is found :) PS. I am loving this library so far, particularly the type-safe query building so please keep up the good work 💯 |
So, the real issue is that the database driver should set the type of the column to What codegen driver are you using? Side note, to supply custom mods, you can write much less code by using one of the generated column mods. dbFactory.AddBaseEmployeeMod(
factory.EmployeeMods.RandomizeAllColumns(&myFaker),
factory.EmployeeMods.IDFunc(func() int { return rand.Intn(1<<31 - 1) }),
) Also, if you do not need the faker to be initialized with a specific seed, you can use |
I'm using the postgres driver. (Using postgres v15). Thanks for the additional information I'll make sure to refactor my solution :) Ps. Seed is needed for my scenario to ensure that the generated data is consistent each time |
I'll also need to know the column type being mapped to |
Yeah this is the rough schema: schema.sql
(Atlas version: atlas version v0.13.2-93d5aeb-canary)
To find the underlying table structure I run this query: query:
Which prints:
Seems to be correct according to the postgres docs: https://www.postgresql.org/docs/current/datatype-numeric.html#DATATYPE-SERIAL |
To clarify, are you using |
I'm using this command to generate the ORM:
Then my
I want to use the bobgen-atlas in the future but atm I can't seem to connect to my table using it but the boben-psql is working fine for now :) |
|
Good to know 👍, I'm new to atlas and HCL thats why I'm keeping to SQL for now. Although I suppose I can always generate the hcl file from my schema.sql 🤔 if this is a problem that doesn't happen in the bobgen-atlas library. |
When you map through the postgres serial types
Should you change the type to int32 if it's serial or serial4? Probably being naive here and haven't looked at what other impact this would cause |
This should already be fixed on the A number of improvements have been made for randomization, including generated tests for randomization. Try running from the latest commit, and let me know if you're still running into issues. |
I've updated |
@stephenafamo latest commit worked for me thanks 🦄 🦖 🔥, can we expect a new release to come out with this fix? |
Likely over the weekend. Can't think of anything else I want to add before a release |
Released |
I'm trying to seed my database with some random data using the factories bob generates from my schema and noticed that my script is failing due to the number faker generates is above the threshold for my ID field.
bob version:
v0.23.2
jaswdr faker version:
v1.19.1
Schema:
Error I receive:
Under the hood the
RandomizeAllColumns
will call the following bob code:Sure enough in my debugger If i inspect
tmpl.ID()
I get back608747136543856411
which is larger than the max int32 (2,147,483,647
)which later causes the error in the bob library
exec.goL114
The text was updated successfully, but these errors were encountered: