update plans; assign lifetime;kanban; column sort;
tests / ci (push) Canceled after 0s

This commit is contained in:
2026-11-04 11:10:05 -08:00
parent 177f122c10
commit 31a80ec4d1
26 changed files with 2984 additions and 672 deletions
@@ -0,0 +1,137 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('plans', function (Blueprint $table) {
$table->id();
$table->string('key')->unique();
$table->string('name');
// Which kind of workspace the plan provisions. Free and personal
// plans map to a single-user personal workspace, family to a shared
// family workspace, and organization to a shared organization.
$table->string('workspace_type')->default('personal');
// The Stripe price id the plan is sold against. Plans without one
// are not purchasable and are hidden from the pricing page.
$table->string('stripe_price')->nullable();
$table->string('interval')->default('month');
// The advertised price, in minor units, so a bad edit cannot
// silently advertise a free plan.
$table->unsignedInteger('amount')->default(0);
// Limits. A null limit means unlimited.
$table->unsignedInteger('seat_limit')->nullable();
$table->unsignedInteger('max_folders')->nullable();
$table->unsignedInteger('max_folder_depth')->nullable();
$table->unsignedInteger('max_notes_per_folder')->nullable();
$table->unsignedInteger('note_chars')->nullable();
$table->unsignedInteger('sort_order')->default(0);
$table->boolean('is_active')->default(true);
$table->timestamps();
});
// The plans that ship with the application. The paid personal plan
// reuses the configured Pro price, so it stays in step with the Stripe
// product created in the dashboard.
$personalPrice = config('plans.plans.pro.price');
$personalPrice = is_string($personalPrice) && $personalPrice !== '' ? $personalPrice : null;
$plans = [
[
'key' => 'free',
'name' => 'Free',
'workspace_type' => 'personal',
'stripe_price' => null,
'amount' => 0,
'seat_limit' => 1,
'max_folders' => 3,
'max_folder_depth' => 1,
'max_notes_per_folder' => 50,
'note_chars' => 1000,
'sort_order' => 0,
],
[
'key' => 'personal',
'name' => 'Personal',
'workspace_type' => 'personal',
'stripe_price' => $personalPrice,
'amount' => 1000,
'seat_limit' => 1,
'max_folders' => null,
'max_folder_depth' => null,
'max_notes_per_folder' => null,
'note_chars' => null,
'sort_order' => 1,
],
[
'key' => 'family',
'name' => 'Family',
'workspace_type' => 'family',
'stripe_price' => null,
'amount' => 2500,
'seat_limit' => 6,
'max_folders' => null,
'max_folder_depth' => null,
'max_notes_per_folder' => null,
'note_chars' => null,
'sort_order' => 2,
],
[
'key' => 'organization',
'name' => 'Organization',
'workspace_type' => 'organization',
'stripe_price' => null,
'amount' => 9900,
'seat_limit' => null,
'max_folders' => null,
'max_folder_depth' => null,
'max_notes_per_folder' => null,
'note_chars' => null,
'sort_order' => 3,
],
[
'key' => 'unlimited',
'name' => 'Unlimited',
'workspace_type' => 'personal',
'stripe_price' => null,
'amount' => 0,
'seat_limit' => 1,
'max_folders' => null,
'max_folder_depth' => null,
'max_notes_per_folder' => null,
'note_chars' => null,
'sort_order' => 4,
],
];
foreach ($plans as $plan) {
DB::table('plans')->insert($plan + [
'interval' => 'month',
'is_active' => true,
'created_at' => now(),
'updated_at' => now(),
]);
}
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('plans');
}
};
@@ -0,0 +1,34 @@
<?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) {
// Nullable while the backfill migration assigns every existing
// workspace a plan; new workspaces are given one when created.
$table->foreignId('plan_id')
->nullable()
->after('lifetime_access')
->constrained()
->nullOnDelete();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('organizations', function (Blueprint $table) {
$table->dropConstrainedForeignId('plan_id');
});
}
};
@@ -0,0 +1,34 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*
* A null notes limit means the user has no per-user override and the limit
* comes from their workspace's plan instead.
*/
public function up(): void
{
Schema::table('users', function (Blueprint $table) {
$table->unsignedInteger('notes_limit')->nullable()->default(null)->change();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
DB::table('users')->whereNull('notes_limit')->update(['notes_limit' => 1000]);
Schema::table('users', function (Blueprint $table) {
$table->unsignedInteger('notes_limit')->nullable(false)->default(1000)->change();
});
}
};
@@ -0,0 +1,72 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Support\Facades\DB;
return new class extends Migration
{
/**
* Run the migrations.
*
* Give every workspace that predates plans one, so that entitlement and
* limits can be read from a plan instead of the legacy lifetime flag and
* subscription rows:
*
* - Grandfathered accounts stay entitled on the unlimited plan.
* - Existing subscribers move to the plan their Stripe price maps to.
* - Everyone else starts on the free plan.
*
* Idempotent: workspaces that already have a plan are left alone.
*/
public function up(): void
{
$unlimited = $this->planId('unlimited');
$personal = $this->planId('personal');
$free = $this->planId('free');
if ($unlimited === null || $personal === null || $free === null) {
return;
}
DB::table('organizations')
->where('lifetime_access', true)
->whereNull('plan_id')
->update(['plan_id' => $unlimited]);
$proPrice = config('plans.plans.pro.price');
if (is_string($proPrice) && $proPrice !== '') {
$subscribed = DB::table('subscriptions')
->where('stripe_price', $proPrice)
->distinct()
->pluck('organization_id');
DB::table('organizations')
->whereNull('plan_id')
->whereIn('id', $subscribed)
->update(['plan_id' => $personal]);
}
DB::table('organizations')
->whereNull('plan_id')
->update(['plan_id' => $free]);
}
/**
* Reverse the migrations.
*/
public function down(): void
{
DB::table('organizations')->update(['plan_id' => null]);
}
/**
* Get the id of the plan with the given key, if it exists.
*/
private function planId(string $key): ?int
{
$id = DB::table('plans')->where('key', $key)->value('id');
return $id === null ? null : (int) $id;
}
};