mirror of
https://github.com/alextselegidis/easyappointments.git
synced 2024-11-24 08:53:05 +03:00
Added support for upgrading and downgrading manually the database via the CLI
This commit is contained in:
parent
0a88442aa2
commit
bcc9b88623
3 changed files with 34 additions and 2 deletions
|
@ -167,6 +167,8 @@ class Console extends EA_Controller {
|
|||
'',
|
||||
'⇾ php index.php console migrate',
|
||||
'⇾ php index.php console migrate fresh',
|
||||
'⇾ php index.php console migrate up',
|
||||
'⇾ php index.php console migrate down',
|
||||
'⇾ php index.php console seed',
|
||||
'⇾ php index.php console install',
|
||||
'⇾ php index.php console backup',
|
||||
|
|
|
@ -42,5 +42,13 @@ require_once __DIR__ . '/../../system/libraries/Migration.php';
|
|||
* @property EA_URI $uri
|
||||
*/
|
||||
class EA_Migration extends CI_Migration {
|
||||
//
|
||||
/**
|
||||
* Get the current migration version.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function current_version(): int
|
||||
{
|
||||
return $this->_get_version();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -45,10 +45,32 @@ class Instance {
|
|||
/**
|
||||
* Migrate the database to the latest state.
|
||||
*
|
||||
* @param string $type Provide "fresh" to revert previous migrations and start from the beginning.
|
||||
* @param string $type Provide "fresh" to revert previous migrations and start from the beginning or "up"/"down" to step.
|
||||
*/
|
||||
public function migrate(string $type = '')
|
||||
{
|
||||
$current_version = $this->CI->migration->current_version();
|
||||
|
||||
if ($type === 'up')
|
||||
{
|
||||
if ( ! $this->CI->migration->version($current_version + 1))
|
||||
{
|
||||
show_error($this->CI->migration->error_string());
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if ($type === 'down')
|
||||
{
|
||||
if ( ! $this->CI->migration->version($current_version - 1))
|
||||
{
|
||||
show_error($this->CI->migration->error_string());
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if ($type === 'fresh' && ! $this->CI->migration->version(0))
|
||||
{
|
||||
show_error($this->CI->migration->error_string());
|
||||
|
|
Loading…
Reference in a new issue