Skip to content
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

Support for mods to respect database constraints #178

Open
Joshswooft opened this issue Feb 13, 2024 · 1 comment
Open

Support for mods to respect database constraints #178

Joshswooft opened this issue Feb 13, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@Joshswooft
Copy link

Joshswooft commented Feb 13, 2024

Lets say I have a schema:

// schema.sql

CREATE TABLE instructors (
    id SERIAL PRIMARY KEY,
    first_name VARCHAR(60) NOT NULL,
    last_name VARCHAR(120) NOT NULL,
    full_name VARCHAR(255) GENERATED ALWAYS AS (first_name || ' ' || last_name) STORED,
);

CREATE TABLE lessons (
    id SERIAL PRIMARY KEY,
    instructor_id INTEGER REFERENCES instructors(id),
    status VARCHAR(20),
);

When I try to create some data, it will fail because internally the data may get generated outside the max 20-character limit imposed by the lesson status field.

bobDB := bob.New[*sql.DB](db)
dbFactory := factory.New()

dbFactory.AddBaseInstructorMod(factory.InstructorMods.RandomizeAllColumns(&myFaker), factory.InstructorMods.UnsetID())
dbFactory.AddBaseLessonMod(factory.LessonMods.RandomizeAllColumns(&myFaker), factory.LessonMods.UnsetID(), factory.LessonMods.UnsetInstructorID())

_, err = dbFactory.NewInstructor(factory.InstructorMods.WithNewLessons(10)).CreateMany(ctx, bobDB, 10)

I can get around the lesson status by defining my own mods, its a bit tedious but certainly not a roadblock.

@stephenafamo
Copy link
Owner

This will surely be useful. I'll tag it as an enhancement.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants