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

Please allow table name to be configurable #427

Open
adrienne opened this issue Jul 7, 2023 · 2 comments
Open

Please allow table name to be configurable #427

adrienne opened this issue Jul 7, 2023 · 2 comments

Comments

@adrienne
Copy link

adrienne commented Jul 7, 2023

I really need my revisions table to be named something other than revisions and I am pretty sure that this is a common issue! Can this be made configurable via the config file? A lot of packages do that; see for instance https://github.com/plank/laravel-mediable , another package i use.

@MirisWisdom
Copy link

Best solution for now is to fork the repository and have your project consume the fork's package.

To edit the table name, refer to the patch below. In a nutshell:

  1. Edit the $table property in src/Venturecraft/Revisionable/Revision.php.
  2. Edit the revisions string in the migration scripts:
    • src/migrations/2013_04_09_062329_create_revisions_table.php
    • tests/migrations/2020_01_02_062329_add_additional_field_to_revisions.php
diff --git a/src/Venturecraft/Revisionable/Revision.php b/src/Venturecraft/Revisionable/Revision.php
index 2fdc838..16c062b 100644
--- a/src/Venturecraft/Revisionable/Revision.php
+++ b/src/Venturecraft/Revisionable/Revision.php
@@ -19,7 +19,7 @@ class Revision extends Eloquent
     /**
      * @var string
      */
-    public $table = 'revisions';
+    public $table = '<<TABLE NAME>>';
 
     /**
      * @var array
diff --git a/src/migrations/2013_04_09_062329_create_revisions_table.php b/src/migrations/2013_04_09_062329_create_revisions_table.php
index 8d3d2d2..04aa866 100644
--- a/src/migrations/2013_04_09_062329_create_revisions_table.php
+++ b/src/migrations/2013_04_09_062329_create_revisions_table.php
@@ -11,7 +11,7 @@ class CreateRevisionsTable extends Migration
      */
     public function up()
     {
-        Schema::create('revisions', function ($table) {
+        Schema::create('<<TABLE NAME>>', function ($table) {
             $table->bigIncrements('id');
             $table->string('revisionable_type');
             $table->unsignedBigInteger('revisionable_id');
@@ -32,6 +32,6 @@ class CreateRevisionsTable extends Migration
      */
     public function down()
     {
-        Schema::dropIfExists('revisions');
+        Schema::dropIfExists('<<TABLE NAME>>');
     }
 }
diff --git a/tests/migrations/2020_01_02_062329_add_additional_field_to_revisions.php b/tests/migrations/2020_01_02_062329_add_additional_field_to_revisions.php
index 389ed10..94dc77e 100644
--- a/tests/migrations/2020_01_02_062329_add_additional_field_to_revisions.php
+++ b/tests/migrations/2020_01_02_062329_add_additional_field_to_revisions.php
@@ -12,7 +12,7 @@ class AddAdditionalFieldToRevisions extends Migration
      */
     public function up()
     {
-        Schema::table('revisions', function (Blueprint $table) {
+        Schema::table('<<TABLE NAME>>', function (Blueprint $table) {
             $table->string('additional_field')->nullable();
         });
     }

@adrienne
Copy link
Author

@MirisWisdom Yeah, I can do that but I don't want to maintain a fork. It really seems to me that this SHOULD be configurable!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants