-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update migrate execution to keep track of old migration
- Loading branch information
Showing
2 changed files
with
79 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<?php | ||
|
||
namespace Abdslam01\MiniFrameworkCore\Database; | ||
|
||
use Abdslam01\MiniFrameworkCore\Model; | ||
|
||
class MigrationTable extends Model { | ||
|
||
private Database $db; | ||
|
||
public function __construct(){ | ||
$this->db = new Database; | ||
$this->table = "migrations"; | ||
} | ||
/** | ||
* createMigrationTable | ||
* | ||
* @param bool $drop_if_exists | ||
* @return bool | ||
*/ | ||
public function createMigrationTable(bool $drop_if_exists = false){ | ||
if($drop_if_exists) | ||
$this->db->schema->dropIfExists('migrations'); | ||
|
||
if(!$this->db->schema->hasTable("migrations")){ | ||
$this->db->schema->create('migrations', function ($table) { | ||
$table->id(); | ||
$table->string('migration'); | ||
$table->timestamps(); | ||
}); | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
/** | ||
* dropMigrationTable | ||
* | ||
* @return void | ||
*/ | ||
public function dropMigrationTable(){ | ||
$this->db->schema->dropIfExists('migrations'); | ||
} | ||
|
||
/** | ||
* getAppliedMigration | ||
* | ||
* @return array | ||
*/ | ||
public function getAppliedMigrations(): array{ | ||
return array_map( | ||
fn($p)=>$p['migration'], | ||
MigrationTable::select("migration")->get()->toArray() | ||
); | ||
} | ||
} |