Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MPM-6] Usage types table in base & extend main settings table #37

Merged
merged 2 commits into from
Feb 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions Website/htdocs/mpmanager/app/Models/UsageType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class UsageType extends MasterModel
{
use HasFactory;

protected $table = 'usage_types';
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::connection('micro_power_manager')->create('usage_types', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->string('value');
$table->timestamps();
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::connection('micro_power_manager')->dropIfExists('usage_types');
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration {
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::connection('shard')->table('main_settings', function (Blueprint $table) {
$table->enum('usage_type', [
'mini-grid',
'shs',
'e-bike',
'mini-grid&shs',
'mini-grid&e-bike',
'shs&e-bike',
'mini-grid&shs&e-bike'
])->default('mini-grid&shs&e-bike')->after('id');
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::connection('shard')->table('main_settings', function (Blueprint $table) {
//
});
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ public function run()
{
$this->call(MpmPluginsSeeder::class);
$this->call(ProtectedPagesSeeder::class);
$this->call(UsageTypeSeeder::class);
}
}
49 changes: 49 additions & 0 deletions Website/htdocs/mpmanager/database/seeders/UsageTypeSeeder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

namespace Database\Seeders;

use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;

class UsageTypeSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
DB::connection('micro_power_manager')->table('usage_types')->insert(array(
[
'name' => 'Mini-Grid',
'value' => 'mini-grid',
],
[
'name' => 'Solar Home System',
'value' => 'shs',
],
[
'name' => 'EBike Rental',
'value' => 'e-bike',
],
[
'name' => 'Mini-Grid & Solar Home System',
'value' => 'mini-grid&shs',
],
[
'name' => 'Mini-Grid & EBike Rental',
'value' => 'mini-grid&e-bike',
],
[
'name' => 'Solar Home & EBike Rental',
'value' => 'shs&e-bike',
],
[
'name' => 'Mini-Grid & Solar Home System & EBike Rental',
'value' => 'mini-grid&shs&e-bike',
]
)
);
}
}
Loading