This commit is contained in:
wangjinlei
2020-11-12 17:15:37 +08:00
parent 824380664c
commit 1abf99316f
893 changed files with 278997 additions and 0 deletions

View File

@@ -0,0 +1,273 @@
<?php
/**
* Phinx
*
* (The MIT license)
* Copyright (c) 2015 Rob Morgan
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated * documentation files (the "Software"), to
* deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*
* @package Phinx
* @subpackage Phinx\Migration
*/
namespace Phinx\Migration;
use Phinx\Db\Table;
use Phinx\Db\Adapter\AdapterInterface;
use think\console\Input as InputInterface;
use think\console\Output as OutputInterface;
/**
* Abstract Migration Class.
*
* It is expected that the migrations 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 AbstractMigration implements MigrationInterface
{
/**
* @var float
*/
protected $version;
/**
* @var AdapterInterface
*/
protected $adapter;
/**
* @var OutputInterface
*/
protected $output;
/**
* @var InputInterface
*/
protected $input;
/**
* Class Constructor.
*
* @param int $version Migration Version
* @param InputInterface|null $input
* @param OutputInterface|null $output
*/
final public function __construct($version, InputInterface $input = null, OutputInterface $output = null)
{
$this->version = $version;
if (!is_null($input)){
$this->setInput($input);
}
if (!is_null($output)){
$this->setOutput($output);
}
$this->init();
}
/**
* Initialize method.
*
* @return void
*/
protected function init()
{
}
/**
* {@inheritdoc}
*/
public function up()
{
}
/**
* {@inheritdoc}
*/
public function down()
{
}
/**
* {@inheritdoc}
*/
public function setAdapter(AdapterInterface $adapter)
{
$this->adapter = $adapter;
return $this;
}
/**
* {@inheritdoc}
*/
public function getAdapter()
{
return $this->adapter;
}
/**
* {@inheritdoc}
*/
public function setInput(InputInterface $input)
{
$this->input = $input;
return $this;
}
/**
* {@inheritdoc}
*/
public function getInput()
{
return $this->input;
}
/**
* {@inheritdoc}
*/
public function setOutput(OutputInterface $output)
{
$this->output = $output;
return $this;
}
/**
* {@inheritdoc}
*/
public function getOutput()
{
return $this->output;
}
/**
* {@inheritdoc}
*/
public function getName()
{
return get_class($this);
}
/**
* {@inheritdoc}
*/
public function setVersion($version)
{
$this->version = $version;
return $this;
}
/**
* {@inheritdoc}
*/
public function getVersion()
{
return $this->version;
}
/**
* {@inheritdoc}
*/
public function execute($sql)
{
return $this->getAdapter()->execute($sql);
}
/**
* {@inheritdoc}
*/
public function query($sql)
{
return $this->getAdapter()->query($sql);
}
/**
* {@inheritdoc}
*/
public function fetchRow($sql)
{
return $this->getAdapter()->fetchRow($sql);
}
/**
* {@inheritdoc}
*/
public function fetchAll($sql)
{
return $this->getAdapter()->fetchAll($sql);
}
/**
* {@inheritdoc}
*/
public function insert($table, $data)
{
// convert to table object
if (is_string($table)) {
$table = new Table($table, array(), $this->getAdapter());
}
return $table->insert($data)->save();
}
/**
* {@inheritdoc}
*/
public function createDatabase($name, $options)
{
$this->getAdapter()->createDatabase($name, $options);
}
/**
* {@inheritdoc}
*/
public function dropDatabase($name)
{
$this->getAdapter()->dropDatabase($name);
}
/**
* {@inheritdoc}
*/
public function hasTable($tableName)
{
return $this->getAdapter()->hasTable($tableName);
}
/**
* {@inheritdoc}
*/
public function table($tableName, $options = array())
{
return new Table($tableName, $options, $this->getAdapter());
}
/**
* A short-hand method to drop the given database table.
*
* @param string $tableName Table Name
* @return void
*/
public function dropTable($tableName)
{
$this->table($tableName)->drop();
}
}

View File

@@ -0,0 +1,97 @@
<?php
/**
* Phinx
*
* (The MIT license)
* Copyright (c) 2015 Rob Morgan
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated * documentation files (the "Software"), to
* deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*
* @package Phinx
* @subpackage Phinx\Migration
*/
namespace Phinx\Migration;
use think\console\Input as InputInterface;
use think\console\Output as OutputInterface;
abstract class AbstractTemplateCreation implements CreationInterface
{
/**
* @var InputInterface
*/
protected $input;
/**
* @var OutputInterface
*/
protected $output;
/**
* Class Constructor.
*
* @param InputInterface|null $input
* @param OutputInterface|null $output
*/
public function __construct(InputInterface $input = null, OutputInterface $output = null)
{
if (!is_null($input)) {
$this->setInput($input);
}
if (!is_null($output)) {
$this->setOutput($output);
}
}
/**
* {@inheritdoc}
*/
public function getInput()
{
return $this->input;
}
/**
* {@inheritdoc}
*/
public function setInput(InputInterface $input)
{
$this->input = $input;
return $this;
}
/**
* {@inheritdoc}
*/
public function getOutput()
{
return $this->output;
}
/**
* {@inheritdoc}
*/
public function setOutput(OutputInterface $output)
{
$this->output = $output;
return $this;
}
}

View File

@@ -0,0 +1,94 @@
<?php
/**
* Phinx
*
* (The MIT license)
* Copyright (c) 2015 Rob Morgan
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated * documentation files (the "Software"), to
* deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*
* @package Phinx
* @subpackage Phinx\Migration
*/
namespace Phinx\Migration;
use think\console\Input as InputInterface;
use think\console\Output as OutputInterface;
/**
* Migration interface
*
* @author Richard Quadling <RQuadling@GMail.com>
*/
interface CreationInterface
{
/**
* CreationInterface constructor.
*
* @param InputInterface|null $input
* @param OutputInterface|null $output
*/
public function __construct(InputInterface $input = null, OutputInterface $output = null);
/**
* @param InputInterface $input
*
* @return CreationInterface
*/
public function setInput(InputInterface $input);
/**
* @param OutputInterface $output
*
* @return CreationInterface
*/
public function setOutput(OutputInterface $output);
/**
* @return InputInterface
*/
public function getInput();
/**
* @return OutputInterface
*/
public function getOutput();
/**
* Get the migration template.
*
* This will be the content that Phinx will amend to generate the migration file.
*
* @return string The content of the template for Phinx to amend.
*/
public function getMigrationTemplate();
/**
* Post Migration Creation.
*
* Once the migration file has been created, this method will be called, allowing any additional
* processing, specific to the template to be performed.
*
* @param string $migrationFilename The name of the newly created migration.
* @param string $className The class name.
* @param string $baseClassName The name of the base class.
* @return void
*/
public function postMigrationCreation($migrationFilename, $className, $baseClassName);
}

View File

@@ -0,0 +1,39 @@
<?php
/**
* Phinx
*
* (The MIT license)
* Copyright (c) 2015 Rob Morgan
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated * documentation files (the "Software"), to
* deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*
* @package Phinx
* @subpackage Phinx\Migration
*/
namespace Phinx\Migration;
/**
* Exception class thrown when migrations cannot be reversed using the 'change'
* feature.
*
* @author Rob Morgan <robbym@gmail.com>
*/
class IrreversibleMigrationException extends \Exception
{
}

View File

@@ -0,0 +1,32 @@
<?php
use $useClassName;
class $className extends $baseClassName
{
/**
* Change Method.
*
* Write your reversible migrations using this method.
*
* More information on writing migrations is available here:
* http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
*
* The following commands can be used in this method and Phinx will
* automatically reverse them when rolling back:
*
* createTable
* renameTable
* addColumn
* renameColumn
* addIndex
* addForeignKey
*
* Remember to call "create()" or "update()" and NOT "save()" when working
* with the Table class.
*/
public function change()
{
}
}

View File

@@ -0,0 +1,215 @@
<?php
/**
* Phinx
*
* (The MIT license)
* Copyright (c) 2015 Rob Morgan
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated * documentation files (the "Software"), to
* deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*
* @package Phinx
* @subpackage Phinx\Migration
*/
namespace Phinx\Migration;
use Phinx\Db\Adapter\AdapterInterface;
use Phinx\Db\Table;
use think\console\Input as InputInterface;
use think\console\Output as OutputInterface;
/**
* Migration interface
*
* @author Rob Morgan <robbym@gmail.com>
*/
interface MigrationInterface
{
/**
* @var string
*/
const CHANGE = 'change';
/**
* @var string
*/
const UP = 'up';
/**
* @var string
*/
const DOWN = 'down';
/**
* Migrate Up
*
* @return void
*/
public function up();
/**
* Migrate Down
*
* @return void
*/
public function down();
/**
* Sets the database adapter.
*
* @param AdapterInterface $adapter Database Adapter
* @return MigrationInterface
*/
public function setAdapter(AdapterInterface $adapter);
/**
* Gets the database adapter.
*
* @return AdapterInterface
*/
public function getAdapter();
/**
* Sets the input object to be used in migration object
*
* @param InputInterface $input
* @return MigrationInterface
*/
public function setInput(InputInterface $input);
/**
* Gets the input object to be used in migration object
*
* @return InputInterface
*/
public function getInput();
/**
* Sets the output object to be used in migration object
*
* @param OutputInterface $output
* @return MigrationInterface
*/
public function setOutput(OutputInterface $output);
/**
* Gets the output object to be used in migration object
*
* @return OutputInterface
*/
public function getOutput();
/**
* Gets the name.
*
* @return string
*/
public function getName();
/**
* Sets the migration version number.
*
* @param float $version Version
* @return MigrationInterface
*/
public function setVersion($version);
/**
* Gets the migration version number.
*
* @return float
*/
public function getVersion();
/**
* Executes a SQL statement and returns the number of affected rows.
*
* @param string $sql SQL
* @return int
*/
public function execute($sql);
/**
* Executes a SQL statement and returns the result as an array.
*
* @param string $sql SQL
* @return array
*/
public function query($sql);
/**
* Executes a query and returns only one row as an array.
*
* @param string $sql SQL
* @return array
*/
public function fetchRow($sql);
/**
* Executes a query and returns an array of rows.
*
* @param string $sql SQL
* @return array
*/
public function fetchAll($sql);
/**
* Insert data into a table.
*
* @param string $tableName
* @param array $data
* @return void
*/
public function insert($tableName, $data);
/**
* Create a new database.
*
* @param string $name Database Name
* @param array $options Options
* @return void
*/
public function createDatabase($name, $options);
/**
* Drop a database.
*
* @param string $name Database Name
* @return void
*/
public function dropDatabase($name);
/**
* Checks to see if a table exists.
*
* @param string $tableName Table Name
* @return boolean
*/
public function hasTable($tableName);
/**
* 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 $options Options
* @return Table
*/
public function table($tableName, $options);
}