Skip to content

Commit

Permalink
Consolidate seeders into migrations (#230)
Browse files Browse the repository at this point in the history
* Remove broken seeders

* Move initial data to migrations

* Remove unneeded seeders

* Remove empty `DatabaseSeeder`

* Fix lint

* Move `UsageTypeSeeder`

* Move `ProtectPagesSeeder`

* Clarify migrations

* Convert `MpmPluginsSeeder` to migrations

* Fix description length

* Populate `updated_at` on ... updates

* Add missing `down()` methods for random migrations

* Add `down()` methods for mpmlugins migrations

* Fix lint
  • Loading branch information
dmohns authored Aug 6, 2024
1 parent ab400a1 commit 614e834
Show file tree
Hide file tree
Showing 56 changed files with 981 additions and 1,102 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ public function store(CompanyRegistrationRequest $request): JsonResponse
$company->getId(),
function () use ($adminData, $company, $plugins, $usageType) {
$this->companyDatabaseService->doMigrations();
$this->companyDatabaseService->runSeeders();
$this->userService->create([
'name' => $adminData['name'],
'password' => $adminData['password'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace App\Services;

use App\Models\CompanyDatabase;
use Database\Seeders\DatabaseSeeder;
use Illuminate\Support\Facades\Artisan;
use MPM\DatabaseProxy\DatabaseProxyManagerService;

Expand Down Expand Up @@ -60,14 +59,6 @@ public function doMigrations(): void
]);
}

public function runSeeders(): void
{
Artisan::call('db:seed', [
'--force' => true,
'--class' => DatabaseSeeder::class,
]);
}

public function addPluginSpecificMenuItemsToCompanyDatabase($plugin, ?int $companyId = null): void
{
$rootClass = $plugin['root_class'];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
<?php

use App\Models\MpmPlugin;
use Carbon\Carbon;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;

return new class() extends Migration {
Expand All @@ -18,6 +21,65 @@ public function up()
$table->string('description');
$table->timestamps();
});

DB::table('mpm_plugins')->insert([
[
'id' => MpmPlugin::SPARK_METER,
'name' => 'SparkMeter',
'description' => 'This plugin uses KoiosAPI for the main authentication. After it got authenticated it uses the ThunderCloud API for basic CRUD operations. You need to enter the ThunderCloud Token on the site',
'created_at' => Carbon::now(),
'updated_at' => Carbon::now(),
],
[
'id' => MpmPlugin::STEAMACO_METER,
'name' => 'SteamaMeter',
'description' => substr('This plugin integrates Steamaco meters to Micropowermanager. It uses the same credentials as ui.steama.co for authentication. After it got authenticated, the plugin synchronizes Site, Customer ..', 0, 191),
'created_at' => Carbon::now(),
'updated_at' => Carbon::now(),
],
[
'id' => MpmPlugin::CALIN_METER,
'name' => 'CalinMeter',
'description' => 'This plugin integrates Calin meters to Micropowermanager. It uses user_id & api_key for creating tokens for energy.',
'created_at' => Carbon::now(),
'updated_at' => Carbon::now(),
],
[
'id' => MpmPlugin::CALIN_SMART_METER,
'name' => 'CalinSmartMeter',
'description' => 'This plugin integrates Calin meters to Micropowermanager. It uses company_name, user_name, password and password_vend for creating tokens for energy.',
'created_at' => Carbon::now(),
'updated_at' => Carbon::now(),
],
[
'id' => MpmPlugin::KELIN_METER,
'name' => 'KelinMeter',
'description' => 'This plugin integrates Kelim meters to Micropowermanager. It uses username & password for creating tokens for energy.',
'created_at' => Carbon::now(),
'updated_at' => Carbon::now(),
],
[
'id' => MpmPlugin::STRON_METER,
'name' => 'StronMeter',
'description' => 'This plugin integrates Stron meters to Micropowermanager. It uses the api login credentials for authentication.',
'created_at' => Carbon::now(),
'updated_at' => Carbon::now(),
],
[
'id' => MpmPlugin::SWIFTA_PAYMENT_PROVIDER,
'name' => 'SwiftaPayment',
'description' => 'This plugin developed for getting Swifta payments into MicroPowerManager.',
'created_at' => Carbon::now(),
'updated_at' => Carbon::now(),
],
[
'id' => MpmPlugin::MESOMB_PAYMENT_PROVIDER,
'name' => 'MesombPayment',
'description' => 'This plugin developed for getting MeSomb payments into MicroPowerManager.',
'created_at' => Carbon::now(),
'updated_at' => Carbon::now(),
],
]);
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
<?php

use App\Models\MpmPlugin;
use Carbon\Carbon;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;

return new class() extends Migration {
Expand All @@ -15,6 +18,24 @@ public function up()
Schema::table('mpm_plugins', function (Blueprint $table) {
$table->string('tail_tag')->nullable();
});

$mpm_plugins_mapping = [
MpmPlugin::SPARK_METER => 'Spark Meter',
MpmPlugin::STEAMACO_METER => 'Steamaco Meter',
MpmPlugin::CALIN_METER => 'Calin Meter',
MpmPlugin::CALIN_SMART_METER => 'CalinSmart Meter',
MpmPlugin::KELIN_METER => 'Kelin Meter',
MpmPlugin::STRON_METER => 'Stron Meter',
MpmPlugin::SWIFTA_PAYMENT_PROVIDER => null,
MpmPlugin::MESOMB_PAYMENT_PROVIDER => null,
];

foreach ($mpm_plugins_mapping as $id => $value) {
DB::table('mpm_plugins')->where('id', $id)->update([
'tail_tag' => $value,
'updated_at' => Carbon::now(),
]);
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
<?php

use App\Models\MpmPlugin;
use Carbon\Carbon;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;

return new class() extends Migration {
Expand All @@ -15,6 +18,24 @@ public function up()
Schema::table('mpm_plugins', function (Blueprint $table) {
$table->string('installation_command')->nullable();
});

$mpm_plugins_mapping = [
MpmPlugin::SPARK_METER => 'spark-meter:install',
MpmPlugin::STEAMACO_METER => 'steama-meter:install',
MpmPlugin::CALIN_METER => 'calin-meter:install',
MpmPlugin::CALIN_SMART_METER => 'calin-smart-meter:install',
MpmPlugin::KELIN_METER => 'kelin-meter:install',
MpmPlugin::STRON_METER => 'stron-meter:installl',
MpmPlugin::SWIFTA_PAYMENT_PROVIDER => 'swifta-payment-provider:install',
MpmPlugin::MESOMB_PAYMENT_PROVIDER => 'mesomb-payment-provider:install',
];

foreach ($mpm_plugins_mapping as $id => $value) {
DB::table('mpm_plugins')->where('id', $id)->update([
'installation_command' => $value,
'updated_at' => Carbon::now(),
]);
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

use App\Models\MpmPlugin;
use Carbon\Carbon;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Support\Facades\DB;

return new class() extends Migration {
public function up()
{
DB::table('mpm_plugins')->insert([
[
'id' => MpmPlugin::BULK_REGISTRATION,
'name' => 'BulkRegistration',
'description' => substr('This plugin provides bulk registration of the company\'s existing records. NOTE: Please do not use this plugin to register your Spark & Stemaco meter records. These records will be synchronized automatically once you configure your credential settings for these plugins.', 0, 191),
'tail_tag' => null,
'installation_command' => 'bulk-registration:install',
'created_at' => Carbon::now(),
'updated_at' => Carbon::now(),
],
]);
}

public function down()
{
DB::table('mpm_plugins')
->where('id', MpmPlugin::BULK_REGISTRATION)
->delete();
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

use App\Models\MpmPlugin;
use Carbon\Carbon;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Support\Facades\DB;

return new class() extends Migration {
public function up()
{
DB::table('mpm_plugins')->insert([
[
'id' => MpmPlugin::VIBER_MESSAGING,
'name' => 'ViberMessaging',
'description' => 'This plugin developed for the communication with customers throughout Viber messages.',
'tail_tag' => 'Viber Messaging',
'installation_command' => 'viber-messaging:install',
'created_at' => Carbon::now(),
'updated_at' => Carbon::now(),
],
]);
}

public function down()
{
DB::table('mpm_plugins')
->where('id', MpmPlugin::VIBER_MESSAGING)
->delete();
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

use App\Models\MpmPlugin;
use Carbon\Carbon;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Support\Facades\DB;

return new class() extends Migration {
public function up()
{
DB::table('mpm_plugins')->insert([
[
'id' => MpmPlugin::WAVE_MONEY_PAYMENT_PROVIDER,
'name' => 'WaveMoneyPayment',
'description' => 'This plugin developed for getting WaveMoney payments into MicroPowerManager.',
'tail_tag' => 'WaveMoney',
'installation_command' => 'wave-money-payment-provider:install',
'created_at' => Carbon::now(),
'updated_at' => Carbon::now(),
],
]);
}

public function down()
{
DB::table('mpm_plugins')
->where('id', MpmPlugin::WAVE_MONEY_PAYMENT_PROVIDER)
->delete();
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

use App\Models\MpmPlugin;
use Carbon\Carbon;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Support\Facades\DB;

return new class() extends Migration {
public function up()
{
DB::table('mpm_plugins')->insert([
[
'id' => MpmPlugin::MICRO_STAR_METERS,
'name' => 'MicroStarMeter',
'description' => 'This plugin integrates MicroStar meters to Micropowermanager. It uses user_id & api_key for creating tokens for energy.',
'tail_tag' => 'MicroStar Meter',
'installation_command' => 'micro-star-meter:install',
'created_at' => Carbon::now(),
'updated_at' => Carbon::now(),
],
]);
}

public function down()
{
DB::table('mpm_plugins')
->where('id', MpmPlugin::MICRO_STAR_METERS)
->delete();
}
};
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
<?php

use App\Models\MpmPlugin;
use Carbon\Carbon;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;

return new class() extends Migration {
Expand All @@ -15,6 +18,28 @@ public function up()
Schema::table('mpm_plugins', function (Blueprint $table) {
$table->string('root_class')->nullable();
});

$mpm_plugins_mapping = [
MpmPlugin::SPARK_METER => 'SparkMeter',
MpmPlugin::STEAMACO_METER => 'SteamaMeter',
MpmPlugin::CALIN_METER => 'CalinMeter',
MpmPlugin::CALIN_SMART_METER => 'CalinSmartMeter',
MpmPlugin::KELIN_METER => 'KelinMeter',
MpmPlugin::STRON_METER => 'StronMeter',
MpmPlugin::SWIFTA_PAYMENT_PROVIDER => 'SwiftaPaymentProvider',
MpmPlugin::MESOMB_PAYMENT_PROVIDER => 'MesombPaymentProvider',
MpmPlugin::BULK_REGISTRATION => 'BulkRegistration',
MpmPlugin::VIBER_MESSAGING => 'ViberMessaging',
MpmPlugin::WAVE_MONEY_PAYMENT_PROVIDER => 'WaveMoneyPaymentProvider',
MpmPlugin::MICRO_STAR_METERS => 'MicroStarMeter',
];

foreach ($mpm_plugins_mapping as $id => $value) {
DB::table('mpm_plugins')->where('id', $id)->update([
'root_class' => $value,
'updated_at' => Carbon::now(),
]);
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

use App\Models\MpmPlugin;
use Carbon\Carbon;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Support\Facades\DB;

return new class() extends Migration {
public function up()
{
DB::table('mpm_plugins')->insert([
[
'id' => MpmPlugin::SUN_KING_SHS,
'name' => 'SunKingSHS',
'description' => 'This plugin integrates SunKing solar home systems to Micropowermanager. It uses client_id & client_secret for creating tokens for energy.',
'tail_tag' => 'SunKing SHS',
'installation_command' => 'sun-king-shs:install',
'root_class' => 'SunKingSHS',
'created_at' => Carbon::now(),
'updated_at' => Carbon::now(),
],
]);
}

public function down()
{
DB::table('mpm_plugins')
->where('id', MpmPlugin::SUN_KING_SHS)
->delete();
}
};
Loading

0 comments on commit 614e834

Please sign in to comment.