Migration.php
67 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Give\Framework\Migrations\Contracts; |
| 4 | |
| 5 | use Give\Framework\Exceptions\Primitives\RuntimeException; |
| 6 | |
| 7 | /** |
| 8 | * Class Migration |
| 9 | * |
| 10 | * Extend this class when create database migration. up and timestamp are required member functions |
| 11 | * |
| 12 | * @since 2.9.0 |
| 13 | */ |
| 14 | abstract class Migration { |
| 15 | /** |
| 16 | * Bootstrap migration logic. |
| 17 | * |
| 18 | * @since 2.9.0 |
| 19 | */ |
| 20 | abstract public function run(); |
| 21 | |
| 22 | /** |
| 23 | * Return a unique identifier for the migration |
| 24 | * |
| 25 | * @return string |
| 26 | */ |
| 27 | public static function id() { |
| 28 | throw new RuntimeException( 'A unique ID must be provided for the migration' ); |
| 29 | } |
| 30 | |
| 31 | /** |
| 32 | * Return a Unix Timestamp for when the migration was created |
| 33 | * |
| 34 | * Example: strtotime( '2020-09-16 12:30:00') |
| 35 | * |
| 36 | * @since 2.9.0 |
| 37 | * |
| 38 | * @return int Unix timestamp for when the migration was created |
| 39 | */ |
| 40 | public static function timestamp() { |
| 41 | throw new RuntimeException( 'This method must be overridden to return a valid unix timestamp' ); |
| 42 | } |
| 43 | |
| 44 | /** |
| 45 | * Return migration title |
| 46 | * |
| 47 | * @since 2.10.0 |
| 48 | * |
| 49 | * @return string |
| 50 | */ |
| 51 | public static function title() { |
| 52 | return static::id(); |
| 53 | } |
| 54 | |
| 55 | |
| 56 | /** |
| 57 | * Return migration source |
| 58 | * |
| 59 | * @since 2.10.0 |
| 60 | * |
| 61 | * @return string |
| 62 | */ |
| 63 | public static function source() { |
| 64 | return esc_html__( 'GiveWP Core', 'give' ); |
| 65 | } |
| 66 | } |
| 67 |