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

Migration and Database correction #1788

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions system/Autoloader/Autoloader.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<?php namespace CodeIgniter\Autoloader;

use Composer\Autoload\ClassLoader;

/**
* CodeIgniter
*
Expand Down Expand Up @@ -159,7 +157,7 @@ public function register()

include_once $config[$class];
}, true, // Throw exception
true // Prepend
true // Prepend
);
}

Expand Down Expand Up @@ -291,7 +289,7 @@ protected function loadInNamespace(string $class)
if (strpos($class, $namespace) === 0)
{
$filePath = $directory . str_replace('\\', '/',
substr($class, strlen($namespace))) . '.php';
substr($class, strlen($namespace))) . '.php';
$filename = $this->requireFile($filePath);

if ($filename)
Expand Down Expand Up @@ -422,7 +420,7 @@ protected function discoverComposerNamespaces()
unset($paths['CodeIgniter\\']);
}

// Composer stores paths with trailng slash. We don't.
// Composer stores paths with trailing slash. We don't.
$newPaths = [];
foreach ($paths as $key => $value)
{
Expand Down
6 changes: 3 additions & 3 deletions system/CLI/Console.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public function __construct(CodeIgniter $app)
* @param boolean $useSafeOutput
*
* @return \CodeIgniter\HTTP\RequestInterface|\CodeIgniter\HTTP\Response|\CodeIgniter\HTTP\ResponseInterface|mixed
* @throws \CodeIgniter\HTTP\RedirectException
* @throws \CodeIgniter\Filters\Exceptions\FilterException
*/
public function run(bool $useSafeOutput = false)
{
Expand All @@ -90,8 +90,8 @@ public function showHeader()
CLI::newLine(1);

CLI::write(CLI::color('CodeIgniter CLI Tool', 'green')
. ' - Version ' . CodeIgniter::CI_VERSION
. ' - Server-Time: ' . date('Y-m-d H:i:sa'));
. ' - Version ' . CodeIgniter::CI_VERSION
. ' - Server-Time: ' . date('Y-m-d H:i:sa'));

CLI::newLine(1);
}
Expand Down
22 changes: 11 additions & 11 deletions system/Database/BaseConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -580,11 +580,11 @@ public function addTableAlias(string $table)
/**
* Executes the query against the database.
*
* @param $sql
* @param string $sql
*
* @return mixed
*/
abstract protected function execute($sql);
abstract protected function execute(string $sql);

//--------------------------------------------------------------------

Expand Down Expand Up @@ -1262,7 +1262,7 @@ public function escapeIdentifiers($item)
}
// Avoid breaking functions and literal values inside queries
elseif (ctype_digit($item) || $item[0] === "'" || ( $this->escapeChar !== '"' && $item[0] === '"') ||
strpos($item, '(') !== false
strpos($item, '(') !== false
)
{
return $item;
Expand Down Expand Up @@ -1413,14 +1413,14 @@ public function escapeString($str, $like = false)
if ($like === true)
{
return str_replace([
$this->likeEscapeChar,
'%',
'_',
], [
$this->likeEscapeChar . $this->likeEscapeChar,
$this->likeEscapeChar . '%',
$this->likeEscapeChar . '_',
], $str
$this->likeEscapeChar,
'%',
'_',
], [
$this->likeEscapeChar . $this->likeEscapeChar,
$this->likeEscapeChar . '%',
$this->likeEscapeChar . '_',
], $str
);
}

Expand Down
98 changes: 49 additions & 49 deletions system/Database/MigrationRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ class MigrationRunner
/**
* used to return messages for CLI.
*
* @var boolean
* @var array
*/
protected $cliMessages = [];

Expand Down Expand Up @@ -196,7 +196,7 @@ public function __construct(BaseConfig $config, $db = null)
* @param string|null $namespace
* @param string|null $group
*
* @return mixed TRUE if no migrations are found, current version string on success, FALSE on failure
* @return mixed TRUE if no migrations are found, current version string on success, False on failure
* @throws ConfigException
*/
public function version(string $targetVersion, string $namespace = null, string $group = null)
Expand Down Expand Up @@ -608,10 +608,10 @@ public function getHistory(string $group = 'default')
$this->ensureTable();

$query = $this->db->table($this->table)
->where('group', $group)
->where('namespace', $this->namespace)
->orderBy('version', 'ASC')
->get();
->where('group', $group)
->where('namespace', $this->namespace)
->orderBy('version', 'ASC')
->get();

if (! $query)
{
Expand Down Expand Up @@ -681,11 +681,11 @@ protected function getVersion()
$this->ensureTable();

$row = $this->db->table($this->table)
->select('version')
->where('group', $this->group)
->where('namespace', $this->namespace)
->orderBy('version', 'DESC')
->get();
->select('version')
->where('group', $this->group)
->where('namespace', $this->namespace)
->orderBy('version', 'DESC')
->get();

return $row && ! is_null($row->getRow()) ? $row->getRow()->version : '0';
}
Expand All @@ -695,7 +695,7 @@ protected function getVersion()
/**
* Retrieves current schema version
*
* @return string Current migration version
* @return array Return messages for CLI
*/
public function getCliMessages()
{
Expand All @@ -714,13 +714,13 @@ public function getCliMessages()
protected function addHistory(string $version)
{
$this->db->table($this->table)
->insert([
'version' => $version,
'name' => $this->name,
'group' => $this->group,
'namespace' => $this->namespace,
'time' => time(),
]);
->insert([
'version' => $version,
'name' => $this->name,
'group' => $this->group,
'namespace' => $this->namespace,
'time' => time(),
]);
if (is_cli())
{
$this->cliMessages[] = "\t" . CLI::color(lang('Migrations.added'), 'yellow') . "($this->namespace) " . $version . '_' . $this->name;
Expand All @@ -737,10 +737,10 @@ protected function addHistory(string $version)
protected function removeHistory(string $version)
{
$this->db->table($this->table)
->where('version', $version)
->where('group', $this->group)
->where('namespace', $this->namespace)
->delete();
->where('version', $version)
->where('group', $this->group)
->where('namespace', $this->namespace)
->delete();
if (is_cli())
{
$this->cliMessages[] = "\t" . CLI::color(lang('Migrations.removed'), 'yellow') . "($this->namespace) " . $version . '_' . $this->name;
Expand All @@ -763,32 +763,32 @@ public function ensureTable()
$forge = \Config\Database::forge($this->db);

$forge->addField([
'version' => [
'type' => 'VARCHAR',
'constraint' => 255,
'null' => false,
],
'name' => [
'type' => 'VARCHAR',
'constraint' => 255,
'null' => false,
],
'group' => [
'type' => 'VARCHAR',
'constraint' => 255,
'null' => false,
],
'namespace' => [
'type' => 'VARCHAR',
'constraint' => 255,
'null' => false,
],
'time' => [
'type' => 'INT',
'constraint' => 11,
'null' => false,
],
]);
'version' => [
'type' => 'VARCHAR',
'constraint' => 255,
'null' => false,
],
'name' => [
'type' => 'VARCHAR',
'constraint' => 255,
'null' => false,
],
'group' => [
'type' => 'VARCHAR',
'constraint' => 255,
'null' => false,
],
'namespace' => [
'type' => 'VARCHAR',
'constraint' => 255,
'null' => false,
],
'time' => [
'type' => 'INT',
'constraint' => 11,
'null' => false,
],
]);

$forge->createTable($this->table, true);

Expand Down
2 changes: 2 additions & 0 deletions system/Database/MySQLi/Utils.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php namespace CodeIgniter\Database\MySQLi;

use CodeIgniter\Database\Exceptions\DatabaseException;

/**
* CodeIgniter
*
Expand Down
31 changes: 15 additions & 16 deletions system/Database/Postgre/Forge.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,39 +116,39 @@ protected function _alterTable($alter_type, $table, $field)
if (version_compare($this->db->getVersion(), '8', '>=') && isset($data['type']))
{
$sqls[] = $sql . ' ALTER COLUMN ' . $this->db->escapeIdentifiers($data['name'])
. " TYPE {$data['type']}{$data['length']}";
. " TYPE {$data['type']}{$data['length']}";
}

if (! empty($data['default']))
{
$sqls[] = $sql . ' ALTER COLUMN ' . $this->db->escapeIdentifiers($data['name'])
. " SET DEFAULT {$data['default']}";
. " SET DEFAULT {$data['default']}";
}

if (isset($data['null']))
{
$sqls[] = $sql . ' ALTER COLUMN ' . $this->db->escapeIdentifiers($data['name'])
. ($data['null'] === true ? ' DROP' : ' SET') . ' NOT NULL';
. ($data['null'] === true ? ' DROP' : ' SET') . ' NOT NULL';
}

if (! empty($data['new_name']))
{
$sqls[] = $sql . ' RENAME COLUMN ' . $this->db->escapeIdentifiers($data['name'])
. ' TO ' . $this->db->escapeIdentifiers($data['new_name']);
. ' TO ' . $this->db->escapeIdentifiers($data['new_name']);
}

if (! empty($data['comment']))
{
$sqls[] = 'COMMENT ON COLUMN' . $this->db->escapeIdentifiers($table)
. '.' . $this->db->escapeIdentifiers($data['name'])
. " IS {$data['comment']}";
. '.' . $this->db->escapeIdentifiers($data['name'])
. " IS {$data['comment']}";
}
}

return $sqls;
}

//--------------------------------------------------------------------
//--------------------------------------------------------------------

/**
* Process column
Expand All @@ -159,11 +159,11 @@ protected function _alterTable($alter_type, $table, $field)
protected function _processColumn($field)
{
return $this->db->escapeIdentifiers($field['name'])
. ' ' . $field['type'] . $field['length']
. $field['default']
. $field['null']
. $field['auto_increment']
. $field['unique'];
. ' ' . $field['type'] . $field['length']
. $field['default']
. $field['null']
. $field['auto_increment']
. $field['unique'];
}

//--------------------------------------------------------------------
Expand All @@ -190,15 +190,14 @@ protected function _attributeType(&$attributes)
case 'TINYINT':
$attributes['TYPE'] = 'SMALLINT';
$attributes['UNSIGNED'] = false;
return;
break;
case 'MEDIUMINT':
$attributes['TYPE'] = 'INTEGER';
$attributes['UNSIGNED'] = false;
return;
break;
case 'DATETIME':
$attributes['TYPE'] = 'TIMESTAMP';
default:
return;
break;
}
}

Expand Down
2 changes: 2 additions & 0 deletions system/Database/Postgre/Utils.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php namespace CodeIgniter\Database\Postgre;

use CodeIgniter\Database\Exceptions\DatabaseException;

/**
* CodeIgniter
*
Expand Down
Loading