From 2da7a6da085b439d60478347ee5d1ecd33b09f53 Mon Sep 17 00:00:00 2001 From: root Date: Mon, 8 Dec 2025 04:27:07 +0000 Subject: [PATCH] Rename sessions to _sessions, drop legacy migrations table MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- .../PHP/DbTableUsage_CodeQualityRule.php | 5 --- .../Migrate_Normalize_Schema_Command.php | 2 +- app/RSpade/Core/Manifest/Manifest.php | 33 +++++++++------ app/RSpade/Core/Session/Session.php | 2 +- .../Core/Session/Session_Cleanup_Service.php | 4 +- .../Rules/Schema_Rule_Abstract.php | 2 +- database/migrations/.migration_whitelist | 5 +++ ...p_migrations_and_rename_sessions_table.php | 42 +++++++++++++++++++ 8 files changed, 72 insertions(+), 23 deletions(-) create mode 100755 database/migrations/2025_12_08_042258_drop_migrations_and_rename_sessions_table.php diff --git a/app/RSpade/CodeQuality/Rules/PHP/DbTableUsage_CodeQualityRule.php b/app/RSpade/CodeQuality/Rules/PHP/DbTableUsage_CodeQualityRule.php index 69e115c31..485b46757 100755 --- a/app/RSpade/CodeQuality/Rules/PHP/DbTableUsage_CodeQualityRule.php +++ b/app/RSpade/CodeQuality/Rules/PHP/DbTableUsage_CodeQualityRule.php @@ -88,11 +88,6 @@ class DbTableUsage_CodeQualityRule extends CodeQualityRule_Abstract continue; } - // Skip Laravel's sessions table - managed by framework - if ($table_name === 'sessions') { - continue; - } - // Skip framework internal tables (prefixed with underscore) // These are low-level system tables managed directly for performance if (str_starts_with($table_name, '_')) { diff --git a/app/RSpade/Commands/Migrate/Migrate_Normalize_Schema_Command.php b/app/RSpade/Commands/Migrate/Migrate_Normalize_Schema_Command.php index 9c662e573..7ab860fb0 100755 --- a/app/RSpade/Commands/Migrate/Migrate_Normalize_Schema_Command.php +++ b/app/RSpade/Commands/Migrate/Migrate_Normalize_Schema_Command.php @@ -323,7 +323,7 @@ class Migrate_Normalize_Schema_Command extends Command */ private function updateDatetimePrecision() { - $excludedTables = ['sessions', 'migrations', 'api_clients']; + $excludedTables = ['_sessions', '_migrations', 'api_clients']; $tables = DB::select('SHOW TABLES'); foreach ($tables as $table) { diff --git a/app/RSpade/Core/Manifest/Manifest.php b/app/RSpade/Core/Manifest/Manifest.php index 18603631b..01d4a0f00 100755 --- a/app/RSpade/Core/Manifest/Manifest.php +++ b/app/RSpade/Core/Manifest/Manifest.php @@ -3633,6 +3633,8 @@ class Manifest // Commands that should skip code quality checks $migration_commands = [ 'migrate', + 'migrate:begin', + 'migrate:commit', 'migrate:fresh', 'migrate:install', 'migrate:refresh', @@ -3652,26 +3654,21 @@ class Manifest /** * Verify database has been provisioned before running code quality checks * - * Checks that required framework tables (_manifest, _session) exist. - * If not, throws a fatal error instructing the user to run migrations. + * Checks that: + * 1. The _migrations table exists (created by Laravel migrate) + * 2. At least one migration has been applied + * * This prevents confusing code quality errors when the real issue is * that migrations haven't been run yet. */ protected static function __verify_database_provisioned(): void { - $required_tables = ['_manifest', '_session']; - $missing_tables = []; + $migrations_table = config('database.migrations', 'migrations'); - foreach ($required_tables as $table) { - if (!\Illuminate\Support\Facades\Schema::hasTable($table)) { - $missing_tables[] = $table; - } - } - - if (!empty($missing_tables)) { - $tables_list = implode(', ', $missing_tables); + // Check if migrations table exists + if (!\Illuminate\Support\Facades\Schema::hasTable($migrations_table)) { throw new \RuntimeException( - "Database not provisioned - required tables missing: {$tables_list}\n\n" . + "Database not provisioned - migrations table '{$migrations_table}' does not exist.\n\n" . "Run migrations before continuing:\n" . " php artisan migrate\n\n" . "If this is a fresh installation, you may also need to:\n" . @@ -3680,6 +3677,16 @@ class Manifest " 3. Run: php artisan migrate" ); } + + // Check if at least one migration has been applied + $result = \Illuminate\Support\Facades\DB::select("SELECT COUNT(*) as cnt FROM `{$migrations_table}`"); + if ($result[0]->cnt === 0) { + throw new \RuntimeException( + "Database not provisioned - no migrations have been applied.\n\n" . + "Run migrations before continuing:\n" . + " php artisan migrate" + ); + } } /** diff --git a/app/RSpade/Core/Session/Session.php b/app/RSpade/Core/Session/Session.php index 0d702a821..04c826aae 100755 --- a/app/RSpade/Core/Session/Session.php +++ b/app/RSpade/Core/Session/Session.php @@ -101,7 +101,7 @@ class Session extends Rsx_System_Model_Abstract * The table associated with the model * @var string */ - protected $table = 'sessions'; + protected $table = '_sessions'; /** * The attributes that should be cast diff --git a/app/RSpade/Core/Session/Session_Cleanup_Service.php b/app/RSpade/Core/Session/Session_Cleanup_Service.php index b2f442799..39db6f4aa 100755 --- a/app/RSpade/Core/Session/Session_Cleanup_Service.php +++ b/app/RSpade/Core/Session/Session_Cleanup_Service.php @@ -36,7 +36,7 @@ class Session_Cleanup_Service extends Rsx_Service_Abstract { // Logged-in sessions: older than 365 days $logged_in_cutoff = now()->subDays(365); - $logged_in_deleted = DB::table('sessions') + $logged_in_deleted = DB::table('_sessions') ->whereNotNull('login_user_id') ->where('last_active', '<', $logged_in_cutoff) ->delete(); @@ -45,7 +45,7 @@ class Session_Cleanup_Service extends Rsx_Service_Abstract // Anonymous sessions: older than 14 days $anonymous_cutoff = now()->subDays(14); - $anonymous_deleted = DB::table('sessions') + $anonymous_deleted = DB::table('_sessions') ->whereNull('login_user_id') ->where('last_active', '<', $anonymous_cutoff) ->delete(); diff --git a/app/RSpade/SchemaQuality/Rules/Schema_Rule_Abstract.php b/app/RSpade/SchemaQuality/Rules/Schema_Rule_Abstract.php index f9f71713c..a211b4c5e 100755 --- a/app/RSpade/SchemaQuality/Rules/Schema_Rule_Abstract.php +++ b/app/RSpade/SchemaQuality/Rules/Schema_Rule_Abstract.php @@ -7,7 +7,7 @@ use App\RSpade\SchemaQuality\SchemaViolation; abstract class Schema_Rule_Abstract { protected array $violations = []; - protected array $excluded_tables = ['migrations', 'sessions']; + protected array $excluded_tables = ['_migrations', '_sessions']; /** * Get the unique rule identifier diff --git a/database/migrations/.migration_whitelist b/database/migrations/.migration_whitelist index a75567cf0..c5514e2f1 100755 --- a/database/migrations/.migration_whitelist +++ b/database/migrations/.migration_whitelist @@ -326,6 +326,11 @@ "created_at": "2025-11-23T16:44:39+00:00", "created_by": "root", "command": "php artisan make:migration:safe reindex_user_roles_to_100_based" + }, + "2025_12_08_042258_drop_migrations_and_rename_sessions_table.php": { + "created_at": "2025-12-08T04:22:58+00:00", + "created_by": "root", + "command": "php artisan make:migration:safe drop_migrations_and_rename_sessions_table" } } } \ No newline at end of file diff --git a/database/migrations/2025_12_08_042258_drop_migrations_and_rename_sessions_table.php b/database/migrations/2025_12_08_042258_drop_migrations_and_rename_sessions_table.php new file mode 100755 index 000000000..c0f9d978f --- /dev/null +++ b/database/migrations/2025_12_08_042258_drop_migrations_and_rename_sessions_table.php @@ -0,0 +1,42 @@ +