Skip to content

feat: ✨ [NEW FEATURE] Creation of specific schemas for each team#519

Open
vqlion wants to merge 6 commits into
master/devfrom
feature/issue-517-_NEW_FEATURE_Creation_of_specific_schemas_for_each_team
Open

feat: ✨ [NEW FEATURE] Creation of specific schemas for each team#519
vqlion wants to merge 6 commits into
master/devfrom
feature/issue-517-_NEW_FEATURE_Creation_of_specific_schemas_for_each_team

Conversation

@vqlion
Copy link
Copy Markdown
Contributor

@vqlion vqlion commented Jan 17, 2025

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, and links. 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:

  1. Artisan Command to Generate Specific Schemas:

    • Implement an Artisan command:
      php artisan make:schema TEAM_ID
    • This command must:
      • Verify if a schema for TEAM_ID already exists.
      • Create a new schema in the database if it does not exist.
  2. Organize Schema-Specific Migrations:

    • Establish a directory structure for migrations:
      • /database/migrations/global: Contains global migrations.
      • /database/migrations/teams/TEAM_ID: Contains migrations specific to a team.
  3. Artisan Command to Copy and Execute Base Table Migrations:

    • Implement an Artisan command:
      php artisan migration:copy TABLE_NAME SCHEMA
    • This command must:
      • Copy all required global migration files into the directory teams/TEAM_ID.
      • Execute the copied migrations in the specified schema.
  4. Handle Global Migration Files:

    • Approach: Direct Copy of Global Files
      • Identify all global migrations associated with a table and copy them into the team-specific schema directory.
      • Retain the complete history of table changes.
  5. Schema Migration Execution:

    • Execute all migrations in a specified schema using an Artisan command.
  6. Unit and Functional Testing:

    • Develop tests to validate the following functionalities:
      • Creating a specific schema.
      • Executing migrations within a specific schema.
      • Verifying the creation of the necessary tables.
    • Test cases:
      • A team with an existing schema.
      • A team requiring multiple global migration files for a single table.

closes #517

- add command to create a schema for a specific team
- add schema model

issue: #517
- add command to migrate a specific schema from a team
- can provide a custom migration path for teams specific migrations

issue: #517
@vqlion vqlion added the New feature New feature or request label Jan 17, 2025
@vqlion vqlion self-assigned this Jan 17, 2025
@vqlion vqlion linked an issue Jan 17, 2025 that may be closed by this pull request
the create schema command also creates a migration folder for the team

issue: #517
- test creating a new custom schema for a team
- test migrate to a custom schema

issue: #517
@vqlion vqlion marked this pull request as ready for review January 21, 2025 15:40
@vqlion vqlion requested a review from lduf January 21, 2025 15:41
$schema->openDatabaseConnection();
$path = $this->option('path') ?? config('database.migration_path');

$this->call('migrate', ['--database' => $dbName, '--path' => $path]);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

No error handling ?

(open question)

Copy link
Copy Markdown
Contributor Author

@vqlion vqlion Jan 31, 2025

Choose a reason for hiding this comment

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

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
@sonarqubecloud
Copy link
Copy Markdown

@lduf lduf enabled auto-merge February 18, 2025 22:00
@sonarqubecloud
Copy link
Copy Markdown

@lduf lduf requested a review from Copilot October 13, 2025 11:11
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

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.

Comment thread src/app/Models/Schema.php
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
Use Illuminate\Database\Eloquent\SoftDeletes;
Copy link

Copilot AI Oct 13, 2025

Choose a reason for hiding this comment

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

Corrected 'Use' to 'use' for proper PHP namespace import syntax.

Suggested change
Use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Database\Eloquent\SoftDeletes;

Copilot uses AI. Check for mistakes.
Comment on lines +63 to +65
$schema['name'] = $dbName;
$schema['crew_id'] = $crew_id;
Schema::Create($schema);
Copy link

Copilot AI Oct 13, 2025

Choose a reason for hiding this comment

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

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'.

Suggested change
$schema['name'] = $dbName;
$schema['crew_id'] = $crew_id;
Schema::Create($schema);
$newSchemaData = [
'name' => $dbName,
'crew_id' => $crew_id,
];
Schema::create($newSchemaData);

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

New feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[NEW FEATURE] Creation of specific schemas for each team

3 participants