Skip to content

Commit

Permalink
feat: enable customize datetime format
Browse files Browse the repository at this point in the history
  • Loading branch information
WatheqAlshowaiter committed Aug 22, 2024
1 parent e53ea32 commit 113a096
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 25 deletions.
12 changes: 4 additions & 8 deletions src/BackupTablesService.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class BackupTablesService
* @return bool
* @throws Exception
*/
public function generateBackup($tablesToBackup)
public function generateBackup($tablesToBackup, $dataTimeText = 'Y_m_d_H_i_s')
{
$tablesToBackup = Arr::wrap($tablesToBackup);

Expand All @@ -30,7 +30,7 @@ public function generateBackup($tablesToBackup)
return false;
}

$result = $this->processBackup($tablesToBackup);
$result = $this->processBackup($tablesToBackup, $dataTimeText);

$output = new ConsoleOutput;

Expand All @@ -51,16 +51,12 @@ public function generateBackup($tablesToBackup)
return false;
}

protected function processBackup(array $tablesToBackup = [])
protected function processBackup(array $tablesToBackup = [], $dateTimeFormat = 'Y_m_d_H_i_s')
{
$currentDateTime = now()->format('Y_m_d_H_i_s');
$currentDateTime = now()->format($dateTimeFormat);
$modelParent = "Illuminate\Database\Eloquent\Model";

foreach ($tablesToBackup as $table) {

//if ($table instanceof \Illuminate\Database\Eloquent\Model) {
// $table = $table->getTable();
//}
$table = $this->convertModelToTableName($table, $modelParent);

$newTableName = $table . '_backup_' . $currentDateTime;
Expand Down
15 changes: 15 additions & 0 deletions tests/BackupTablesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,21 @@ public function test_generate_single_table_backup_with_proper_name()
$this->assertTrue(Schema::hasTable($newTableName));
}

public function test_generate_single_table_backup_with_with_custom_format()
{
Carbon::setTestNow();
$tableName = 'fathers';
$customFormat = 'Y_d_m_H_i';

BackupTables::generateBackup($tableName, $customFormat);

$newTableName = $tableName.'_backup_'.now()->format($customFormat);

$this->assertTrue(Schema::hasTable($newTableName));

}


public function test_generate_single_table_backup_all_table_data()
{
Carbon::setTestNow();
Expand Down
29 changes: 12 additions & 17 deletions todos.md
Original file line number Diff line number Diff line change
@@ -1,25 +1,20 @@
### Todos
## Todos

### Before reload
- [x] new banner and make it in GitHub.com
- [x] make BackupTables facade if applicable
- [ ] customize `Y_m_d_H_i_s`
- [ ] add deepbackup(structure+data+virtual+stored columns)
- [ ] add ShallowBackup(structure+data)
- [ ] add OnlyData(structure+data)
- [ ] add OnlyStructure(structure)
- [ ] improve namings for method names
- [ ] add datbase droplist (sqilte, mysql, sql server, mariadb, postgres) + version for each of them in the ISSUE_TEMPLATE, and make it required and even add it to the next
- [ ] use Stratigy pattern instead of switch with OOP features
- [x] try previous versions of laravel until laravel 6
- [x] try all SQLs MySQL, MariaDB, SQLite, Postgres, and SQL Server
- [x] customize datetime format `Y_m_d_H_i_s`
- [ ] fix for foreign keys, and return foreign key father_id
- [ ] improve namings for method names
- [ ] add database drop list (sqlite, mysql, sql server, mariadb, postgres) + version for each of them in the ISSUE_TEMPLATE, and make it required and even add it to the next
- [ ] clean up the code
- [ ] return foreign key father_id
- [ ] php storm recommendations
- [ ] write automated tests for the code
- [ ] write documentation for the code
- [ ] add the package to packagist
- [ ] try previous versions of laravel until laravel 6
- [ ] 11 => sqlite, mysql/mariadb (1st party supported in Laravel 11), postgres
- [ ] 10 => sqlite, mysql, postgres
- [ ] 9 => sqlite, mysql, postgres
- [ ] 8 => sqlite, mysql, postgres
- [ ] 7 => sqlite, mysql, postgres
- [ ] 6 => sqlite, mysql, postgres
- [ ] fix all todo in the code, and remove commented code

### After
- [ ] use Strategy pattern instead of switch with OOP features (if useful)

0 comments on commit 113a096

Please sign in to comment.