-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Convert sql dump to Seeder (Sms, SubConnectionType) This change replaces the old approach of using sql dump to seed the db, instead uses Seperate Seeders. Created seeders; SmsSeeder and SubConnectionTypeSeeder * fix laravel lint * Create Seeder for agent_balance_history * Create seeder for targets and sub_targets
- Loading branch information
1 parent
29948ed
commit 4f9d8e9
Showing
20 changed files
with
342 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
src/backend/database/factories/SmsAndroidSettingFactory.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
namespace Database\Factories; | ||
|
||
use App\Models\SmsAndroidSetting; | ||
use Illuminate\Database\Eloquent\Factories\Factory; | ||
|
||
class SmsAndroidSettingFactory extends Factory { | ||
protected $model = SmsAndroidSetting::class; | ||
|
||
/** | ||
* Define the model's default state. | ||
* | ||
* @return array | ||
*/ | ||
public function definition() { | ||
return [ | ||
'url' => $this->faker->url, // Generates a random URL | ||
'token' => $this->faker->regexify('[A-Za-z0-9_-]{64}'), // Mimics a token format | ||
'key' => $this->faker->regexify('[A-Za-z0-9:_-]{72}'), // Mimics a key format | ||
'callback' => sprintf( | ||
'https://cloud.micropowermanager.com/api/sms-android-callback/%s/confirm/11', | ||
$this->faker->uuid | ||
), // Generates a formatted callback URL with a UUID | ||
'created_at' => now(), // Current timestamp | ||
'updated_at' => now(), // Current timestamp | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
namespace Database\Factories; | ||
|
||
use App\Models\SmsBody; | ||
use Illuminate\Database\Eloquent\Factories\Factory; | ||
|
||
class SmsBodyFactory extends Factory { | ||
protected $model = SmsBody::class; | ||
|
||
/** | ||
* Define the model's default state. | ||
* | ||
* @return array | ||
*/ | ||
public function definition() { | ||
return [ | ||
'reference' => 'test ref', | ||
'title' => 'Test title', | ||
'body' => 'test body', | ||
'place_holder' => 'test placeholder', | ||
'variables' => 'variable', | ||
'created_at' => $this->faker->dateTimeBetween('-1 year', 'now'), | ||
'updated_at' => $this->faker->dateTimeBetween($this->faker->dateTimeThisYear(), 'now'), | ||
]; | ||
} | ||
|
||
/** | ||
* Define the specific data for seeding. | ||
* | ||
* @return static | ||
*/ | ||
public function withCustomData($data) { | ||
return $this->state($data); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
<?php | ||
|
||
namespace Database\Factories; | ||
|
||
use App\Models\Sms; | ||
use Illuminate\Database\Eloquent\Factories\Factory; | ||
use Illuminate\Support\Str; | ||
|
||
class SmsFactory extends Factory { | ||
protected $model = Sms::class; | ||
|
||
/** | ||
* Define the model's default state. | ||
* | ||
* @return array | ||
*/ | ||
public function definition() { | ||
// Generate realistic Tanzanian names | ||
$firstNames = ['Ambidwile', 'Samiha', 'Tatu', 'Sharifa', 'Manica', 'Seghen', 'Bamba', | ||
'Bora', 'Hadiya', 'Fahima', 'Asiya', 'Asha', 'Adla', 'Hiba', 'Malika']; | ||
$lastNames = ['Ngabile', 'Furaha', 'Amaziah', 'Sanaa', 'Asili', 'Adhra', 'Fadhili', | ||
'Buyu', 'Sakina', 'Tumo', 'Ndweleifwa', 'Buyu', 'Amaziah', 'Saidi']; | ||
|
||
// Generate realistic meter numbers | ||
$meterNumber = '47000'.$this->faker->numberBetween(290000, 520000); | ||
|
||
// Generate realistic transaction amounts (between 1000 and 20000) | ||
$amount = $this->faker->numberBetween(1000, 20000); | ||
|
||
// Calculate units based on amount (approximately amount/2) | ||
$units = round($amount / 2, 1); | ||
|
||
// Calculate VAT (1% of amount) | ||
$vat = round($amount / 100, 2); | ||
|
||
// Generate random token (32 characters) | ||
$token = Str::random(32); | ||
|
||
// Format Tanzanian phone number | ||
$phone = '+255'.$this->faker->numberBetween(710000000, 789999999); | ||
|
||
// Construct message body | ||
$fullName = $this->faker->firstName().' '.$this->faker->lastName(); | ||
$body = sprintf( | ||
'Dear %s, we received your transaction %d.Meter: %s, %s Unit %s .Transaction amount is %d, \n VAT for energy : %s \n VAT for the other staffs : 0 . Your Company etc.', | ||
$fullName, | ||
$amount, | ||
$meterNumber, | ||
$token, | ||
$units, | ||
$amount, | ||
$vat | ||
); | ||
|
||
return [ | ||
'receiver' => $phone, | ||
'trigger_type' => 0, | ||
'trigger_id' => $this->faker->unique()->numberBetween(1, 10000), | ||
'body' => $body, | ||
'status' => 0, | ||
'uuid' => $this->faker->uuid(), | ||
'sender_id' => null, | ||
'direction' => 1, | ||
'gateway_id' => 1, | ||
'created_at' => $this->faker->dateTimeBetween('-1 month', 'now'), | ||
'updated_at' => $this->faker->dateTimeBetween('-1 month', 'now'), | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
src/backend/database/factories/SmsVariableDefaultValueFactory.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
|
||
namespace Database\Factories; | ||
|
||
use App\Models\SmsVariableDefaultValue; | ||
use Illuminate\Database\Eloquent\Factories\Factory; | ||
|
||
class SmsVariableDefaultValueFactory extends Factory { | ||
protected $model = SmsVariableDefaultValue::class; | ||
|
||
protected $variables = [ | ||
'name' => ['Herbert', 'John', 'Maria', 'Sarah', 'Michael'], | ||
'surname' => ['Kale', 'Smith', 'Johnson', 'Brown', 'Davis'], | ||
'amount' => ['1000', '1500', '2000', '2500', '3000'], | ||
'appliance_type_name' => ['fridge', 'tv', 'cooker', 'ac', 'washing machine'], | ||
'remaining' => ['3', '4', '5', '6', '7'], | ||
'due_date' => ['2021/04/01', '2021/05/01', '2021/06/01', '2021/07/01'], | ||
'meter' => ['47782371232', '47782371233', '47782371234', '47782371235'], | ||
'token' => ['5111 3511 9911 1177 7711', '5111 3511 9911 1177 7712'], | ||
'vat_energy' => ['15', '16', '17', '18', '19'], | ||
'vat_others' => ['10', '11', '12', '13', '14'], | ||
'energy' => ['5123.1', '5124.2', '5125.3', '5126.4'], | ||
'transaction_amount' => ['500', '600', '700', '800', '900'], | ||
]; | ||
|
||
/** | ||
* Define the model's default state. | ||
* | ||
* @return array | ||
*/ | ||
public function definition() { | ||
$variable = $this->faker->randomElement(array_keys($this->variables)); | ||
|
||
return [ | ||
'variable' => $variable, | ||
'value' => $this->faker->randomElement($this->variables[$variable]), | ||
'created_at' => $this->faker->dateTimeBetween('-1 year', 'now'), | ||
'updated_at' => $this->faker->dateTimeBetween('-1 year', 'now'), | ||
]; | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
src/backend/database/seeders/AgentBalanceHistorySeeder.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
namespace Database\Seeders; | ||
|
||
use App\Models\Agent; | ||
use App\Models\AgentBalanceHistory; | ||
use Illuminate\Database\Seeder; | ||
use MPM\DatabaseProxy\DatabaseProxyManagerService; | ||
|
||
class AgentBalanceHistorySeeder extends Seeder { | ||
public function __construct( | ||
private DatabaseProxyManagerService $databaseProxyManagerService, | ||
) { | ||
$this->databaseProxyManagerService->buildDatabaseConnectionDummyCompany(); | ||
} | ||
|
||
/** | ||
* Run the database seeds. | ||
* | ||
* @return void | ||
*/ | ||
public function run() { | ||
$agents = Agent::all(); | ||
|
||
foreach ($agents as $agent) { | ||
AgentBalanceHistory::factory()->create(['agent_id' => $agent->id]); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
namespace Database\Seeders; | ||
|
||
use App\Models\Sms; | ||
use App\Models\SmsAndroidSetting; | ||
use App\Models\SmsResendInformationKey; | ||
use App\Models\SmsVariableDefaultValue; | ||
use Illuminate\Database\Seeder; | ||
use MPM\DatabaseProxy\DatabaseProxyManagerService; | ||
|
||
class SmsSeeder extends Seeder { | ||
public function __construct( | ||
private DatabaseProxyManagerService $databaseProxyManagerService, | ||
) { | ||
$this->databaseProxyManagerService->buildDatabaseConnectionDummyCompany(); | ||
} | ||
|
||
/** | ||
* Run the database seeds. | ||
* | ||
* @return void | ||
*/ | ||
public function run() { | ||
SmsVariableDefaultValue::factory()->count(12)->create(); | ||
SmsResendInformationKey::factory()->create(); | ||
|
||
SmsAndroidSetting::factory()->count(2)->create(); | ||
Sms::factory()->count(2000)->create(); | ||
} | ||
} |
Oops, something went wrong.