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

[11.x] Support Model::class Table Discovery in Migrations Schema #52845

Conversation

devajmeireles
Copy link
Contributor

@devajmeireles devajmeireles commented Sep 18, 2024

This PR consists of adding the same support we have for test stuff like:

$this->assertDatabaseHas(User::class, [...]);

$this->assertDatabaseMissing(User::class, [...]);

$this->assertDatabaseEmpty(User::class);

$this->assertDatabaseCount(User::class, 1);

... but thinking about migrations, making possible things like:

Schema::table(User::class, function (Blueprint $table) {
    /* ... */
});

The main benefit of this is that it allows us to fix the name of the table defined through the model, which can be reused mainly in the table method, making errors related to the table name impossible.

@aligulzar729
Copy link

@devajmeireles I believe migrations and models should remain decoupled and operate independently since they represent different abstraction layers within the application.

  1. Migrations are focused on database schema management, while models represent the business logic in an OOP context. Mixing these layers adds unnecessary complexity.
  2. Migrations need to run in isolation, especially in environments like CI/CD pipelines or during headless deployments, where models may not even be available. Introducing a dependency on models would complicate this process.
  3. This approach also raises challenges for scenarios like multi-tenant systems or applications with dynamic tables, where table names can vary at runtime.

Keeping migrations and models separate ensures flexibility, simplicity, and a clear separation of concerns.
Thank you for your collaboration.

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.

2 participants