diff --git a/config/sqlviews.php b/config/sqlviews.php index 9124735..d4b8f9d 100644 --- a/config/sqlviews.php +++ b/config/sqlviews.php @@ -2,4 +2,11 @@ return [ 'mysql_views_path' => 'database/views', + + 'folder' => [ + 'create' => [ + 'views' => env('SQL_VIEWS_REGISTER_VIEWS_FOLDER', true), + 'procedures' => env('SQL_VIEWS_REGISTER_PROCEDURES_FOLDER', true) + ] + ] ]; diff --git a/readme.md b/readme.md index c5428e5..2cdd9e6 100644 --- a/readme.md +++ b/readme.md @@ -32,9 +32,16 @@ To use: It will search the folder recursively, so you can organise your views into subfolders if you wish. The packge comes with a tiny config file. +``` +php artisan vendor:publish --tag=sqlviews.config +``` - - +To disable the automatic creation of either the `database/views` and/or `database/procedures` folder(s) you can add the following `.env` variables :- +``` +SQL_VIEWS_REGISTER_VIEWS_FOLDER=false +SQL_VIEWS_REGISTER_PROCEDURES_FOLDER=false +``` +Please note that disabling folder creation without a good understanding of this package will cause you issues. ## Change log diff --git a/src/Commands/UpdateSqlViews.php b/src/Commands/UpdateSqlViews.php index d3e135b..559e251 100644 --- a/src/Commands/UpdateSqlViews.php +++ b/src/Commands/UpdateSqlViews.php @@ -44,12 +44,15 @@ public function __construct() */ public function handle() { - $countViews = $this->processDir(base_path('database/views')); - $this->info($countViews . ' views created'); - + if (config('sqlviews.folder.create.views')) { + $countViews = $this->processDir(base_path('database/views')); + $this->info($countViews . ' views created'); + } - $countProcs = $this->processProcsDir(base_path('database/procedures')); - $this->info($countProcs . ' procedures run'); + if (config('sqlviews.folder.create.procedures')) { + $countProcs = $this->processProcsDir(base_path('database/procedures')); + $this->info($countProcs . ' procedures run'); + } } public function processProcsDir(string $dir_path) diff --git a/src/SqlViewsServiceProvider.php b/src/SqlViewsServiceProvider.php index 396deb3..55a04e9 100644 --- a/src/SqlViewsServiceProvider.php +++ b/src/SqlViewsServiceProvider.php @@ -38,12 +38,12 @@ public function register() $this->mergeConfigFrom(__DIR__.'/../config/sqlviews.php', 'sqlviews'); //create the default folder for storing mysql view definitions - if (! is_dir(base_path('database/views'))) { + if (! is_dir(base_path('database/views')) && config('sqlviews.folder.create.views')) { mkdir(base_path('database/views')); copy(__DIR__.'/database/views/example.sql', base_path('database/views/example.sql')); } - if (!is_dir(base_path('database/procedures'))) { + if (!is_dir(base_path('database/procedures')) && config('sqlviews.folder.create.procedures')) { mkdir(base_path('database/procedures')); copy(__DIR__ . '/database/procedures/example-proc.sql', base_path('database/procedures/example-proc.sql')); }