67 lines
1.3 KiB
PHP
67 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace Nest\Database\Migrations;
|
|
|
|
use Nest\Database\Database;
|
|
use Nest\Database\Migrations\Diff\Table;
|
|
|
|
/**
|
|
* A database migration.
|
|
*/
|
|
abstract class Migration
|
|
{
|
|
|
|
/**
|
|
* Construct a new database migration.
|
|
* @param Database $database The database of the migration.
|
|
* @param string $version Version identifier.
|
|
* @param string $name Database migration name.
|
|
*/
|
|
public function __construct(protected readonly Database $database, private readonly string $version, private readonly string $name)
|
|
{
|
|
}
|
|
|
|
/**
|
|
* @return string The version identifier.
|
|
*/
|
|
public function getVersion(): string
|
|
{
|
|
return $this->version;
|
|
}
|
|
/**
|
|
* @return string The database migration name.
|
|
*/
|
|
public function getName(): string
|
|
{
|
|
return $this->name;
|
|
}
|
|
|
|
/**
|
|
* Describes operations of the current database migration.
|
|
* @return string Description of database migration.
|
|
*/
|
|
public abstract function getDescription(): string;
|
|
|
|
/**
|
|
* Do the migration.
|
|
* @return void
|
|
*/
|
|
public abstract function up(): void;
|
|
|
|
/**
|
|
* Undo the migration.
|
|
* @return void
|
|
*/
|
|
public abstract function down(): void;
|
|
|
|
|
|
/**
|
|
* Create a new table diff manager.
|
|
* @param string $tableName Table name to alter.
|
|
* @return Table Table diff manager.
|
|
*/
|
|
protected function table(string $tableName): Table
|
|
{
|
|
return new Table($this->database, $tableName);
|
|
}
|
|
}
|