torrentpier/_release.php
Yury Pikhtarev fbde8cd421
feat(migrations): implement Phinx database migration system (#1976)
* feat(migrations): implement Phinx database migration system and update installation process

- Introduced a modern database migration system using Phinx, replacing the legacy SQL import method.
- Updated `install.php` to run migrations instead of importing SQL dumps.
- Added migration configuration file `phinx.php` and initial migration files for schema and data seeding.
- Created a new admin panel for migration status management.
- Updated UPGRADE_GUIDE.md to include migration setup instructions and benefits.
- Ensured backward compatibility for existing installations while facilitating a smoother transition to the new system.

* update runProcess to return process exit code

* refactor(migrations): clean up whitespace and formatting in migration files

- Removed unnecessary whitespace and adjusted formatting for consistency across migration files.

* fix(migrations): enforce NOT NULL constraints on migration columns

- Updated various migration columns to enforce NOT NULL constraints, ensuring data integrity across the schema.
- Adjusted default values and nullability for multiple fields in the initial schema migration files.

* refactor(database): standardize table engines to InnoDB for reliability

- Updated UPGRADE_GUIDE.md to reflect the use of InnoDB for all tables, emphasizing data integrity and reliability.
- Modified migration files to change table engines from MyISAM to InnoDB for various tracker and temporary tables.
- Optimized session variable settings in cron jobs for InnoDB compatibility.
- Ensured consistency across the schema by enforcing InnoDB usage in all relevant areas.

* fix(migrations): correct MySQL integer field types to match original schema

- Fix bb_forums table: forum_status (INT→TINYINT), forum_tpl_id (INT→SMALLINT)
- Fix bb_users table: avatar_ext_id remains TINYINT as per original schema
- Fix bb_groups table: avatar_ext_id (SMALLINT→INT) to match original INT(15)
- Fix bb_topics table: topic_show_first_post, topic_allow_robots (TINYINT(1)→TINYINT UNSIGNED)
- Remove incorrect 'limit' => 11 from standard INT fields, use default Phinx behavior
- Fix search_size field to use proper INT type instead of maximum value hack
- Correct poll table field types: vote_id (TINYINT), user_id (MEDIUMINT), vote_result (MEDIUMINT UNSIGNED)
- Standardize all timestamp and ID fields to use appropriate MySQL integer types

Ensures migration creates database schema identical to install/sql/mysql.sql
while maintaining InnoDB engine for all tables instead of MyISAM.

* fix(cache): auto-create cache directories when using FileStorage

The UnifiedCacheSystem was constructing directory paths for Nette FileStorage
but not creating them, causing "Directory not found" errors when accessing
caches like 'bb_login_err'. FileStorage expects directories to already exist.

Changes:
- Add automatic directory creation using bb_mkdir() before FileStorage init
- Handle both regular cache directories and SQLite parent directories
- Apply to both _buildStorage() and _buildDatastoreStorage() methods
- Add proper error handling with RuntimeException for failed creation
- Maintain consistency with TorrentPier's directory creation patterns

This ensures cache directories are created automatically when first accessed,
eliminating the need for manual directory creation during deployment.

Fixes: Cache initialization failures with missing directories

* refactor(docs): update README for clarity and remove legacy SQL file

- Improved formatting and clarity in the README, ensuring consistent line breaks and spacing.
- Updated installation instructions to reflect the new migration process, emphasizing the use of `phinx` for database setup.
- Removed the legacy SQL dump file `mysql.sql` and the `legacy-changes.txt` file, streamlining the installation process and reducing confusion for new users.
- Enhanced the documentation to guide users through the setup process more effectively.

* docs: enhance CLAUDE.md with migration details and directory updates

- Updated the `/library/` section to clarify its purpose.
- Added a new `/migrations/` directory section detailing database migration files managed by Phinx.
- Included migration commands for running and checking migration status.
- Revised the initial schema and seed data references for clarity.
- Improved formatting for consistency throughout the document.

* refactor(cron): remove demo_mode.php cron job and related functionality

- Deleted the demo_mode.php cron job file, which was responsible for managing demo mode operations.
- Added a migration to remove the demo_mode.php entry from the bb_cron table, ensuring a clean database state.
- Updated the initial schema migration comment to reflect the creation of essential database schema for fresh installations.

* refactor(docs): Fixed some typos

* chore: update changelog generation starting from v2.4.6-alpha.4

* refactor: Changed some `php_sapi_name()` to `PHP_SAPI` constants

* refactor: Extract hardcoded migrations to class property

* refactor: Use `count()` to count $initialMigrations elements

* feat(migrations): enhance migration management UI with new language variables

- Added new language variables for migration status, instructions, and applied/pending migrations to improve user interface clarity.
- Updated admin migration template to utilize these new language variables for better localization and maintainability.
- Introduced a new file 'CLAUDE.md' to the cleanup process for documentation purposes.

---------

Co-authored-by: Roman Kelesidis <roman25052006.kelesh@gmail.com>
2025-06-20 13:23:33 +04:00

130 lines
3.6 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
/**
* TorrentPier Bull-powered BitTorrent tracker engine
*
* @copyright Copyright (c) 2005-2025 TorrentPier (https://torrentpier.com)
* @link https://github.com/torrentpier/torrentpier for the canonical source repository
* @license https://github.com/torrentpier/torrentpier/blob/master/LICENSE MIT License
*/
define('BB_ROOT', __DIR__ . DIRECTORY_SEPARATOR);
define('BB_PATH', BB_ROOT);
// Check CLI mode
if (PHP_SAPI != 'cli') {
die('Please run <code style="background:#222;color:#00e01f;padding:2px 6px;border-radius:3px;">php ' . basename(__FILE__) . '</code> in CLI mode');
}
// Get all constants
require_once BB_ROOT . 'library/defines.php';
// Include CLI functions
require INC_DIR . '/functions_cli.php';
// Welcoming message
out("--- Release creation tool ---\n", 'info');
$configFile = BB_PATH . '/library/config.php';
if (!is_file($configFile)) {
out('- Config file ' . basename($configFile) . ' not found', 'error');
exit;
}
if (!is_readable($configFile)) {
out('- Config file ' . basename($configFile) . ' is not readable', 'error');
exit;
}
if (!is_writable($configFile)) {
out('- Config file ' . basename($configFile) . ' is not writable', 'error');
exit;
}
// Ask for version
fwrite(STDOUT, 'Enter version number (e.g, v2.4.0): ');
$version = trim(fgets(STDIN));
if (empty($version)) {
out("- Version cannot be empty. Please enter a valid version number", 'error');
exit;
} else {
// Add 'v' prefix if missing
if (!str_starts_with($version, 'v')) {
$version = 'v' . $version;
}
out("- Using version: $version", 'info');
}
// Ask for version emoji
fwrite(STDOUT, 'Enter version emoji: ');
$versionEmoji = trim(fgets(STDIN));
if (!empty($versionEmoji)) {
out("- Using version emoji: $versionEmoji", 'info');
}
// Ask for release date or use today's date
fwrite(STDOUT, "Enter release date (e.g. 25-05-2025), leave empty to use today's date: ");
$date = trim(fgets(STDIN));
if (empty($date)) {
$date = date('d-m-Y');
out("- Using current date: $date", 'info');
} else {
// Validate date format (dd-mm-yyyy)
$dateObj = DateTime::createFromFormat('d-m-Y', $date);
if (!$dateObj || $dateObj->format('d-m-Y') !== $date) {
out("- Invalid date format. Expected format: DD-MM-YYYY", 'error');
exit;
}
out("- Using date: $date", 'info');
}
// Read config file content
$content = file_get_contents($configFile);
// Update version
$content = preg_replace(
"/\\\$bb_cfg\['tp_version'\]\s*=\s*'[^']*';/",
"\$bb_cfg['tp_version'] = '$version';",
$content
);
// Update release date
$content = preg_replace(
"/\\\$bb_cfg\['tp_release_date'\]\s*=\s*'[^']*';/",
"\$bb_cfg['tp_release_date'] = '$date';",
$content
);
// Save updated config
$bytesWritten = file_put_contents($configFile, $content);
if ($bytesWritten === false) {
out("- Failed to write to config file", 'error');
exit;
}
if ($bytesWritten === 0) {
out("- Config file was not updated (0 bytes written)", 'error');
exit;
}
out("\n- Config file has been updated!", 'success');
// Update CHANGELOG.md
runProcess('npx git-cliff v2.4.6-alpha.4.. --config cliff.toml --tag "' . $version . '" > CHANGELOG.md');
// Git add & commit
runProcess('git add -A && git commit -m "release: ' . escapeshellarg($version) . (!empty($versionEmoji) ? (' ' . $versionEmoji) : '') . '"');
// Git tag
runProcess("git tag -a \"$version\" -m \"Release $version\"");
runProcess("git tag -v \"$version\"");
// Git push
runProcess("git push origin master");
runProcess("git push origin $version");
out("\n- Release $version has been successfully prepared, committed and pushed!", 'success');