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

Expand Blueprint into DatabaseBlueprint, SchemaBlueprint, and TableBlueprint #201

Open
wants to merge 5 commits into
base: v1.x
Choose a base branch
from

Conversation

AdamLenda
Copy link

@AdamLenda AdamLenda commented Mar 26, 2021

These changes extend the work that was done in https://github.com/reliese/laravel/pull/200/files

The new classes define a (hopefully) "idealized" representation of meta data from a database.

In the case of SchemaBlueprint it is a wrapper around a the existing Schema implementations.

The reason it is implemented as a "wrapper" is to ensure that previous implementations can be "adapted" to fit a new object model that organizes blueprints as a hierarchy of blueprints.

intended usage:

    public function handle()
    {
        $connection = $this->getConnection();
        $schema = $this->getSchema($connection);
        $table = $this->getTable();

        $schemaBlueprint = $this->blueprintFactory->database($connection)->schema($schema);

        $tableBlueprints = [];
        // Check whether we just need to generate one table
        if ($table) {
            $tableBlueprints[] = $schemaBlueprint->table($table);
        } else {
            $tableBlueprints = $schemaBlueprint->allTables($table);
        }
        
        /* TODO: allow command options to override the blueprint definition */

        // convert Blueprints into Model definitions
        $modelManager = new ModelManager($config);
        foreach ($tableBlueprints as $tableBlueprint) {
            $model = $this->modelFactory->fromTableBlueprint($tableBlueprint);
            $modelManager->addModel($model);
        }
        
        $modelManager->generateModelFiles();
        
    }

/**
* @var SchemaBlueprint[]
*/
private $schemaBlueprints;
Copy link
Member

Choose a reason for hiding this comment

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

Even though PHP might work this way, we should give an initial value to our variables.

Suggested change
private $schemaBlueprints;
private $schemaBlueprints = [];

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.

None yet

2 participants