Add Meilisearch deploy support and studio grid tweak

This commit is contained in:
2026-04-06 09:33:28 +02:00
parent 08ad757bcb
commit 23d363a50c
4 changed files with 78 additions and 1 deletions

View File

@@ -355,6 +355,21 @@ class User extends Authenticatable
*/ */
protected static function bootSearchable(): void protected static function bootSearchable(): void
{ {
// Register the SearchableScope so that the Builder::searchable() macro
// is available (needed for scout:import and manual ::searchable() calls).
// We intentionally skip static::observe(new ModelObserver) so that
// User saves/deletes do not auto-enqueue Scout sync jobs.
static::addGlobalScope(new \Laravel\Scout\SearchableScope);
$whenBootedCallback = function () {
(new static)->registerSearchableMacros();
};
if (method_exists(static::class, 'whenBooted')) {
static::whenBooted($whenBootedCallback);
} else {
$whenBootedCallback();
}
} }
/** /**

View File

@@ -554,7 +554,7 @@ export default function StudioContentBrowser({
{items.length > 0 ? ( {items.length > 0 ? (
viewMode === 'grid' ? ( viewMode === 'grid' ? (
<div className="grid gap-5 sm:grid-cols-2 xl:grid-cols-3"> <div className="grid gap-5 sm:grid-cols-2 xl:grid-cols-3 2xl:grid-cols-4">
{items.map((item) => <GridCard key={item.id} item={item} onExecuteAction={executeAction} busyKey={busyKey} />)} {items.map((item) => <GridCard key={item.id} item={item} onExecuteAction={executeAction} busyKey={busyKey} />)}
</div> </div>
) : ( ) : (

View File

@@ -16,6 +16,7 @@ local_build_command="${LOCAL_BUILD_COMMAND:-}"
run_local_build=1 run_local_build=1
run_remote_migrations=1 run_remote_migrations=1
run_db_sync=0 run_db_sync=0
run_meilisearch_setup=0
db_sync_source="" db_sync_source=""
legacy_db_sync_mode=0 legacy_db_sync_mode=0
force_db_sync=0 force_db_sync=0
@@ -37,6 +38,7 @@ Options:
Must equal 'replace production db from local' when running non-interactively. Must equal 'replace production db from local' when running non-interactively.
--with-db Legacy alias for --with-db-from=local. --with-db Legacy alias for --with-db-from=local.
--force-db-sync Legacy extra confirmation flag for --with-db. --force-db-sync Legacy extra confirmation flag for --with-db.
--with-meilisearch Sync index settings then reimport all searchable models.
--no-maintenance Skip php artisan down/up during deploy. --no-maintenance Skip php artisan down/up during deploy.
--help Show this help. --help Show this help.
@@ -157,6 +159,9 @@ while [[ $# -gt 0 ]]; do
--confirm-db-sync-phrase=*) --confirm-db-sync-phrase=*)
db_sync_confirm_phrase="${1#*=}" db_sync_confirm_phrase="${1#*=}"
;; ;;
--with-meilisearch)
run_meilisearch_setup=1
;;
--no-maintenance) --no-maintenance)
skip_maintenance=1 skip_maintenance=1
;; ;;
@@ -235,6 +240,7 @@ echo "Running remote Composer and Artisan steps..."
COMPOSER_BIN="$(printf '%q' "$composer_bin")" \ COMPOSER_BIN="$(printf '%q' "$composer_bin")" \
RUN_REMOTE_MIGRATIONS="$run_remote_migrations" \ RUN_REMOTE_MIGRATIONS="$run_remote_migrations" \
SKIP_MAINTENANCE="$skip_maintenance" \ SKIP_MAINTENANCE="$skip_maintenance" \
RUN_MEILISEARCH_SETUP="$run_meilisearch_setup" \
'bash -s' <<'EOF' 'bash -s' <<'EOF'
set -euo pipefail set -euo pipefail
@@ -263,6 +269,18 @@ fi
"$PHP_BIN" artisan view:cache "$PHP_BIN" artisan view:cache
"$PHP_BIN" artisan queue:restart || true "$PHP_BIN" artisan queue:restart || true
if [[ "$RUN_MEILISEARCH_SETUP" -eq 1 ]]; then
echo "Importing searchable models into Meilisearch (auto-creates indexes)..."
"$PHP_BIN" artisan scout:import "App\\Models\\Artwork"
"$PHP_BIN" artisan scout:import "App\\Models\\User"
"$PHP_BIN" artisan scout:import "App\\Models\\Group"
"$PHP_BIN" artisan scout:import "App\\Models\\Post"
"$PHP_BIN" artisan scout:import "App\\Models\\Message"
echo "Syncing Meilisearch index settings..."
"$PHP_BIN" artisan scout:sync-index-settings
echo "Meilisearch setup complete."
fi
if [[ "$SKIP_MAINTENANCE" -eq 0 ]]; then if [[ "$SKIP_MAINTENANCE" -eq 0 ]]; then
"$PHP_BIN" artisan up "$PHP_BIN" artisan up
trap - EXIT trap - EXIT

View File

@@ -0,0 +1,44 @@
<?php
declare(strict_types=1);
/**
* Sets artworks.updated_at = artworks.created_at for every row where they differ.
*
* Usage (local):
* php scripts/fix_artworks_updated_at.php [--dry-run]
*
* Usage (production via SSH):
* ssh klevze@server3.klevze.si "cd /opt/www/virtual/SkinbaseNova && php scripts/fix_artworks_updated_at.php"
*/
require __DIR__ . '/../vendor/autoload.php';
$app = require __DIR__ . '/../bootstrap/app.php';
$app->make(Illuminate\Contracts\Console\Kernel::class)->bootstrap();
$options = getopt('', ['dry-run']);
$isDryRun = array_key_exists('dry-run', $options);
use Illuminate\Support\Facades\DB;
// Count rows that need updating
$total = DB::table('artworks')
->whereColumn('updated_at', '!=', 'created_at')
->orWhereNull('updated_at')
->count();
if ($total === 0) {
fwrite(STDOUT, "Nothing to do: all artworks already have updated_at = created_at.\n");
exit(0);
}
fwrite(STDOUT, sprintf("Rows to fix: %d%s\n", $total, $isDryRun ? ' (dry-run, no changes written)' : ''));
if ($isDryRun) {
exit(0);
}
// Single bulk UPDATE — fast even on large tables, uses the existing index on created_at
$affected = DB::statement('UPDATE artworks SET updated_at = created_at WHERE updated_at != created_at OR updated_at IS NULL');
fwrite(STDOUT, sprintf("Done. updated_at synced to created_at for %d rows.\n", $total));