Skip to content

Commit eb5e9cd

Browse files
committed
fix: use local migrations
1 parent 9763f18 commit eb5e9cd

5 files changed

Lines changed: 230 additions & 102 deletions

testbench.yaml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@ providers:
1414
- Workbench\App\Providers\WorkbenchServiceProvider
1515

1616
migrations:
17-
- vendor/orchestra/testbench-core/laravel/migrations
18-
- vendor/orchestra/testbench-core/laravel/database/migrations
19-
- vendor/spatie/laravel-permission/database/migrations
2017
- workbench/database/migrations
2118
- database/migrations
2219

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php
2+
3+
use Illuminate\Database\Migrations\Migration;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Support\Facades\Schema;
6+
7+
return new class extends Migration
8+
{
9+
/**
10+
* Run the migrations.
11+
*/
12+
public function up(): void
13+
{
14+
Schema::create('users', function (Blueprint $table) {
15+
$table->id();
16+
$table->string('name');
17+
$table->string('email')->unique();
18+
$table->timestamp('email_verified_at')->nullable();
19+
$table->string('password');
20+
$table->rememberToken();
21+
$table->timestamps();
22+
});
23+
24+
Schema::create('password_reset_tokens', function (Blueprint $table) {
25+
$table->string('email')->primary();
26+
$table->string('token');
27+
$table->timestamp('created_at')->nullable();
28+
});
29+
30+
Schema::create('sessions', function (Blueprint $table) {
31+
$table->string('id')->primary();
32+
$table->foreignId('user_id')->nullable()->index();
33+
$table->string('ip_address', 45)->nullable();
34+
$table->text('user_agent')->nullable();
35+
$table->longText('payload');
36+
$table->integer('last_activity')->index();
37+
});
38+
}
39+
40+
/**
41+
* Reverse the migrations.
42+
*/
43+
public function down(): void
44+
{
45+
Schema::dropIfExists('users');
46+
Schema::dropIfExists('password_reset_tokens');
47+
Schema::dropIfExists('sessions');
48+
}
49+
};
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
use Illuminate\Database\Migrations\Migration;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Support\Facades\Schema;
6+
7+
return new class extends Migration
8+
{
9+
/**
10+
* Run the migrations.
11+
*/
12+
public function up(): void
13+
{
14+
Schema::create('cache', function (Blueprint $table) {
15+
$table->string('key')->primary();
16+
$table->mediumText('value');
17+
$table->integer('expiration');
18+
});
19+
20+
Schema::create('cache_locks', function (Blueprint $table) {
21+
$table->string('key')->primary();
22+
$table->string('owner');
23+
$table->integer('expiration');
24+
});
25+
}
26+
27+
/**
28+
* Reverse the migrations.
29+
*/
30+
public function down(): void
31+
{
32+
Schema::dropIfExists('cache');
33+
Schema::dropIfExists('cache_locks');
34+
}
35+
};
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<?php
2+
3+
use Illuminate\Database\Migrations\Migration;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Support\Facades\Schema;
6+
7+
return new class extends Migration
8+
{
9+
/**
10+
* Run the migrations.
11+
*/
12+
public function up(): void
13+
{
14+
Schema::create('jobs', function (Blueprint $table) {
15+
$table->id();
16+
$table->string('queue')->index();
17+
$table->longText('payload');
18+
$table->unsignedTinyInteger('attempts');
19+
$table->unsignedInteger('reserved_at')->nullable();
20+
$table->unsignedInteger('available_at');
21+
$table->unsignedInteger('created_at');
22+
});
23+
24+
Schema::create('job_batches', function (Blueprint $table) {
25+
$table->string('id')->primary();
26+
$table->string('name');
27+
$table->integer('total_jobs');
28+
$table->integer('pending_jobs');
29+
$table->integer('failed_jobs');
30+
$table->longText('failed_job_ids');
31+
$table->mediumText('options')->nullable();
32+
$table->integer('cancelled_at')->nullable();
33+
$table->integer('created_at');
34+
$table->integer('finished_at')->nullable();
35+
});
36+
37+
Schema::create('failed_jobs', function (Blueprint $table) {
38+
$table->id();
39+
$table->string('uuid')->unique();
40+
$table->text('connection');
41+
$table->text('queue');
42+
$table->longText('payload');
43+
$table->longText('exception');
44+
$table->timestamp('failed_at')->useCurrent();
45+
});
46+
}
47+
48+
/**
49+
* Reverse the migrations.
50+
*/
51+
public function down(): void
52+
{
53+
Schema::dropIfExists('jobs');
54+
Schema::dropIfExists('job_batches');
55+
Schema::dropIfExists('failed_jobs');
56+
}
57+
};

workbench/database/migrations/2025_08_28_142604_create_permission_tables.php

Lines changed: 89 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -20,106 +20,96 @@ public function up(): void
2020
throw_if(empty($tableNames), new Exception('Error: config/permission.php not loaded. Run [php artisan config:clear] and try again.'));
2121
throw_if($teams && empty($columnNames['team_foreign_key'] ?? null), new Exception('Error: team_foreign_key on config/permission.php not loaded. Run [php artisan config:clear] and try again.'));
2222

23-
if (! Schema::hasTable($tableNames['permissions'])) {
24-
Schema::create($tableNames['permissions'], static function (Blueprint $table) {
25-
// $table->engine('InnoDB');
26-
$table->bigIncrements('id'); // permission id
27-
$table->string('name'); // For MyISAM use string('name', 225); // (or 166 for InnoDB with Redundant/Compact row format)
28-
$table->string('guard_name'); // For MyISAM use string('guard_name', 25);
29-
$table->timestamps();
30-
23+
Schema::create($tableNames['permissions'], static function (Blueprint $table) {
24+
// $table->engine('InnoDB');
25+
$table->bigIncrements('id'); // permission id
26+
$table->string('name'); // For MyISAM use string('name', 225); // (or 166 for InnoDB with Redundant/Compact row format)
27+
$table->string('guard_name'); // For MyISAM use string('guard_name', 25);
28+
$table->timestamps();
29+
30+
$table->unique(['name', 'guard_name']);
31+
});
32+
33+
Schema::create($tableNames['roles'], static function (Blueprint $table) use ($teams, $columnNames) {
34+
// $table->engine('InnoDB');
35+
$table->bigIncrements('id'); // role id
36+
if ($teams || config('permission.testing')) { // permission.testing is a fix for sqlite testing
37+
$table->unsignedBigInteger($columnNames['team_foreign_key'])->nullable();
38+
$table->index($columnNames['team_foreign_key'], 'roles_team_foreign_key_index');
39+
}
40+
$table->string('name'); // For MyISAM use string('name', 225); // (or 166 for InnoDB with Redundant/Compact row format)
41+
$table->string('guard_name'); // For MyISAM use string('guard_name', 25);
42+
$table->timestamps();
43+
if ($teams || config('permission.testing')) {
44+
$table->unique([$columnNames['team_foreign_key'], 'name', 'guard_name']);
45+
} else {
3146
$table->unique(['name', 'guard_name']);
32-
});
33-
}
34-
35-
if (! Schema::hasTable($tableNames['roles'])) {
36-
Schema::create($tableNames['roles'], static function (Blueprint $table) use ($teams, $columnNames) {
37-
// $table->engine('InnoDB');
38-
$table->bigIncrements('id'); // role id
39-
if ($teams || config('permission.testing')) { // permission.testing is a fix for sqlite testing
40-
$table->unsignedBigInteger($columnNames['team_foreign_key'])->nullable();
41-
$table->index($columnNames['team_foreign_key'], 'roles_team_foreign_key_index');
42-
}
43-
$table->string('name'); // For MyISAM use string('name', 225); // (or 166 for InnoDB with Redundant/Compact row format)
44-
$table->string('guard_name'); // For MyISAM use string('guard_name', 25);
45-
$table->timestamps();
46-
if ($teams || config('permission.testing')) {
47-
$table->unique([$columnNames['team_foreign_key'], 'name', 'guard_name']);
48-
} else {
49-
$table->unique(['name', 'guard_name']);
50-
}
51-
});
52-
}
53-
54-
if (! Schema::hasTable($tableNames['model_has_permissions'])) {
55-
Schema::create($tableNames['model_has_permissions'], static function (Blueprint $table) use ($tableNames, $columnNames, $pivotPermission, $teams) {
56-
$table->unsignedBigInteger($pivotPermission);
57-
58-
$table->string('model_type');
59-
$table->unsignedBigInteger($columnNames['model_morph_key']);
60-
$table->index([$columnNames['model_morph_key'], 'model_type'], 'model_has_permissions_model_id_model_type_index');
61-
62-
$table->foreign($pivotPermission)
63-
->references('id') // permission id
64-
->on($tableNames['permissions'])
65-
->onDelete('cascade');
66-
if ($teams) {
67-
$table->unsignedBigInteger($columnNames['team_foreign_key']);
68-
$table->index($columnNames['team_foreign_key'], 'model_has_permissions_team_foreign_key_index');
69-
70-
$table->primary([$columnNames['team_foreign_key'], $pivotPermission, $columnNames['model_morph_key'], 'model_type'],
71-
'model_has_permissions_permission_model_type_primary');
72-
} else {
73-
$table->primary([$pivotPermission, $columnNames['model_morph_key'], 'model_type'],
74-
'model_has_permissions_permission_model_type_primary');
75-
}
76-
77-
});
78-
}
79-
80-
if (! Schema::hasTable($tableNames['model_has_roles'])) {
81-
Schema::create($tableNames['model_has_roles'], static function (Blueprint $table) use ($tableNames, $columnNames, $pivotRole, $teams) {
82-
$table->unsignedBigInteger($pivotRole);
83-
84-
$table->string('model_type');
85-
$table->unsignedBigInteger($columnNames['model_morph_key']);
86-
$table->index([$columnNames['model_morph_key'], 'model_type'], 'model_has_roles_model_id_model_type_index');
87-
88-
$table->foreign($pivotRole)
89-
->references('id') // role id
90-
->on($tableNames['roles'])
91-
->onDelete('cascade');
92-
if ($teams) {
93-
$table->unsignedBigInteger($columnNames['team_foreign_key']);
94-
$table->index($columnNames['team_foreign_key'], 'model_has_roles_team_foreign_key_index');
95-
96-
$table->primary([$columnNames['team_foreign_key'], $pivotRole, $columnNames['model_morph_key'], 'model_type'],
97-
'model_has_roles_role_model_type_primary');
98-
} else {
99-
$table->primary([$pivotRole, $columnNames['model_morph_key'], 'model_type'],
100-
'model_has_roles_role_model_type_primary');
101-
}
102-
});
103-
}
104-
105-
if (! Schema::hasTable($tableNames['role_has_permissions'])) {
106-
Schema::create($tableNames['role_has_permissions'], static function (Blueprint $table) use ($tableNames, $pivotRole, $pivotPermission) {
107-
$table->unsignedBigInteger($pivotPermission);
108-
$table->unsignedBigInteger($pivotRole);
109-
110-
$table->foreign($pivotPermission)
111-
->references('id') // permission id
112-
->on($tableNames['permissions'])
113-
->onDelete('cascade');
114-
115-
$table->foreign($pivotRole)
116-
->references('id') // role id
117-
->on($tableNames['roles'])
118-
->onDelete('cascade');
119-
120-
$table->primary([$pivotPermission, $pivotRole], 'role_has_permissions_permission_id_role_id_primary');
121-
});
122-
}
47+
}
48+
});
49+
50+
Schema::create($tableNames['model_has_permissions'], static function (Blueprint $table) use ($tableNames, $columnNames, $pivotPermission, $teams) {
51+
$table->unsignedBigInteger($pivotPermission);
52+
53+
$table->string('model_type');
54+
$table->unsignedBigInteger($columnNames['model_morph_key']);
55+
$table->index([$columnNames['model_morph_key'], 'model_type'], 'model_has_permissions_model_id_model_type_index');
56+
57+
$table->foreign($pivotPermission)
58+
->references('id') // permission id
59+
->on($tableNames['permissions'])
60+
->onDelete('cascade');
61+
if ($teams) {
62+
$table->unsignedBigInteger($columnNames['team_foreign_key']);
63+
$table->index($columnNames['team_foreign_key'], 'model_has_permissions_team_foreign_key_index');
64+
65+
$table->primary([$columnNames['team_foreign_key'], $pivotPermission, $columnNames['model_morph_key'], 'model_type'],
66+
'model_has_permissions_permission_model_type_primary');
67+
} else {
68+
$table->primary([$pivotPermission, $columnNames['model_morph_key'], 'model_type'],
69+
'model_has_permissions_permission_model_type_primary');
70+
}
71+
72+
});
73+
74+
Schema::create($tableNames['model_has_roles'], static function (Blueprint $table) use ($tableNames, $columnNames, $pivotRole, $teams) {
75+
$table->unsignedBigInteger($pivotRole);
76+
77+
$table->string('model_type');
78+
$table->unsignedBigInteger($columnNames['model_morph_key']);
79+
$table->index([$columnNames['model_morph_key'], 'model_type'], 'model_has_roles_model_id_model_type_index');
80+
81+
$table->foreign($pivotRole)
82+
->references('id') // role id
83+
->on($tableNames['roles'])
84+
->onDelete('cascade');
85+
if ($teams) {
86+
$table->unsignedBigInteger($columnNames['team_foreign_key']);
87+
$table->index($columnNames['team_foreign_key'], 'model_has_roles_team_foreign_key_index');
88+
89+
$table->primary([$columnNames['team_foreign_key'], $pivotRole, $columnNames['model_morph_key'], 'model_type'],
90+
'model_has_roles_role_model_type_primary');
91+
} else {
92+
$table->primary([$pivotRole, $columnNames['model_morph_key'], 'model_type'],
93+
'model_has_roles_role_model_type_primary');
94+
}
95+
});
96+
97+
Schema::create($tableNames['role_has_permissions'], static function (Blueprint $table) use ($tableNames, $pivotRole, $pivotPermission) {
98+
$table->unsignedBigInteger($pivotPermission);
99+
$table->unsignedBigInteger($pivotRole);
100+
101+
$table->foreign($pivotPermission)
102+
->references('id') // permission id
103+
->on($tableNames['permissions'])
104+
->onDelete('cascade');
105+
106+
$table->foreign($pivotRole)
107+
->references('id') // role id
108+
->on($tableNames['roles'])
109+
->onDelete('cascade');
110+
111+
$table->primary([$pivotPermission, $pivotRole], 'role_has_permissions_permission_id_role_id_primary');
112+
});
123113

124114
app('cache')
125115
->store(config('permission.cache.store') != 'default' ? config('permission.cache.store') : null)

0 commit comments

Comments
 (0)