Skip to content

Commit

Permalink
Merge pull request #8 from stats4sd/enhancement/add_config_to_disable…
Browse files Browse the repository at this point in the history
…_folder_creation

Suggested changes.
  • Loading branch information
dave-mills authored Oct 12, 2023
2 parents 246c01b + 4ffcf40 commit 70c7e93
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 9 deletions.
7 changes: 7 additions & 0 deletions config/sqlviews.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
]
]
];
11 changes: 9 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
13 changes: 8 additions & 5 deletions src/Commands/UpdateSqlViews.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions src/SqlViewsServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
}
Expand Down

0 comments on commit 70c7e93

Please sign in to comment.