修复seeder错误;删除第三方的think迁移工具,在extend中重新实现;

This commit is contained in:
2023-09-20 15:35:20 +08:00
parent 0b23e0a940
commit 85f2f29b81
91 changed files with 20798 additions and 66 deletions

View File

@@ -0,0 +1,222 @@
<?php
/**
* MIT License
* For full license information, please view the LICENSE file that was distributed with this source code.
*/
namespace Phinx\Seed;
use Phinx\Db\Adapter\AdapterInterface;
use Phinx\Db\Table;
use think\console\Input as InputInterface;
use think\console\Output as OutputInterface;
/**
* Abstract Seed Class.
*
* It is expected that the seeds you write extend from this class.
*
* This abstract class proxies the various database methods to your specified
* adapter.
*
* @author Rob Morgan <robbym@gmail.com>
*/
abstract class AbstractSeed implements SeedInterface
{
/**
* @var string
*/
protected $environment;
/**
* @var \Phinx\Db\Adapter\AdapterInterface
*/
protected $adapter;
/**
* @var \think\console\Input
*/
protected $input;
/**
* @var \think\console\Output
*/
protected $output;
/**
* Override to specify dependencies for dependency injection from the configured PSR-11 container
*/
public function __construct()
{
}
/**
* @inheritDoc
*/
public function run(): void
{
}
/**
* @inheritDoc
*/
public function getDependencies(): array
{
return [];
}
/**
* @inheritDoc
*/
public function setEnvironment(string $environment)
{
$this->environment = $environment;
return $this;
}
/**
* @inheritDoc
*/
public function getEnvironment(): string
{
return $this->environment;
}
/**
* @inheritDoc
*/
public function setAdapter(AdapterInterface $adapter): SeedInterface
{
$this->adapter = $adapter;
return $this;
}
/**
* @inheritDoc
*/
public function getAdapter(): AdapterInterface
{
return $this->adapter;
}
/**
* @inheritDoc
*/
public function setInput(InputInterface $input)
{
$this->input = $input;
return $this;
}
/**
* @inheritDoc
*/
public function getInput(): InputInterface
{
return $this->input;
}
/**
* @inheritDoc
*/
public function setOutput(OutputInterface $output): SeedInterface
{
$this->output = $output;
return $this;
}
/**
* @inheritDoc
*/
public function getOutput(): OutputInterface
{
return $this->output;
}
/**
* @inheritDoc
*/
public function getName(): string
{
return static::class;
}
/**
* @inheritDoc
*/
public function execute(string $sql, array $params = [])
{
return $this->getAdapter()->execute($sql, $params);
}
/**
* @inheritDoc
*/
public function query(string $sql, array $params = [])
{
return $this->getAdapter()->query($sql, $params);
}
/**
* @inheritDoc
*/
public function fetchRow(string $sql)
{
return $this->getAdapter()->fetchRow($sql);
}
/**
* @inheritDoc
*/
public function fetchAll(string $sql): array
{
return $this->getAdapter()->fetchAll($sql);
}
/**
* @inheritDoc
*/
public function insert(string $table, array $data): void
{
// convert to table object
if (is_string($table)) {
$table = new Table($table, [], $this->getAdapter());
}
$table->insert($data)->save();
}
/**
* @inheritDoc
*/
public function hasTable(string $tableName): bool
{
return $this->getAdapter()->hasTable($tableName);
}
/**
* @inheritDoc
*/
public function table(string $tableName, array $options = []): Table
{
return new Table($tableName, $options, $this->getAdapter());
}
/**
* Checks to see if the seed should be executed.
*
* Returns true by default.
*
* You can use this to prevent a seed from executing.
*
* @return bool
*/
public function shouldExecute(): bool
{
return true;
}
}

View File

@@ -0,0 +1,20 @@
<?php
$namespaceDefinition
use $useClassName;
class $className extends $baseClassName
{
/**
* Run Method.
*
* Write your database seeder using this method.
*
* More information on writing seeders is available here:
* https://book.cakephp.org/phinx/0/en/seeding.html
*/
public function run(): void
{
}
}

View File

@@ -0,0 +1,188 @@
<?php
/**
* MIT License
* For full license information, please view the LICENSE file that was distributed with this source code.
*/
namespace Phinx\Seed;
use Phinx\Db\Adapter\AdapterInterface;
use think\console\Input as InputInterface;
use think\console\Output as OutputInterface;
/**
* Seed interface
*
* @author Rob Morgan <robbym@gmail.com>
*/
interface SeedInterface
{
/**
* @var string
*/
public const RUN = 'run';
/**
* @var string
*/
public const INIT = 'init';
/**
* Run the seeder.
*
* @return void
*/
public function run(): void;
/**
* Return seeds dependencies.
*
* @return array
*/
public function getDependencies(): array;
/**
* Sets the environment.
*
* @return $this
*/
public function setEnvironment(string $environment);
/**
* Gets the environment.
*
* @return string
*/
public function getEnvironment(): string;
/**
* Sets the database adapter.
*
* @param \Phinx\Db\Adapter\AdapterInterface $adapter Database Adapter
* @return $this
*/
public function setAdapter(AdapterInterface $adapter);
/**
* Gets the database adapter.
*
* @return \Phinx\Db\Adapter\AdapterInterface
*/
public function getAdapter(): AdapterInterface;
/**
* Sets the input object to be used in migration object
*
* @param \think\console\Input $input Input
* @return $this
*/
public function setInput(InputInterface $input);
/**
* Gets the input object to be used in migration object
*
* @return \think\console\Input
*/
public function getInput(): InputInterface;
/**
* Sets the output object to be used in migration object
*
* @param \think\console\Output $output Output
* @return $this
*/
public function setOutput(OutputInterface $output);
/**
* Gets the output object to be used in migration object
*
* @return \think\console\Output
*/
public function getOutput(): OutputInterface;
/**
* Gets the name.
*
* @return string
*/
public function getName(): string;
/**
* Executes a SQL statement and returns the number of affected rows.
*
* @param string $sql SQL
* @param array $params parameters to use for prepared query
* @return int
*/
public function execute(string $sql, array $params = []);
/**
* Executes a SQL statement.
*
* The return type depends on the underlying adapter being used. To improve
* IDE auto-completion possibility, you can overwrite the query method
* phpDoc in your (typically custom abstract parent) seed class, where
* you can set the return type by the adapter in your current use.
*
* @param string $sql SQL
* @param array $params parameters to use for prepared query
* @return mixed
*/
public function query(string $sql, array $params = []);
/**
* Executes a query and returns only one row as an array.
*
* @param string $sql SQL
* @return array|false
*/
public function fetchRow(string $sql);
/**
* Executes a query and returns an array of rows.
*
* @param string $sql SQL
* @return array
*/
public function fetchAll(string $sql): array;
/**
* Insert data into a table.
*
* @param string $tableName Table name
* @param array $data Data
* @return void
*/
public function insert(string $tableName, array $data): void;
/**
* Checks to see if a table exists.
*
* @param string $tableName Table name
* @return bool
*/
public function hasTable(string $tableName): bool;
/**
* Returns an instance of the <code>\Table</code> class.
*
* You can use this class to create and manipulate tables.
*
* @param string $tableName Table name
* @param array<string, mixed> $options Options
* @return \Phinx\Db\Table
*/
public function table(string $tableName, array $options): \Phinx\Db\Table;
/**
* Checks to see if the seed should be executed.
*
* Returns true by default.
*
* You can use this to prevent a seed from executing.
*
* @return bool
*/
public function shouldExecute(): bool;
}