Skip to content

Commit

Permalink
changes
Browse files Browse the repository at this point in the history
  • Loading branch information
davidvandertuijn committed Oct 2, 2024
1 parent 596364e commit 1b4f922
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 105 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,19 @@ Progress is tracked in the after_seeders table. so that the seeder is only run o

## Install

```
```shell
composer require davidvandertuijn/laravel-after-seeders
```

Run migration

```php
```shell
php artisan migrate
```

Publish config

```
```shell
php artisan vendor:publish --provider="Davidvandertuijn\LaravelAfterSeeders\ServiceProvider"
```

Expand Down Expand Up @@ -99,13 +99,13 @@ Created Seeder: */database/after_seeders/YYYY_MM_DD_XXXXXX_my_table.json*:

The pending after seeders are executed with the command below:

```php
```shell
php artisan after-seeders:run
```

During execution it is checked whether the table and / or columns actually exist, otherwise the seeder is skipped.

```bash
```
Check seeder: YYYY_MM_DD_XXXXXX_my_table
[OK] Table "my_table" exists.
[OK] Columns "id, name" exists.
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
}
],
"require": {
"php": ">=7.0.0",
"ext-json": "*"
"ext-json": "*",
"php": ">=8.0.0"
},
"autoload": {
"psr-4" : {
Expand Down
2 changes: 1 addition & 1 deletion src/ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function boot()
$this->commands([
GenerateCommand::class,
MakeCommand::class,
RunCommand::class
RunCommand::class,
]);
}
}
34 changes: 7 additions & 27 deletions src/app/Console/Commands/AfterSeeders/Generate.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ public function handle(): void
{
$table = $this->argument('table');

if ( ! $this->ensureTableExist($table)) {
if (! $this->ensureTableExist($table)) {
return;
}

$path = $this->getPath();
$filename = $this->getFilename($table);
$columns = $this->getColumns($table);

if ( ! $this->checkColumns($columns)) {
if (! $this->checkColumns($columns)) {
return;
}

Expand All @@ -48,13 +48,12 @@ public function handle(): void

/**
* Check Columns.
* @param array $columns
* @return bool
*/
protected function checkColumns(array $columns): bool
{
if (count($columns) == 0) {
$this->error('[ERROR] No columns have been added.');

return false;
}

Expand All @@ -63,9 +62,6 @@ protected function checkColumns(array $columns): bool

/**
* Create.
* @param string $path
* @param string $filename
* @param string $json
*/
protected function create(string $path, string $filename, string $json): void
{
Expand All @@ -79,12 +75,10 @@ protected function create(string $path, string $filename, string $json): void

/**
* Ensure Table Exist.
* @param string $table
* @return bool
*/
protected function ensureTableExist(string $table): bool
{
if ( ! Schema::hasTable($table)) {
if (! Schema::hasTable($table)) {
$this->error(sprintf(
'[ERROR] Table "%s" does not exists.',
$table
Expand All @@ -98,14 +92,12 @@ protected function ensureTableExist(string $table): bool

/**
* Get Columns
* @param string $table
* @return array $columns
*/
protected function getColumns(string $table): array
{
$columns = [];

$this->line("Columns");
$this->line('Columns');

$columnListing = Schema::getColumnListing($table);

Expand All @@ -123,7 +115,6 @@ protected function getColumns(string $table): array

/**
* Get Date Prefix.
* @return string
*/
protected function getDatePrefix(): string
{
Expand All @@ -132,8 +123,6 @@ protected function getDatePrefix(): string

/**
* Get Filename.
* @param string $table
* @return string
*/
protected function getFilename(string $table): string
{
Expand All @@ -142,13 +131,11 @@ protected function getFilename(string $table): string

/**
* Get Json.
* @param \Illuminate\Support\Collection $records
* @return string
*/
protected function getJson(\Illuminate\Support\Collection $records): string
{
$records = [
'RECORDS' => $records->toArray()
'RECORDS' => $records->toArray(),
];

return json_encode($records, JSON_PRETTY_PRINT | JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX_APOS | JSON_HEX_QUOT);
Expand All @@ -164,7 +151,6 @@ protected function getMaxId(string $table)

/**
* Get Path.
* @return string
*/
protected function getPath(): string
{
Expand All @@ -173,12 +159,10 @@ protected function getPath(): string

/**
* Get Range
* @param string $table
* @return array
*/
protected function getRange(string $table): array
{
$this->line("Range");
$this->line('Range');

$from = $this->ask(sprintf(
'%s.id from',
Expand All @@ -195,10 +179,6 @@ protected function getRange(string $table): array

/**
* Get Records.
* @param string $table
* @param array $columns
* @param array $range
* @return \Illuminate\Support\Collection
*/
protected function getRecords(string $table, array $columns, array $range): \Illuminate\Support\Collection
{
Expand Down
22 changes: 6 additions & 16 deletions src/app/Console/Commands/AfterSeeders/Make.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Make extends Command
protected $signature = 'after-seeders:make {table}';

/**
* @var string $description
* @var string
*/
protected $description = 'Make After Seeder';

Expand All @@ -26,7 +26,7 @@ public function handle(): void
{
$table = $this->argument('table');

if ( ! $this->ensureTableExist($table)) {
if (! $this->ensureTableExist($table)) {
return;
}

Expand All @@ -39,9 +39,6 @@ public function handle(): void

/**
* Create.
* @param string $path
* @param string $filename
* @param string $json
*/
protected function create(string $path, string $filename, string $json): void
{
Expand All @@ -55,12 +52,10 @@ protected function create(string $path, string $filename, string $json): void

/**
* Ensure Table Exist.
* @param string $table
* @return bool
*/
protected function ensureTableExist(string $table): bool
{
if ( ! Schema::hasTable($table)) {
if (! Schema::hasTable($table)) {
$this->error(sprintf(
'[ERROR] Table "%s" does not exists.',
$table
Expand All @@ -74,7 +69,6 @@ protected function ensureTableExist(string $table): bool

/**
* Get Date Prefix.
* @return string
*/
protected function getDatePrefix(): string
{
Expand All @@ -83,8 +77,6 @@ protected function getDatePrefix(): string

/**
* Get Filename.
* @param string $table
* @return string
*/
protected function getFilename(string $table): string
{
Expand All @@ -93,24 +85,22 @@ protected function getFilename(string $table): string

/**
* Get Json.
* @return string
*/
protected function getJson(): string
{
$records = [
'RECORDS' => [
[
'name' => 'Example'
]
]
'name' => 'Example',
],
],
];

return json_encode($records, JSON_PRETTY_PRINT | JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX_APOS | JSON_HEX_QUOT);
}

/**
* Get Path.
* @return string
*/
protected function getPath(): string
{
Expand Down
Loading

0 comments on commit 1b4f922

Please sign in to comment.