|
@@ -11,8 +11,10 @@
|
|
|
const MIGRATE_UP = 'up';
|
|
|
const MIGRATE_DOWN = 'down';
|
|
|
private static $pdo;
|
|
|
- private static $date;
|
|
|
- private static $version;
|
|
|
+ private static $last_date;
|
|
|
+ private static $initial_date;
|
|
|
+ private static $current_version;
|
|
|
+ private static $initial_version;
|
|
|
|
|
|
final public static function version(){
|
|
|
$name = get_called_class();
|
|
@@ -25,28 +27,52 @@
|
|
|
return Settings::get('db.versions');
|
|
|
}
|
|
|
final public static function get_current_version(bool $force = false){
|
|
|
- if(is_null(self::$version) || $force){
|
|
|
+ if(is_null(self::$current_version) || $force){
|
|
|
if(is_null(self::$pdo)){
|
|
|
throw new \Exception("Migration is not bound to a data source");
|
|
|
}
|
|
|
$table_name = self::version_table();
|
|
|
$query = self::$pdo->query("select max(version) version from `{$table_name}`");
|
|
|
- self::$version = $query->fetch()['version'];
|
|
|
+ self::$current_version = $query->fetch()['version'];
|
|
|
$query->closeCursor();
|
|
|
}
|
|
|
- return self::$version;
|
|
|
+ return self::$current_version;
|
|
|
+ }
|
|
|
+ final public static function get_initial_version(bool $force = false){
|
|
|
+ if(is_null(self::$initial_version) || $force){
|
|
|
+ if(is_null(self::$pdo)){
|
|
|
+ throw new \Exception("Migration is not bound to a data source");
|
|
|
+ }
|
|
|
+ $table_name = self::version_table();
|
|
|
+ $query = self::$pdo->query("select min(version) version from `{$table_name}`");
|
|
|
+ self::$initial_version = $query->fetch()['version'];
|
|
|
+ $query->closeCursor();
|
|
|
+ }
|
|
|
+ return self::$initial_version;
|
|
|
}
|
|
|
final public static function get_last_install_date(bool $force = false){
|
|
|
- if(is_null(self::$date) || $force){
|
|
|
+ if(is_null(self::$last_date) || $force){
|
|
|
if(is_null(self::$pdo)){
|
|
|
throw new \Exception("Migration is not bound to a data source");
|
|
|
}
|
|
|
$table_name = self::version_table();
|
|
|
$query = self::$pdo->query("select max(date) date from `{$table_name}`");
|
|
|
- self::$date = $query->fetch()['date'];
|
|
|
+ self::$last_date = $query->fetch()['date'];
|
|
|
+ $query->closeCursor();
|
|
|
+ }
|
|
|
+ return self::$last_date;
|
|
|
+ }
|
|
|
+ final public static function get_initial_install_date(bool $force = false){
|
|
|
+ if(is_null(self::$initial_date) || $force){
|
|
|
+ if(is_null(self::$pdo)){
|
|
|
+ throw new \Exception("Migration is not bound to a data source");
|
|
|
+ }
|
|
|
+ $table_name = self::version_table();
|
|
|
+ $query = self::$pdo->query("select min(date) date from `{$table_name}`");
|
|
|
+ self::$initial_date = $query->fetch()['date'];
|
|
|
$query->closeCursor();
|
|
|
}
|
|
|
- return self::$date;
|
|
|
+ return self::$initial_date;
|
|
|
}
|
|
|
final public static function installed(){
|
|
|
$pdo = self::$pdo;
|
|
@@ -117,6 +143,8 @@
|
|
|
default:
|
|
|
throw new \Exception("Invalid migration direction '{$direction}'");
|
|
|
}
|
|
|
+ self::get_initial_version(true);
|
|
|
+ self::get_initial_install_date(true);
|
|
|
self::get_current_version(true);
|
|
|
self::get_last_install_date(true);
|
|
|
}
|