From 85bdafbbb89f5e8b8fc96f0bce61773b15352330 Mon Sep 17 00:00:00 2001 From: Jani Cerar <29040621+janicerar@users.noreply.github.com> Date: Fri, 19 Oct 2018 12:51:38 +0200 Subject: [PATCH] [Feature] Make migrations publishable --- README.md | 8 ++--- ...018_10_15_095425_create_user_2fa_table.php | 6 ++-- ..._095425_add_recovery_to_user_2fa_table.php | 32 ------------------- src/ToolServiceProvider.php | 6 +++- 4 files changed, 11 insertions(+), 41 deletions(-) rename {resources/database => database/migrations}/2018_10_15_095425_create_user_2fa_table.php (79%) delete mode 100644 resources/database/2018_10_17_095425_add_recovery_to_user_2fa_table.php diff --git a/README.md b/README.md index 48c71aa..da65260 100644 --- a/README.md +++ b/README.md @@ -6,16 +6,16 @@ Install via composer $ composer require lifeonscreen/nova-google2fa ``` -Run migrations +Publish config and migrations ``` bash -$ php artisan migrate +$ php artisan vendor:publish --provider="Lifeonscreen\Google2fa\ToolServiceProvider" ``` -Publish config +Run migrations ``` bash -$ php artisan vendor:publish --provider="Lifeonscreen\Google2fa\ToolServiceProvider" +$ php artisan migrate ``` Add relation to User model diff --git a/resources/database/2018_10_15_095425_create_user_2fa_table.php b/database/migrations/2018_10_15_095425_create_user_2fa_table.php similarity index 79% rename from resources/database/2018_10_15_095425_create_user_2fa_table.php rename to database/migrations/2018_10_15_095425_create_user_2fa_table.php index 0adb7dd..ac17d5f 100644 --- a/resources/database/2018_10_15_095425_create_user_2fa_table.php +++ b/database/migrations/2018_10_15_095425_create_user_2fa_table.php @@ -18,10 +18,8 @@ public function up() $table->unsignedInteger('user_id'); $table->boolean('google2fa_enable')->default(false); $table->string('google2fa_secret')->nullable(); - $table->timestamp('created_at') - ->default(DB::raw('CURRENT_TIMESTAMP')); - $table->timestamp('updated_at') - ->default(DB::raw('CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP')); + $table->text('recovery')->nullable(); + $table->timestamps(); $table->foreign('user_id') ->references('id') diff --git a/resources/database/2018_10_17_095425_add_recovery_to_user_2fa_table.php b/resources/database/2018_10_17_095425_add_recovery_to_user_2fa_table.php deleted file mode 100644 index 2099108..0000000 --- a/resources/database/2018_10_17_095425_add_recovery_to_user_2fa_table.php +++ /dev/null @@ -1,32 +0,0 @@ -text('recovery')->nullable()->after('google2fa_secret'); - }); - } - - /** - * Reverse the migrations. - * - * @return void - */ - public function down() - { - Schema::table('user_2fa', function (Blueprint $table) { - $table->dropColumn('recovery'); - }); - } -} \ No newline at end of file diff --git a/src/ToolServiceProvider.php b/src/ToolServiceProvider.php index 44ed367..bbbe1f6 100644 --- a/src/ToolServiceProvider.php +++ b/src/ToolServiceProvider.php @@ -16,7 +16,6 @@ class ToolServiceProvider extends ServiceProvider public function boot() { $this->loadViewsFrom(__DIR__ . '/../resources/views', 'google2fa'); - $this->loadMigrationsFrom(__DIR__ . '/../resources/database'); // Publishing is only necessary when using the CLI. if ($this->app->runningInConsole()) { @@ -24,6 +23,11 @@ public function boot() $this->publishes([ __DIR__ . '/../config/lifeonscreen2fa.php' => config_path('lifeonscreen2fa.php'), ], 'lifeonscreen2fa.config'); + + // Publishing the migrations. + $this->publishes([ + __DIR__.'/../database/migrations/' => database_path('migrations') + ], 'migrations'); } $this->app->booted(function () {