Migration.php
71 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 | /** |
| 17 | * Bootstrap migration logic. |
| 18 | * |
| 19 | * @since 2.9.0 |
| 20 | */ |
| 21 | abstract public function run(); |
| 22 | |
| 23 | /** |
| 24 | * Return a unique identifier for the migration |
| 25 | * |
| 26 | * @return string |
| 27 | */ |
| 28 | public static function id() |
| 29 | { |
| 30 | throw new RuntimeException('A unique ID must be provided for the migration'); |
| 31 | } |
| 32 | |
| 33 | /** |
| 34 | * Return a Unix Timestamp for when the migration was created |
| 35 | * |
| 36 | * Example: strtotime( '2020-09-16 12:30:00') |
| 37 | * |
| 38 | * @since 2.9.0 |
| 39 | * |
| 40 | * @return int Unix timestamp for when the migration was created |
| 41 | */ |
| 42 | public static function timestamp() |
| 43 | { |
| 44 | throw new RuntimeException('This method must be overridden to return a valid unix timestamp'); |
| 45 | } |
| 46 | |
| 47 | /** |
| 48 | * Return migration title |
| 49 | * |
| 50 | * @since 2.10.0 |
| 51 | * |
| 52 | * @return string |
| 53 | */ |
| 54 | public static function title() |
| 55 | { |
| 56 | return static::id(); |
| 57 | } |
| 58 | |
| 59 | /** |
| 60 | * Return migration source |
| 61 | * |
| 62 | * @since 2.10.0 |
| 63 | * |
| 64 | * @return string |
| 65 | */ |
| 66 | public static function source() |
| 67 | { |
| 68 | return esc_html__('GiveWP Core', 'give'); |
| 69 | } |
| 70 | } |
| 71 |