File tree Expand file tree Collapse file tree 7 files changed +85
-14
lines changed
Expand file tree Collapse file tree 7 files changed +85
-14
lines changed Original file line number Diff line number Diff line change @@ -10,22 +10,17 @@ return new class extends Migration {
1010 Schema::create($this->prefix('entries'), function (Blueprint $table) {
1111 $table->id();
1212 $table->string('site')->index();
13- $table->unsignedBigInteger('origin_id')->nullable();
13+ $table->unsignedBigInteger('origin_id')->nullable()->index() ;
1414 $table->boolean('published')->default(true);
1515 $table->string('status');
1616 $table->string('slug')->nullable();
1717 $table->string('uri')->nullable()->index();
1818 $table->string('date')->nullable();
19- $table->integer('order')->nullable();
19+ $table->integer('order')->nullable()->index() ;
2020 $table->string('collection')->index();
2121 $table->string('blueprint', 30)->nullable()->index();
2222 $table->jsonb('data');
2323 $table->timestamps();
24-
25- $table->foreign('origin_id')
26- ->references('id')
27- ->on($this->prefix('entries'))
28- ->onDelete('set null');
2924 });
3025 }
3126
Original file line number Diff line number Diff line change @@ -10,23 +10,19 @@ return new class extends Migration {
1010 Schema::create($this->prefix('entries'), function (Blueprint $table) {
1111 $table->uuid('id');
1212 $table->string('site')->index();
13- $table->uuid('origin_id')->nullable();
13+ $table->uuid('origin_id')->nullable()->index() ;
1414 $table->boolean('published')->default(true);
1515 $table->string('status');
1616 $table->string('slug')->nullable();
1717 $table->string('uri')->nullable()->index();
1818 $table->string('date')->nullable();
19- $table->integer('order')->nullable();
19+ $table->integer('order')->nullable()->index() ;
2020 $table->string('collection')->index();
2121 $table->string('blueprint', 30)->nullable()->index();
2222 $table->jsonb('data');
2323 $table->timestamps();
2424
2525 $table->primary('id');
26- $table->foreign('origin_id')
27- ->references('id')
28- ->on($this->prefix('entries'))
29- ->onDelete('set null');
3026 });
3127 }
3228
Original file line number Diff line number Diff line change @@ -9,7 +9,7 @@ return new class extends Migration {
99 {
1010 Schema::create($this->prefix('form_submissions'), function (Blueprint $table) {
1111 $table->id();
12- $table->foreignId ('form_id')->constrained($this->prefix('forms'))->cascadeOnDelete ();
12+ $table->unsignedBigInteger ('form_id')->index ();
1313 $table->jsonb('data')->nullable();
1414 $table->timestamps(6);
1515
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ use Illuminate\Database\Schema\Blueprint;
4+ use Illuminate\Support\Facades\Schema;
5+ use Statamic\Eloquent\Database\BaseMigration as Migration;
6+
7+ return new class extends Migration {
8+ public function up()
9+ {
10+ Schema::table($this->prefix('entries'), function (Blueprint $table) {
11+ $table->dropForeign(['origin_id']);
12+ $table->index('order');
13+ });
14+ }
15+
16+ public function down()
17+ {
18+ Schema::table($this->prefix('entries'), function (Blueprint $table) {
19+ $table->foreign('origin_id')
20+ ->references('id')
21+ ->on($this->prefix('entries'))
22+ ->onDelete('set null');
23+ $table->dropIndex(['order']);
24+ });
25+ }
26+ };
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ use Illuminate\Database\Schema\Blueprint;
4+ use Illuminate\Support\Facades\Schema;
5+ use Statamic\Eloquent\Database\BaseMigration as Migration;
6+
7+ return new class extends Migration {
8+ public function up()
9+ {
10+ Schema::table($this->prefix('form_submissions'), function (Blueprint $table) {
11+ $table->dropForeign(['origin_id']);
12+ });
13+ }
14+
15+ public function down()
16+ {
17+ Schema::table($this->prefix('form_submissions'), function (Blueprint $table) {
18+ $table->foreign('form_id')
19+ ->references('id')
20+ ->on($this->prefix('forms'))
21+ ->onDelete('cascade');
22+ });
23+ }
24+ };
Original file line number Diff line number Diff line change @@ -42,6 +42,7 @@ class ServiceProvider extends AddonServiceProvider
4242 protected $ updateScripts = [
4343 \Statamic \Eloquent \Updates \AddOrderToEntriesTable::class,
4444 \Statamic \Eloquent \Updates \AddBlueprintToEntriesTable::class,
45+ \Statamic \Eloquent \Updates \DropForeignKeysOnEntriesAndForms::class,
4546 ];
4647
4748 protected $ listen = [
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Statamic \Eloquent \Updates ;
4+
5+ use Statamic \UpdateScripts \UpdateScript ;
6+
7+ class DropForeignKeysOnEntriesAndForms extends UpdateScript
8+ {
9+ public function shouldUpdate ($ newVersion , $ oldVersion )
10+ {
11+ return $ this ->isUpdatingTo ('2.3.0 ' );
12+ }
13+
14+ public function update ()
15+ {
16+ $ source = __DIR__ .'/../../database/migrations/updates/drop_foreign_keys_on_entries.php.stub ' ;
17+ $ dest = database_path ('migrations/ ' .date ('Y_m_d_His ' ).'_drop_foreign_keys_on_entries.php ' );
18+
19+ $ this ->files ->copy ($ source , $ dest );
20+
21+ $ source = __DIR__ .'/../../database/migrations/updates/drop_foreign_keys_on_forms.php.stub ' ;
22+ $ dest = database_path ('migrations/ ' .date ('Y_m_d_His ' ).'_drop_foreign_keys_on_forms.php ' );
23+
24+ $ this ->files ->copy ($ source , $ dest );
25+
26+ $ this ->console ()->info ('Migrations created ' );
27+ $ this ->console ()->comment ('Remember to run `php artisan migrate` to apply it to your database. ' );
28+ }
29+ }
You can’t perform that action at this time.
0 commit comments