Skip to content

Commit aa7aa0e

Browse files
qschmickroshangautam
authored andcommitted
feature ( table-prefix) : add a config parameter for table prefix to avoid table name collisions
1 parent 0f76c80 commit aa7aa0e

12 files changed

+36
-21
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ php artisan migrate
5050
php artisan totem:assets
5151
```
5252

53+
##### Table Prefix
54+
55+
Totems' tables use generic names which may conflict with existing tables in a project. To alleviate this the `.env` param `TOTEM_TABLE_PREFIX` can be set which will apply a prefix to all of Totems tables and their models.
56+
5357
#### Updating
5458

5559
Please republish totem assets after updating totem to a new version

config/totem.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@
222222
'api' => [
223223
'middleware' => env('TOTEM_API_MIDDLEWARE', 'api'),
224224
],
225+
'table_prefix' => env('TOTEM_TABLE_PREFIX', ''),
225226
'artisan' => [
226227
'command_filter' => [],
227228
],

database/migrations/2017_08_05_194349_create_tasks_table.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class CreateTasksTable extends Migration
1313
*/
1414
public function up()
1515
{
16-
Schema::create('tasks', function (Blueprint $table) {
16+
Schema::create(config('totem.table_prefix').'tasks', function (Blueprint $table) {
1717
$table->increments('id');
1818
$table->string('description');
1919
$table->string('command');
@@ -35,6 +35,6 @@ public function up()
3535
*/
3636
public function down()
3737
{
38-
Schema::dropIfExists('tasks');
38+
Schema::dropIfExists(config('totem.table_prefix').'tasks');
3939
}
4040
}

database/migrations/2017_08_05_195539_create_task_frequencies_table.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class CreateTaskFrequenciesTable extends Migration
1313
*/
1414
public function up()
1515
{
16-
Schema::create('task_frequencies', function (Blueprint $table) {
16+
Schema::create(config('totem.table_prefix').'task_frequencies', function (Blueprint $table) {
1717
$table->increments('id');
1818
$table->unsignedInteger('task_id');
1919
$table->string('label');
@@ -29,6 +29,6 @@ public function up()
2929
*/
3030
public function down()
3131
{
32-
Schema::dropIfExists('task_frequencies');
32+
Schema::dropIfExists(config('totem.table_prefix').'task_frequencies');
3333
}
3434
}

database/migrations/2017_08_05_201914_create_task_results_table.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class CreateTaskResultsTable extends Migration
1313
*/
1414
public function up()
1515
{
16-
Schema::create('task_results', function (Blueprint $table) {
16+
Schema::create(config('totem.table_prefix').'task_results', function (Blueprint $table) {
1717
$table->increments('id');
1818
$table->unsignedInteger('task_id');
1919
$table->timestamp('ran_at')->useCurrent();
@@ -30,6 +30,6 @@ public function up()
3030
*/
3131
public function down()
3232
{
33-
Schema::dropIfExists('task_results');
33+
Schema::dropIfExists(config('totem.table_prefix').'task_results');
3434
}
3535
}

database/migrations/2017_08_24_085132_create_frequency_parameters_table.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class CreateFrequencyParametersTable extends Migration
1313
*/
1414
public function up()
1515
{
16-
Schema::create('frequency_parameters', function (Blueprint $table) {
16+
Schema::create(config('totem.table_prefix').'frequency_parameters', function (Blueprint $table) {
1717
$table->increments('id');
1818
$table->unsignedInteger('frequency_id');
1919
$table->string('name');
@@ -29,6 +29,6 @@ public function up()
2929
*/
3030
public function down()
3131
{
32-
Schema::dropIfExists('frequency_parameters');
32+
Schema::dropIfExists(config('totem.table_prefix').'frequency_parameters');
3333
}
3434
}

database/migrations/2017_08_26_083622_alter_tasks_table_add_notifications_fields.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class AlterTasksTableAddNotificationsFields extends Migration
1313
*/
1414
public function up()
1515
{
16-
Schema::table('tasks', function (Blueprint $table) {
16+
Schema::table(config('totem.table_prefix').'tasks', function (Blueprint $table) {
1717
$table->string('notification_phone_number')->nullable()->after('notification_email_address');
1818
$table->string('notification_slack_webhook')->nullable()->after('notification_phone_number');
1919
});
@@ -26,11 +26,11 @@ public function up()
2626
*/
2727
public function down()
2828
{
29-
Schema::table('tasks', function (Blueprint $table) {
29+
Schema::table(config('totem.table_prefix').'tasks', function (Blueprint $table) {
3030
$table->dropColumn('notification_phone_number');
3131
});
3232

33-
Schema::table('tasks', function (Blueprint $table) {
33+
Schema::table(config('totem.table_prefix').'tasks', function (Blueprint $table) {
3434
$table->dropColumn('notification_slack_webhook');
3535
});
3636
}

src/Frequency.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@
33
namespace Studio\Totem;
44

55
use Studio\Totem\Traits\HasParameters;
6-
use Illuminate\Database\Eloquent\Model;
76

8-
class Frequency extends Model
7+
class Frequency extends TotemModel
98
{
109
use HasParameters;
1110

src/Parameter.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22

33
namespace Studio\Totem;
44

5-
use Illuminate\Database\Eloquent\Model;
6-
7-
class Parameter extends Model
5+
class Parameter extends TotemModel
86
{
97
protected $table = 'frequency_parameters';
108

src/Result.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22

33
namespace Studio\Totem;
44

5-
use Illuminate\Database\Eloquent\Model;
6-
7-
class Result extends Model
5+
class Result extends TotemModel
86
{
97
protected $table = 'task_results';
108

0 commit comments

Comments
 (0)