Skip to content

Commit

Permalink
added database connection config
Browse files Browse the repository at this point in the history
  • Loading branch information
ivanwilliammd committed Sep 30, 2023
1 parent 35de8f5 commit bee7afa
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 6 deletions.
7 changes: 7 additions & 0 deletions config/satusehatintegration.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,11 @@
*/
'log_table_name' => 'satusehat_log',
'token_table_name' => 'satusehat_token',

/*
* This is the database connection that will be used by the migration and
* the Activity model shipped with this following Laravel's database.default
* If not set, it will use mysql instead.
*/
'database_connection' => env('DB_CONNECTION', 'mysql'),
];
4 changes: 2 additions & 2 deletions database/migrations/create_satusehat_log_table.php.stub
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class CreateSatusehatLogTable extends Migration
*/
public function up()
{
Schema::create(config('satusehatintegration.log_table_name'), function (Blueprint $table) {
Schema::connection(config('satusehatintegration.database_connection'))->create(config('satusehatintegration.log_table_name'), function (Blueprint $table) {
$table->string('response_id')->nullable();
$table->string('action');
$table->string('url');
Expand All @@ -31,6 +31,6 @@ class CreateSatusehatLogTable extends Migration
*/
public function down()
{
Schema::dropIfExists(config('satusehatintegration.log_table_name'));
Schema::connection(config('satusehatintegration.database_connection'))->dropIfExists(config('satusehatintegration.log_table_name'));
}
}
4 changes: 2 additions & 2 deletions database/migrations/create_satusehat_token_table.php.stub
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class CreateSatusehatTokenTable extends Migration
*/
public function up()
{
Schema::create(config('satusehatintegration.token_table_name'), function (Blueprint $table) {
Schema::connection(config('satusehatintegration.database_connection'))->create(config('satusehatintegration.token_table_name'), function (Blueprint $table) {
$table->string('environment');
$table->longText('token');
$table->timestamps();
Expand All @@ -27,6 +27,6 @@ class CreateSatusehatTokenTable extends Migration
*/
public function down()
{
Schema::dropIfExists(config('satusehatintegration.token_table_name'));
Schema::connection(config('satusehatintegration.database_connection'))->dropIfExists(config('satusehatintegration.token_table_name'));
}
}
5 changes: 4 additions & 1 deletion src/Models/SatusehatLog.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
<?php

namespace Satusehat\Integration;
namespace Satusehat\Integration\Models;

use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
32 changes: 31 additions & 1 deletion src/Models/SatusehatToken.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,33 @@
<?php

namespace Satusehat\Integration;
namespace Satusehat\Integration\Models;

use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;

/**
* Satusehat\Integration\Models\SatusehatToken.
*
* @property string $environment
* @property string $token
* @property \Illuminate\Support\Carbon|null $created_at
* @property \Illuminate\Support\Carbon|null $updated_at
*/

class SatusehatToken extends Model
{
public $guarded = [];

public function __construct(array $attributes = [])
{
if (! isset($this->connection)) {
$this->setConnection(config('satusehatintegration.database_connection'));
}

if (! isset($this->table)) {
$this->setTable(config('satusehatintegration.table_name'));
}

parent::__construct($attributes);
}
}

0 comments on commit bee7afa

Please sign in to comment.