Compare commits
10
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
dbc5e5bed2 | ||
|
|
edf7974a4f | ||
|
|
84a76017d7 | ||
|
|
235c58d1a9 | ||
|
|
8b45dd556a | ||
|
|
5632f15107 | ||
|
|
1e9aeb6266 | ||
|
|
ad50a598af | ||
|
|
8138187667 | ||
|
|
d1da3f781a |
Regular → Executable
@@ -1,3 +1,5 @@
|
||||
https://book.cakephp.org/3.0/en/phinx/migrations.html#working-with-columns
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
@@ -19,4 +21,41 @@ $table->removeColumn('idb');
|
||||
|
||||
$table->save();
|
||||
Wrapper::commit();
|
||||
```
|
||||
|
||||
```
|
||||
//Data Types
|
||||
|
||||
biginteger
|
||||
binary
|
||||
boolean
|
||||
char
|
||||
date
|
||||
datetime
|
||||
decimal
|
||||
float
|
||||
integer
|
||||
smallinteger
|
||||
string
|
||||
text
|
||||
time
|
||||
timestamp
|
||||
uuid
|
||||
|
||||
//Mysql-------------------
|
||||
enum
|
||||
set
|
||||
blob
|
||||
bit
|
||||
json
|
||||
|
||||
//PostgreSql-------------
|
||||
interval
|
||||
json
|
||||
jsonb
|
||||
uuid
|
||||
cidr
|
||||
inet
|
||||
macaddr
|
||||
|
||||
```
|
||||
Regular → Executable
+1
-1
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"name": "urfat/schema",
|
||||
"name": "inforsistemas/schema",
|
||||
"description": "From Phinx, just the DDL",
|
||||
"type": "library",
|
||||
"authors": [
|
||||
|
||||
@@ -52,7 +52,7 @@ class AdapterFactory
|
||||
public static function instance()
|
||||
{
|
||||
if (!static::$instance) {
|
||||
static::$instance = new static();
|
||||
static::$instance = new static ();
|
||||
}
|
||||
return static::$instance;
|
||||
}
|
||||
@@ -63,8 +63,8 @@ class AdapterFactory
|
||||
* @var array
|
||||
*/
|
||||
protected $adapters = array(
|
||||
'mysql' => 'Phinx\Db\Adapter\MysqlAdapter',
|
||||
'pgsql' => 'Phinx\Db\Adapter\PostgresAdapter',
|
||||
'mysql' => 'Phinx\Db\Adapter\MysqlAdapter',
|
||||
'pgsql' => 'Phinx\Db\Adapter\PostgresAdapter',
|
||||
'sqlite' => 'Phinx\Db\Adapter\SQLiteAdapter',
|
||||
'sqlsrv' => 'Phinx\Db\Adapter\SqlServerAdapter',
|
||||
);
|
||||
@@ -76,7 +76,7 @@ class AdapterFactory
|
||||
*/
|
||||
protected $wrappers = array(
|
||||
'prefix' => 'Phinx\Db\Adapter\TablePrefixAdapter',
|
||||
'proxy' => 'Phinx\Db\Adapter\ProxyAdapter',
|
||||
'proxy' => 'Phinx\Db\Adapter\ProxyAdapter',
|
||||
);
|
||||
|
||||
/**
|
||||
@@ -90,10 +90,12 @@ class AdapterFactory
|
||||
public function registerAdapter($name, $class)
|
||||
{
|
||||
if (!is_subclass_of($class, 'Phinx\Db\Adapter\AdapterInterface')) {
|
||||
throw new \RuntimeException(sprintf(
|
||||
'Adapter class "%s" must implement Phinx\\Db\\Adapter\\AdapterInterface',
|
||||
$class
|
||||
));
|
||||
throw new \RuntimeException(
|
||||
sprintf(
|
||||
'Adapter class "%s" must implement Phinx\\Db\\Adapter\\AdapterInterface',
|
||||
$class
|
||||
)
|
||||
);
|
||||
}
|
||||
$this->adapters[$name] = $class;
|
||||
return $this;
|
||||
@@ -109,10 +111,12 @@ class AdapterFactory
|
||||
protected function getClass($name)
|
||||
{
|
||||
if (empty($this->adapters[$name])) {
|
||||
throw new \RuntimeException(sprintf(
|
||||
'Adapter "%s" has not been registered',
|
||||
$name
|
||||
));
|
||||
throw new \RuntimeException(
|
||||
sprintf(
|
||||
'Adapter "%s" has not been registered',
|
||||
$name
|
||||
)
|
||||
);
|
||||
}
|
||||
return $this->adapters[$name];
|
||||
}
|
||||
@@ -141,10 +145,12 @@ class AdapterFactory
|
||||
public function registerWrapper($name, $class)
|
||||
{
|
||||
if (!is_subclass_of($class, 'Phinx\Db\Adapter\WrapperInterface')) {
|
||||
throw new \RuntimeException(sprintf(
|
||||
'Wrapper class "%s" must be implement Phinx\\Db\\Adapter\\WrapperInterface',
|
||||
$class
|
||||
));
|
||||
throw new \RuntimeException(
|
||||
sprintf(
|
||||
'Wrapper class "%s" must be implement Phinx\\Db\\Adapter\\WrapperInterface',
|
||||
$class
|
||||
)
|
||||
);
|
||||
}
|
||||
$this->wrappers[$name] = $class;
|
||||
return $this;
|
||||
@@ -160,10 +166,12 @@ class AdapterFactory
|
||||
protected function getWrapperClass($name)
|
||||
{
|
||||
if (empty($this->wrappers[$name])) {
|
||||
throw new \RuntimeException(sprintf(
|
||||
'Wrapper "%s" has not been registered',
|
||||
$name
|
||||
));
|
||||
throw new \RuntimeException(
|
||||
sprintf(
|
||||
'Wrapper "%s" has not been registered',
|
||||
$name
|
||||
)
|
||||
);
|
||||
}
|
||||
return $this->wrappers[$name];
|
||||
}
|
||||
@@ -180,4 +188,4 @@ class AdapterFactory
|
||||
$class = $this->getWrapperClass($name);
|
||||
return new $class($adapter);
|
||||
}
|
||||
}
|
||||
}
|
||||
+40
-31
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Phinx
|
||||
*
|
||||
@@ -26,6 +27,7 @@
|
||||
* @package Phinx
|
||||
* @subpackage Phinx\Db
|
||||
*/
|
||||
|
||||
namespace Schema\Db;
|
||||
|
||||
use Schema\Db\Table\Column;
|
||||
@@ -39,6 +41,7 @@ use Schema\Db\Adapter\AdapterInterface;
|
||||
*/
|
||||
class Table
|
||||
{
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
@@ -87,7 +90,6 @@ class Table
|
||||
$this->setOptions($options);
|
||||
|
||||
if (null !== $adapter) {
|
||||
//echo 'Adapter definido';
|
||||
$this->setAdapter($adapter);
|
||||
}
|
||||
}
|
||||
@@ -349,11 +351,13 @@ class Table
|
||||
|
||||
// Delegate to Adapters to check column type
|
||||
if (!$this->getAdapter()->isValidColumnType($column)) {
|
||||
throw new \InvalidArgumentException(sprintf(
|
||||
'An invalid column type "%s" was specified for column "%s".',
|
||||
$column->getType(),
|
||||
$column->getName()
|
||||
));
|
||||
throw new \InvalidArgumentException(
|
||||
sprintf(
|
||||
'An invalid column type "%s" was specified for column "%s".',
|
||||
$column->getType(),
|
||||
$column->getName()
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
$this->columns[] = $column;
|
||||
@@ -513,8 +517,8 @@ class Table
|
||||
$fk->setReferencedTable(new Table($referencedTable, array(), $this->adapter));
|
||||
}
|
||||
$fk->setColumns($columns)
|
||||
->setReferencedColumns($referencedColumns)
|
||||
->setOptions($options);
|
||||
->setReferencedColumns($referencedColumns)
|
||||
->setOptions($options);
|
||||
$this->foreignKeys[] = $fk;
|
||||
|
||||
return $this;
|
||||
@@ -566,34 +570,36 @@ class Table
|
||||
$createdAtColumnName = is_null($createdAtColumnName) ? 'created_at' : $createdAtColumnName;
|
||||
$updatedAtColumnName = is_null($updatedAtColumnName) ? 'updated_at' : $updatedAtColumnName;
|
||||
$this->addColumn($createdAtColumnName, 'timestamp', array(
|
||||
'default' => 'CURRENT_TIMESTAMP',
|
||||
'update' => ''
|
||||
)
|
||||
)
|
||||
->addColumn($updatedAtColumnName, 'timestamp', array(
|
||||
'default' => 'CURRENT_TIMESTAMP',
|
||||
'update' => ''
|
||||
))
|
||||
->addColumn($updatedAtColumnName, 'timestamp', array(
|
||||
'null' => true,
|
||||
'default' => null
|
||||
));
|
||||
)
|
||||
);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add deleted_at column to the table.
|
||||
*
|
||||
* @param string $deletedAtColumnName
|
||||
*
|
||||
* @return Table
|
||||
/**
|
||||
* Add deleted_at column to the table.
|
||||
*
|
||||
* @param string $deletedAtColumnName
|
||||
*
|
||||
* @return Table
|
||||
*/
|
||||
public function addSoftDelete($deletedAtColumnName = 'deleted_at'){
|
||||
$deletedAtColumnName = is_null($deletedAtColumnName) ? 'deleted_at' : $deletedAtColumnName;
|
||||
public function addSoftDelete($deletedAtColumnName = 'deleted_at')
|
||||
{
|
||||
$deletedAtColumnName = is_null($deletedAtColumnName) ? 'deleted_at' : $deletedAtColumnName;
|
||||
$this->addColumn($deletedAtColumnName, 'timestamp', array(
|
||||
'default' => null,
|
||||
'null' => true,
|
||||
));
|
||||
'null' => true,
|
||||
)
|
||||
);
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Insert data into the table.
|
||||
*
|
||||
@@ -626,9 +632,11 @@ class Table
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
$this->getAdapter()->createTable($this);
|
||||
$this->saveData();
|
||||
$this->reset(); // reset pending changes
|
||||
if (!$this->getAdapter()->hasTable($this->name)) {
|
||||
$this->getAdapter()->createTable($this);
|
||||
$this->saveData();
|
||||
$this->reset(); // reset pending changes
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -689,4 +697,5 @@ class Table
|
||||
|
||||
$this->reset(); // reset pending changes
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+23
-11
@@ -9,7 +9,8 @@ use Schema\Db\Adapter\MysqlAdapter;
|
||||
use Schema\Db\Adapter\SQLiteAdapter;
|
||||
use Schema\Db\Adapter\SqlServerAdapter;
|
||||
|
||||
class Wrapper{
|
||||
class Wrapper
|
||||
{
|
||||
|
||||
private static $_instance;
|
||||
|
||||
@@ -19,14 +20,16 @@ class Wrapper{
|
||||
function __construct(){ }
|
||||
|
||||
//SINGLETON==============================================
|
||||
private static function newObj(){
|
||||
private static function newObj()
|
||||
{
|
||||
if (!isset(self::$_instance)) {
|
||||
self::$_instance = new Wrapper();
|
||||
}
|
||||
return self::$_instance;
|
||||
}
|
||||
|
||||
public static function getInstance(){
|
||||
public static function getInstance()
|
||||
{
|
||||
if (!isset(self::$_instance)) {
|
||||
return self::newObj();
|
||||
}
|
||||
@@ -34,7 +37,8 @@ class Wrapper{
|
||||
}
|
||||
//=======================================================
|
||||
|
||||
public static function set_driver(\PDO $driver){
|
||||
public static function set_driver(\PDO $driver)
|
||||
{
|
||||
$instance = self::getInstance();
|
||||
$instance->_driver = $driver;
|
||||
|
||||
@@ -55,29 +59,37 @@ class Wrapper{
|
||||
}
|
||||
}
|
||||
|
||||
public static function get_table($name){
|
||||
public static function get_table($name)
|
||||
{
|
||||
$instance = self::getInstance();
|
||||
echo $instance->_adapter->getConnection()->prefix;
|
||||
|
||||
if( $instance->_adapter->getConnection()->prefix ){
|
||||
$name = $instance->_adapter->getConnection()->prefix . $name;
|
||||
}
|
||||
|
||||
return new Table($name, Array(), $instance->_adapter);
|
||||
}
|
||||
|
||||
public static function begin(){
|
||||
public static function begin()
|
||||
{
|
||||
$instance = self::getInstance();
|
||||
$instance->_adapter->beginTransaction();
|
||||
}
|
||||
|
||||
public static function commit(){
|
||||
public static function commit()
|
||||
{
|
||||
$instance = self::getInstance();
|
||||
$instance->_adapter->commitTransaction();
|
||||
}
|
||||
|
||||
public static function exec($sql){
|
||||
public static function exec($sql)
|
||||
{
|
||||
$instance = self::getInstance();
|
||||
$sql = preg_replace('/{(.*)}/', "$con->prefix$1", $sql);
|
||||
$prefix = $instance->_adapter->getConnection()->prefix;
|
||||
$sql = preg_replace_callback('/{.*?}/', function($match) use ($prefix){
|
||||
return str_replace('}', '', str_replace('{', $prefix, $match[0]));
|
||||
} , $sql);
|
||||
$instance->_driver->exec($sql);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Regular → Executable
Reference in New Issue
Block a user