Вход Регистрация
Файл: vendor/laravel/framework/src/Illuminate/Database/Schema/SqliteSchemaState.php
Строк: 115
<?php

namespace IlluminateDatabaseSchema;

use 
IlluminateDatabaseConnection;

class 
SqliteSchemaState extends SchemaState
{
    
/**
     * Dump the database's schema into a file.
     *
     * @param  IlluminateDatabaseConnection  $connection
     * @param  string  $path
     * @return void
     */
    
public function dump(Connection $connection$path)
    {
        
with($process $this->makeProcess(
            
$this->baseCommand().' .schema'
        
))->setTimeout(null)->mustRun(nullarray_merge($this->baseVariables($this->connection->getConfig()), [
            
//
        
]));

        
$migrations collect(preg_split("/rn|n|r/"$process->getOutput()))->filter(function ($line) {
            return 
stripos($line'sqlite_sequence') === false &&
                   
strlen($line) > 0;
        })->
all();

        
$this->files->put($pathimplode(PHP_EOL$migrations).PHP_EOL);

        if (
$this->hasMigrationTable()) {
            
$this->appendMigrationData($path);
        }
    }

    
/**
     * Append the migration data to the schema dump.
     *
     * @param  string  $path
     * @return void
     */
    
protected function appendMigrationData(string $path)
    {
        
with($process $this->makeProcess(
            
$this->baseCommand().' ".dump ''.$this->migrationTable.''"'
        
))->mustRun(nullarray_merge($this->baseVariables($this->connection->getConfig()), [
            
//
        
]));

        
$migrations collect(preg_split("/rn|n|r/"$process->getOutput()))->filter(function ($line) {
            return 
preg_match('/^s*(--|INSERTs)/iu'$line) === &&
                   
strlen($line) > 0;
        })->
all();

        
$this->files->append($pathimplode(PHP_EOL$migrations).PHP_EOL);
    }

    
/**
     * Load the given schema file into the database.
     *
     * @param  string  $path
     * @return void
     */
    
public function load($path)
    {
        if (
$this->connection->getDatabaseName() === ':memory:') {
            
$this->connection->getPdo()->exec($this->files->get($path));

            return;
        }

        
$process $this->makeProcess($this->baseCommand().' < "${:LARAVEL_LOAD_PATH}"');

        
$process->mustRun(nullarray_merge($this->baseVariables($this->connection->getConfig()), [
            
'LARAVEL_LOAD_PATH' => $path,
        ]));
    }

    
/**
     * Get the base sqlite command arguments as a string.
     *
     * @return string
     */
    
protected function baseCommand()
    {
        return 
'sqlite3 "${:LARAVEL_LOAD_DATABASE}"';
    }

    
/**
     * Get the base variables for a dump / load command.
     *
     * @param  array  $config
     * @return array
     */
    
protected function baseVariables(array $config)
    {
        return [
            
'LARAVEL_LOAD_DATABASE' => $config['database'],
        ];
    }
}
Онлайн: 0
Реклама