Last active
June 4, 2019 19:18
-
-
Save wilcorrea/79621ca86e4a89e340385f3cf27beb4c to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| <?php | |
| namespace App\Database\Migration; | |
| use App\Database\Migration; | |
| use App\Database\Schema; | |
| use App\Database\Table; | |
| use Illuminate\Database\Schema\Blueprint; | |
| /** | |
| * Class TableCreate | |
| * @package App\Database\Migration | |
| */ | |
| abstract class TableCreate extends Migration | |
| { | |
| /** | |
| * @var string | |
| */ | |
| protected $table = ''; | |
| /** | |
| * @var bool | |
| */ | |
| protected $modifiable = true; | |
| /** | |
| * @param Table $table | |
| * @return void | |
| */ | |
| protected abstract function withStatements(Table $table); | |
| /** | |
| * Run the migrations. | |
| * | |
| * @return void | |
| */ | |
| public function up() | |
| { | |
| if (Schema::hasTable($this->table)) { | |
| return; | |
| } | |
| Schema::create($this->table, function (Blueprint $blueprint) { | |
| $table = Table::make($blueprint); | |
| $table->uuid('uuid')->primary(); | |
| $table->string('id')->unique(); | |
| $this->withStatements($table); | |
| $this->timestamps($table); | |
| $table->softDeletes(); | |
| }); | |
| } | |
| /** | |
| * @param Table $table | |
| */ | |
| private function timestamps(Table $table) | |
| { | |
| if ($this->modifiable) { | |
| $table->timestamps(); | |
| return; | |
| } | |
| $table->timestamp('created_at')->nullable(); | |
| } | |
| /** | |
| * Reverse the migrations. | |
| * | |
| * @return void | |
| */ | |
| public function down() | |
| { | |
| Schema::dropIfExists($this->table); | |
| } | |
| } |
This file contains hidden or 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
| <?php | |
| use App\Database\Migration\TableCreate; | |
| use App\Database\Table; | |
| /** | |
| * Class UserServicesCreate | |
| */ | |
| class UserServicesCreate extends TableCreate | |
| { | |
| /** | |
| * @var string | |
| */ | |
| protected $table = 'user_services'; | |
| /** | |
| * @param Table $table | |
| * @return void | |
| */ | |
| protected function withStatements(Table $table) | |
| { | |
| $table->uuid('user_id'); | |
| $table->foreign('user_id')->references('uuid')->on('users'); | |
| $table->string('service')->index(); | |
| $table->json('payload'); | |
| $table->timestamp('expires_at')->nullable(); | |
| $table->boolean('active')->default(1); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment