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

[PROPOSAL] Generate seeds for all tables with one command #129

Closed
artemmolotov opened this issue Sep 7, 2018 · 2 comments
Closed

[PROPOSAL] Generate seeds for all tables with one command #129

artemmolotov opened this issue Sep 7, 2018 · 2 comments

Comments

@artemmolotov
Copy link

artemmolotov commented Sep 7, 2018

#24

Example of implementation:

php artisan iseed:all

Or

php artisan iseed
    /**
     * @var \Doctrine\DBAL\Connection $conn
     */
    $sm = $conn->getSchemaManager();
    $fullSchema = $sm->createSchema();
    $tables = $fullSchema->getTables(); // exclude 'migrations'

    foreach ($tables as $table) {
        // code for one table
    }
@artemmolotov
Copy link
Author

artemmolotov commented Sep 13, 2018

Currently we can use:

class ISeedAllCommand extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'iseed:all';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Make seeders for all tables by iseed';

    /**
     * @var Connection
     */
    protected $connection;

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
        $this->connection = DB::getDoctrineConnection();
    }

    /**
     * Execute the console command.
     *
     * @return void
     */
    public function handle()
    {
        $tableNames = $this->getShortestTableNames();
        $tableNames = array_diff($tableNames, ['migrations']);

        Artisan::call('iseed', [
            'tables' => implode(',', $tableNames),
            //  '--force' => true,
        ]);
    }

    protected function getShortestTableNames(): array
    {
        $sm = $this->connection->getSchemaManager();
        $databaseName = $this->connection->getDatabase();

        $fullSchema = $sm->createSchema();
        $tableNames = $fullSchema->getTableNames();

        $shortTableNames = str_replace("$databaseName.", '', $tableNames);

        return $shortTableNames;
    }
}

@artemmolotov artemmolotov reopened this Sep 25, 2018
@orangehill orangehill deleted a comment from famarojr Sep 26, 2018
@orangehill orangehill deleted a comment from artemmolotov Sep 26, 2018
@orangehill orangehill deleted a comment from famarojr Sep 26, 2018
@orangehill orangehill deleted a comment from artemmolotov Sep 26, 2018
@orangehill orangehill deleted a comment from famarojr Sep 26, 2018
@orangehill orangehill deleted a comment from artemmolotov Sep 26, 2018
@orangehill orangehill deleted a comment from famarojr Sep 26, 2018
@orangehill orangehill deleted a comment from artemmolotov Sep 26, 2018
@orangehill orangehill deleted a comment from artemmolotov Sep 26, 2018
@tihomiro
Copy link
Member

Closing. More info: #58 (comment)

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

No branches or pull requests

2 participants