@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('organizations', function (Blueprint $table) {
|
||||
// Personal for every workspace created so far; family and
|
||||
// organization workspaces are introduced later.
|
||||
$table->string('type')->default('personal')->after('name');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('organizations', function (Blueprint $table) {
|
||||
$table->dropColumn('type');
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('folders', function (Blueprint $table) {
|
||||
// Nullable so existing rows can be backfilled in a separate
|
||||
// migration; the Folder model always writes a value.
|
||||
$table->foreignId('organization_id')
|
||||
->nullable()
|
||||
->after('user_id')
|
||||
->constrained()
|
||||
->cascadeOnDelete();
|
||||
|
||||
$table->string('visibility')->default('private')->after('name');
|
||||
|
||||
$table->index(['organization_id', 'visibility']);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('folders', function (Blueprint $table) {
|
||||
$table->dropIndex(['organization_id', 'visibility']);
|
||||
$table->dropConstrainedForeignId('organization_id');
|
||||
$table->dropColumn('visibility');
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('todos', function (Blueprint $table) {
|
||||
// Nullable so existing rows can be backfilled in a separate
|
||||
// migration; the Todo model always writes a value.
|
||||
$table->foreignId('organization_id')
|
||||
->nullable()
|
||||
->after('user_id')
|
||||
->constrained()
|
||||
->cascadeOnDelete();
|
||||
|
||||
$table->index(['organization_id', 'completed_at']);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('todos', function (Blueprint $table) {
|
||||
$table->dropIndex(['organization_id', 'completed_at']);
|
||||
$table->dropConstrainedForeignId('organization_id');
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('folder_user', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('folder_id')->constrained()->cascadeOnDelete();
|
||||
$table->foreignId('user_id')->constrained()->cascadeOnDelete();
|
||||
$table->string('role')->default('viewer');
|
||||
$table->foreignId('invited_by')->nullable()->constrained('users')->nullOnDelete();
|
||||
$table->timestamps();
|
||||
|
||||
$table->unique(['folder_id', 'user_id']);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('folder_user');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('invitations', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('inviter_id')->constrained('users')->cascadeOnDelete();
|
||||
$table->string('email');
|
||||
// Workspace invitations store an OrganizationRole; folder
|
||||
// invitations store a FolderRole. The inviteable type selects
|
||||
// which role vocabulary applies.
|
||||
$table->string('role');
|
||||
$table->morphs('inviteable');
|
||||
$table->string('token', 64)->unique();
|
||||
$table->timestamp('expires_at')->nullable();
|
||||
$table->timestamp('accepted_at')->nullable();
|
||||
$table->foreignId('accepted_by_id')->nullable()->constrained('users')->nullOnDelete();
|
||||
$table->timestamps();
|
||||
|
||||
$table->unique(['inviteable_type', 'inviteable_id', 'email']);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('invitations');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Give every existing folder and todo a workspace so the access rules have
|
||||
* something to hang off. A folder belongs to whatever workspace its owner
|
||||
* had active at the time the schema changed, which is the personal
|
||||
* workspace every account receives. Todos inherit the workspace of their
|
||||
* folder.
|
||||
*
|
||||
* The visibility backfill mirrors predated behaviour: folders in personal
|
||||
* workspaces are private, and folders in any other workspace start shared
|
||||
* with members. Rows that already have a value are left untouched, which
|
||||
* makes this safe to re-run.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
DB::table('folders')
|
||||
->join('users', 'users.id', '=', 'folders.user_id')
|
||||
->whereNull('folders.organization_id')
|
||||
->update(['folders.organization_id' => DB::raw('users.current_organization_id')]);
|
||||
|
||||
DB::table('todos')
|
||||
->join('folders', 'folders.id', '=', 'todos.folder_id')
|
||||
->whereNull('todos.organization_id')
|
||||
->update(['todos.organization_id' => DB::raw('folders.organization_id')]);
|
||||
|
||||
DB::table('folders')
|
||||
->join('organizations', 'organizations.id', '=', 'folders.organization_id')
|
||||
->update([
|
||||
'folders.visibility' => DB::raw(
|
||||
"CASE WHEN organizations.personal_workspace = 1 THEN 'private' ELSE 'workspace' END"
|
||||
),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* The organization id is derived from the folder's owner, so nulling it
|
||||
* out restores the pre-migration state. Visibility is not reverted because
|
||||
* reverting it would only be guesswork.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
DB::table('todos')->update(['organization_id' => null]);
|
||||
DB::table('folders')->update(['organization_id' => null]);
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Every folder and todo must belong to a workspace: the workspace backfill
|
||||
* has run by this point, the models fill the id on create, and the bulk
|
||||
* seeding and transfer paths set it explicitly. Enforce it so no row can
|
||||
* ever exist without knowing which workspace it belongs to.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('folders', function (Blueprint $table) {
|
||||
$table->foreignId('organization_id')->nullable(false)->change();
|
||||
});
|
||||
|
||||
Schema::table('todos', function (Blueprint $table) {
|
||||
$table->foreignId('organization_id')->nullable(false)->change();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('folders', function (Blueprint $table) {
|
||||
$table->foreignId('organization_id')->nullable()->change();
|
||||
});
|
||||
|
||||
Schema::table('todos', function (Blueprint $table) {
|
||||
$table->foreignId('organization_id')->nullable()->change();
|
||||
});
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user