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

hackgreenville-com-435 Build out db seeders to create an org and some org related data #438

Draft
wants to merge 6 commits into
base: develop
Choose a base branch
from

Conversation

zach2825
Copy link
Collaborator

@zach2825 zach2825 commented Nov 5, 2024

resolves #435

@zach2825
Copy link
Collaborator Author

zach2825 commented Nov 5, 2024

I need to track down why the tests are failing, I might need to combine this PR with #437 to help resolve the failure

Comment on lines +1 to +12
<?php

namespace App\Traits;

trait HasSlug
{
public static bool $update_slug = false;

public static function bootHasSlug()
{
static::creating(function ($model) {
if ( ! $model[self::$slug_column ?? 'slug']) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My initial reaction is, do we need this?
Also, if we need this to be "automatic" we should use a package that way we do not need to maintain this code.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens when the package goes away or becomes unmaintained? This is a relatively straightforward approach

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find it hard to believe that a spatie package goes away, again, I think the less custom stuff we need to maintain and bugfix the better.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. This does seem like code we shouldn't maintain ourselves, personally.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This missing functionality has been in place for a while. I tried to implement a simple solution using laravel methods and practices. If there is a suggested package, either links it or creates a PR to this branch or something to resolve the discrepancy.

@irby or @bogdankharchenko

'address' => $this->faker->address,
'zipcode' => $this->faker->postcode,
'country' => $this->faker->countryCode(),
'phone' => $this->faker->phoneNumber,
'city' => $this->faker->city,
'state_id' => State::factory(),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be a factory

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't want to generate random states for new venues. Take note of the next line where it selects a random existing state.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to check to see if a state exists first or is that secured by the migration done here?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not against what is being done below, but what's the motivation behind this change? Just the fact that our tests are generating a new state value for each venue created?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@irby the State::inRandomOrder()->first() code selects a random existing state from the database.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should not create a new state. Moving the states into a migration ensures they are safely created in the database. The migration only makes the state if it does not exist.

Doing it as a seeder in tests, working in general, is more of a pain since you need to make sure to run seeders and since this is required data for things to work. It should be a migration.

@bogdankharchenko bogdankharchenko marked this pull request as draft November 5, 2024 15:13
app/Models/Event.php Outdated Show resolved Hide resolved
$org->category()->associate($category);

// Recycle or create events
$events = Event::inRandomOrder()->limit(random_int(1, 10))->get();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why would we want to grab existing events and attach them to a new org? I would think we could just generate a random amount of new events with the factory and just attach them to the org.

Also, would we want to store random_int(1, 10) as a variable? Wouldn't referencing it as we are cause a new random value to be generated for each call?

'address' => $this->faker->address,
'zipcode' => $this->faker->postcode,
'country' => $this->faker->countryCode(),
'phone' => $this->faker->phoneNumber,
'city' => $this->faker->city,
'state_id' => State::factory(),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to check to see if a state exists first or is that secured by the migration done here?

'address' => $this->faker->address,
'zipcode' => $this->faker->postcode,
'country' => $this->faker->countryCode(),
'phone' => $this->faker->phoneNumber,
'city' => $this->faker->city,
'state_id' => State::factory(),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not against what is being done below, but what's the motivation behind this change? Just the fact that our tests are generating a new state value for each venue created?

Comment on lines +1 to +12
<?php

namespace App\Traits;

trait HasSlug
{
public static bool $update_slug = false;

public static function bootHasSlug()
{
static::creating(function ($model) {
if ( ! $model[self::$slug_column ?? 'slug']) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. This does seem like code we shouldn't maintain ourselves, personally.

.tool-versions Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Build out db seeders to create an org and some org related data
3 participants