Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"backstage/fields": "self.version",
"backstage/media": "self.version",
"backstage/redirects": "self.version",
"backstage/users": "self.version",
"backstage/ai": "self.version",
"baspa/laravel-timezones": "^1.2",
"codewithdennis/filament-select-tree": "^4.0",
Expand Down
2 changes: 2 additions & 0 deletions packages/core/config/backstage/cms.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,6 @@
// Can be used to override the default file upload field user in Backstage.
// Example: 'default_file_upload_field' => \Backstage\Uploadcare\Forms\Components\Uploadcare::class,
'default_file_upload_field' => \Backstage\Fields\Fields\FileUpload::class,

'show_id_in_content_overview' => false,
];
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?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
{
if (Schema::hasColumn('content', 'id')) {
return;
}

Schema::table('content', function (Blueprint $table) {
$table->unsignedBigInteger('id')->after('ulid')->nullable();
});

// Fill the id column for existing content based on creation order (database-agnostic)
$contents = DB::table('content')->orderBy('created_at', 'asc')->get(['ulid']);
$id = 1;
foreach ($contents as $content) {
DB::table('content')->where('ulid', $content->ulid)->update(['id' => $id++]);
}

// Add unique index and make NOT NULL
Schema::table('content', function (Blueprint $table) {
$table->unsignedBigInteger('id')->nullable(false)->unique()->change();
});

// Set auto-increment using database-specific syntax
$driver = DB::getDriverName();

match ($driver) {
'mysql' => DB::statement('ALTER TABLE content MODIFY id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT'),
'pgsql' => DB::statement('CREATE SEQUENCE IF NOT EXISTS content_id_seq OWNED BY content.id;
SELECT setval(\'content_id_seq\', COALESCE((SELECT MAX(id) FROM content), 0) + 1, false);
ALTER TABLE content ALTER COLUMN id SET DEFAULT nextval(\'content_id_seq\')'),
'sqlite' => null, // SQLite doesn't support adding autoincrement to existing columns
'sqlsrv' => DB::statement('ALTER TABLE content ALTER COLUMN id BIGINT NOT NULL'),
default => null,
};
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Migration breaks inserts for SQLite and SQL Server

High Severity

The migration adds a NOT NULL id column but only configures auto-increment for MySQL and PostgreSQL. For SQLite (returns null, with a comment acknowledging the limitation) and SQL Server (only sets NOT NULL without IDENTITY), no auto-increment mechanism is established. Since the Content model uses ulid as primary key and doesn't set id explicitly, any attempt to create new content on SQLite or SQL Server will fail with a NOT NULL constraint violation.

Fix in Cursor Fix in Web

}

/**
* Reverse the migrations.
*/
public function down(): void
{
if (! Schema::hasColumn('content', 'id')) {
return;
}

Schema::table('content', function (Blueprint $table) {
$table->dropColumn('id');
});
}
};
6 changes: 6 additions & 0 deletions packages/core/src/Resources/ContentResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -814,6 +814,12 @@ public static function table(Table $table): Table
{
return $table
->columns([
TextColumn::make('id')
->label(__('ID'))
->sortable(fn () => config('backstage.cms.show_id_in_content_overview', false))
->searchable(fn () => config('backstage.cms.show_id_in_content_overview', false))
->visible(fn () => config('backstage.cms.show_id_in_content_overview', false)),

IconColumn::make('published')
->label(null)
->width(1)
Expand Down
Loading