feat: ✨ [NEW FEATURE] Creation of specific schemas for each team#519
feat: ✨ [NEW FEATURE] Creation of specific schemas for each team#519vqlion wants to merge 6 commits into
Conversation
| $schema->openDatabaseConnection(); | ||
| $path = $this->option('path') ?? config('database.migration_path'); | ||
|
|
||
| $this->call('migrate', ['--database' => $dbName, '--path' => $path]); |
There was a problem hiding this comment.
No error handling ?
(open question)
There was a problem hiding this comment.
I think it's unlikely that an error occurs at that point, but I guess handling it couldn't hurt and it's extra safe 👍 (ace6224)
add error handling to migrate command call issue: #517
|
…n_of_specific_schemas_for_each_team
|
There was a problem hiding this comment.
Pull Request Overview
This PR implements a new feature for creating team-specific database schemas in a Laravel application. The system allows each team to have its own isolated database schema with custom tables, managed through Artisan commands.
- Introduces Artisan commands for schema creation (
make:schema) and migration (migrate:custom) - Creates a Schema model to track team-specific database schemas
- Implements comprehensive test coverage for schema operations
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
src/tests/Feature/CustomSchemaTest.php |
Comprehensive test suite covering schema creation, migration, and error handling scenarios |
src/database/migrations/2025_01_15_143802_create_schemas_table.php |
Database migration to create the schemas tracking table |
src/app/Models/Schema.php |
Model for managing schema records with database connection utilities |
src/app/Console/Commands/MigrateCustomSchemaCommand.php |
Artisan command to execute migrations on team-specific schemas |
src/app/Console/Commands/MakeSchemaCommand.php |
Artisan command to create new team schemas and migration directories |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| use Illuminate\Database\Eloquent\Factories\HasFactory; | ||
| use Illuminate\Database\Eloquent\Model; | ||
| use Illuminate\Database\Eloquent\Relations\BelongsTo; | ||
| Use Illuminate\Database\Eloquent\SoftDeletes; |
There was a problem hiding this comment.
Corrected 'Use' to 'use' for proper PHP namespace import syntax.
| Use Illuminate\Database\Eloquent\SoftDeletes; | |
| use Illuminate\Database\Eloquent\SoftDeletes; |
| $schema['name'] = $dbName; | ||
| $schema['crew_id'] = $crew_id; | ||
| Schema::Create($schema); |
There was a problem hiding this comment.
The variable $schema is being used as an array but was previously assigned a model instance from the query. This will cause a runtime error. Should initialize as an empty array or use Schema::create() with lowercase 'c'.
| $schema['name'] = $dbName; | |
| $schema['crew_id'] = $crew_id; | |
| Schema::Create($schema); | |
| $newSchemaData = [ | |
| 'name' => $dbName, | |
| 'crew_id' => $crew_id, | |
| ]; | |
| Schema::create($newSchemaData); |



Original issue description
Original issue description @lduf (transferred to discussion https://github.com//discussions/514)
Description:
This feature introduces the ability to dynamically create specific database schemas for individual teams. Each team will have its own schema, including custom tables such as
fields,items, andlinks. The process will rely on Artisan commands to manage schema creation and migration execution, ensuring flexibility and modularity in the system. Tests will validate all functionalities to ensure a seamless experience.Tasks to Perform:
Artisan Command to Generate Specific Schemas:
TEAM_IDalready exists.Organize Schema-Specific Migrations:
/database/migrations/global: Contains global migrations./database/migrations/teams/TEAM_ID: Contains migrations specific to a team.Artisan Command to Copy and Execute Base Table Migrations:
teams/TEAM_ID.Handle Global Migration Files:
Schema Migration Execution:
Unit and Functional Testing:
closes #517