diff --git a/.phpcs.xml b/.phpcs.xml index 7b2f27d82..fdeb70bf1 100644 --- a/.phpcs.xml +++ b/.phpcs.xml @@ -42,6 +42,7 @@ classes/* misc/my-migrations/* + misc/my2-migrations/* misc/pg-migrations/* diff --git a/misc/docker/web/bootstrap-base.sh b/misc/docker/web/bootstrap-base.sh index ea4db64b2..574d6c8cb 100755 --- a/misc/docker/web/bootstrap-base.sh +++ b/misc/docker/web/bootstrap-base.sh @@ -76,15 +76,22 @@ EOF ) | mysql -u root -p"$MYSQL_ROOT_PASSWORD" || exit 1 fi -echo "Run Mysql migrations..." -if ! FKEY_MY_DATABASE=1 LOCK_MY_DATABASE=1 "${CI_PROJECT_DIR}/vendor/bin/phinx" migrate -e gazelle; then - echo "phinx encountered a fatal error in the Mysql migrations" +PHINXBIN="${CI_PROJECT_DIR}/vendor/bin/phinx" +echo "Phase 1 Mysql migrations..." +if ! FKEY_MY_DATABASE=1 LOCK_MY_DATABASE=1 $PHINXBIN migrate -e gazelle; then + echo "Fatal error in the phase 1 Mysql migrations" exit 1 fi -echo "Run Postgresql migrations..." -if ! "${CI_PROJECT_DIR}/vendor/bin/phinx" migrate -c ./misc/phinx-pg.php; then - echo "phinx encountered a fatal error in the Postgresql migrations" +echo "Postgresql migrations..." +if ! $PHINXBIN migrate -c ./misc/phinx-pg.php; then + echo "Fatal error in the Postgresql migrations" + exit 1 +fi + +echo "Phase 2 Mysql migrations..." +if ! $PHINXBIN migrate -c ./misc/my2-phinx.php; then + echo "Fatal error in the phase 2 Mysql migrations" exit 1 fi diff --git a/misc/docker/web/bootstrap-npm.sh b/misc/docker/web/bootstrap-npm.sh index 55482f060..53f52ec2e 100755 --- a/misc/docker/web/bootstrap-npm.sh +++ b/misc/docker/web/bootstrap-npm.sh @@ -7,7 +7,7 @@ export npm_config_cache bin/config-css /tmp/config-css.js -npm install -g npm@11.2.0 +npm install -g npm@11.4.1 npm install sass npx update-browserslist-db@latest npx puppeteer browsers install chrome diff --git a/misc/docker/web/entrypoint.sh b/misc/docker/web/entrypoint.sh index 57ee5f037..24df95c43 100644 --- a/misc/docker/web/entrypoint.sh +++ b/misc/docker/web/entrypoint.sh @@ -14,7 +14,7 @@ if [ ! -e .docker-init-done ] ; then bin/local-patch echo "Installing node, go grab a coffee" bin/config-css /tmp/config-css.js - npm install -g npm@11.2.0 + npm install -g npm@11.4.1 npm install cypress npx update-browserslist-db@latest npx puppeteer browsers install chrome @@ -29,15 +29,22 @@ do sleep 10 done -echo "Run mysql migrations..." -if ! FKEY_MY_DATABASE=1 LOCK_MY_DATABASE=1 /var/www/vendor/bin/phinx migrate; then - echo "phinx encountered a fatal error in the Mysql migrations" +PHINXBIN=/var/www/vendor/bin/phinx +echo "Phase 1 Mysql migrations..." +if ! FKEY_MY_DATABASE=1 LOCK_MY_DATABASE=1 $PHINXBIN migrate -e gazelle; then + echo "Fatal error in the phase 1 Mysql migrations" exit 1 fi -echo "Run postgres migrations..." -if ! /var/www/vendor/bin/phinx migrate -c ./misc/phinx-pg.php; then - echo "phinx encountered a fatal error in the Postgresql migrations" +echo "Postgresql migrations..." +if ! $PHINXBIN migrate -c ./misc/phinx-pg.php; then + echo "Fatal error in the Postgresql migrations" + exit 1 +fi + +echo "Phase 2 Mysql migrations..." +if ! $PHINXBIN migrate -c ./misc/my2-phinx.php; then + echo "Fatal error in the phase 2 Mysql migrations" exit 1 fi diff --git a/misc/my2-migrations/20250528000000_drop_migrated_tables.php b/misc/my2-migrations/20250528000000_drop_migrated_tables.php new file mode 100644 index 000000000..ffccff5fe --- /dev/null +++ b/misc/my2-migrations/20250528000000_drop_migrated_tables.php @@ -0,0 +1,100 @@ +table($table)->drop()->save(); + } + } + + public function down(): void { + // There is no real reason to have to roll these tables back + // so it is much less hassle to paste the current definitions + // than convert to phinx methods. + $this->execute(" + CREATE TABLE blog ( + ID int NOT NULL AUTO_INCREMENT, + UserID int NOT NULL, + Title varchar(255) NOT NULL, + Body mediumtext NOT NULL, + Time datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, + ThreadID int DEFAULT NULL, + Important tinyint NOT NULL DEFAULT '0', + PRIMARY KEY (ID), + KEY UserID (UserID), + KEY Time (Time) + ) + "); + $this->execute(" + CREATE TABLE donations_bitcoin ( + BitcoinAddress varchar(34) CHARACTER SET utf8mb4 NOT NULL, + Amount decimal(24,8) NOT NULL, + donations_bitcoin_id int NOT NULL AUTO_INCREMENT, + PRIMARY KEY (donations_bitcoin_id), + KEY BitcoinAddress (BitcoinAddress,Amount) + ) + "); + $this->execute(" + CREATE TABLE email_blacklist ( + ID int NOT NULL AUTO_INCREMENT, + UserID int NOT NULL, + Email varchar(255) NOT NULL, + Time datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, + Comment mediumtext NOT NULL, + PRIMARY KEY (ID) + ) + "); + $this->execute(" + CREATE TABLE error_log ( + error_log_id int NOT NULL AUTO_INCREMENT, + duration float NOT NULL DEFAULT '0', + memory bigint NOT NULL DEFAULT '0', + nr_query int NOT NULL DEFAULT '0', + nr_cache int NOT NULL DEFAULT '0', + seen int NOT NULL DEFAULT '1', + created timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, + updated timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + digest binary(16) NOT NULL, + uri varchar(255) NOT NULL, + trace mediumtext NOT NULL, + request json NOT NULL, + error_list json NOT NULL, + logged_var json NOT NULL, + user_id int NOT NULL DEFAULT '0', + PRIMARY KEY (error_log_id), + UNIQUE KEY digest_uidx (digest), + KEY updated_idx (updated) + ) + "); + $this->execute(" + CREATE TABLE news ( + ID int NOT NULL AUTO_INCREMENT, + UserID int NOT NULL, + Title varchar(255) NOT NULL, + Body longtext NOT NULL, + Time datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, + PRIMARY KEY (ID), + KEY Time (Time) + ) + "); + $this->execute(" + CREATE TABLE users_history_passkeys ( + UserID int NOT NULL, + OldPassKey varchar(32) NOT NULL, + NewPassKey varchar(32) NOT NULL, + ChangeTime datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, + ChangerIP varchar(15) NOT NULL, + PRIMARY KEY (UserID,OldPassKey) + ) + "); + } +} diff --git a/misc/my2-phinx.php b/misc/my2-phinx.php new file mode 100644 index 000000000..01bd5434c --- /dev/null +++ b/misc/my2-phinx.php @@ -0,0 +1,34 @@ + [ + 'migrations' => __DIR__ . '/my2-migrations', + ], + 'environments' => [ + 'default_migration_table' => 'phinxlog2', + 'default_environment' => 'my2', + 'my2' => [ + 'adapter' => 'mysql', + 'host' => MYSQL_HOST, + 'port' => MYSQL_PORT, + 'name' => MYSQL_DB, + 'user' => MYSQL_PHINX_USER, + 'pass' => MYSQL_PHINX_PASS, + 'charset' => 'utf8mb4' + ], + ], + 'version_order' => 'creation', + 'feature_flags' => [ + 'unsigned_primary_keys' => false, + 'column_null_default' => false, + ], +]; diff --git a/phinx.php b/phinx.php index c71bb7354..0c04d9f02 100644 --- a/phinx.php +++ b/phinx.php @@ -4,11 +4,11 @@ require_once __DIR__ . '/lib/config.php'; return [ 'paths' => [ - 'migrations' => '%%PHINX_CONFIG_DIR%%/misc/my-migrations', + 'migrations' => __DIR__ . '/misc/my-migrations', ], 'environments' => [ - 'migration_table' => 'phinxlog', - 'default_environment' => 'gazelle', + 'default_migration_table' => 'phinxlog', + 'default_environment' => 'gazelle', 'gazelle' => [ 'adapter' => 'mysql', 'host' => MYSQL_HOST, diff --git a/tests/phpunit/manager/FeaturedAlbumTest.php b/tests/phpunit/manager/FeaturedAlbumTest.php index d6b93a6f5..5241af047 100644 --- a/tests/phpunit/manager/FeaturedAlbumTest.php +++ b/tests/phpunit/manager/FeaturedAlbumTest.php @@ -9,6 +9,8 @@ use Gazelle\Enum\LeechType; use Gazelle\Enum\LeechReason; class FeaturedAlbumTest extends TestCase { + use Pg; + protected TGroup $tgroup; protected User $user; @@ -24,10 +26,9 @@ class FeaturedAlbumTest extends TestCase { } public function tearDown(): void { - $db = DB::DB(); new Manager\News()->remove( - (int)$db->scalar(" - SELECT ID FROM news WHERE UserID = ? + (int)$this->pg()->scalar(" + select id_news from news where id_user = ? ", $this->user->id ) );