diff --git a/.docker/mysql-home/.my.cnf b/.docker/mysql-home/.my.cnf new file mode 100644 index 000000000..195755015 --- /dev/null +++ b/.docker/mysql-home/.my.cnf @@ -0,0 +1,4 @@ +[mysql] +user=gazelle +password=password +database=gazelle diff --git a/.docker/mysql/mysqld_sql_mode.cnf b/.docker/mysql/mysqld_sql_mode.cnf deleted file mode 100644 index b308fbada..000000000 --- a/.docker/mysql/mysqld_sql_mode.cnf +++ /dev/null @@ -1,6 +0,0 @@ -[mysqld] -sql_mode = ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION,NO_ZERO_DATE -userstat = on - -[client] -default-character-set = utf8mb4 diff --git a/.docker/web/entrypoint.sh b/.docker/web/entrypoint.sh index 55fbec37b..173e94ced 100644 --- a/.docker/web/entrypoint.sh +++ b/.docker/web/entrypoint.sh @@ -1,5 +1,7 @@ #!/bin/bash +set -euo pipefail + PHP_VER=8.1 run_service() @@ -7,42 +9,35 @@ run_service() service "$1" start || exit 1 } -# We'll need these anyway so why not kill some time while waiting on MySQL to be ready -if [ -n "$ENV" ] && [ "$ENV" == "prod" ]; then - su -c 'composer --version && composer install --no-progress --no-dev --optimize-autoloader --no-suggest; yarn --prod; yarn prod' gazelle -else - su -c 'composer --version && composer install --no-progress; yarn; yarn dev' gazelle +[ -f /var/www/lib/override.config.php ] || bash /var/www/.docker/web/generate-config.sh + +if [ ! -f /etc/php/${PHP_VER}/cli/conf.d/99-boris.ini ]; then + echo "Initialize Boris..." + grep '^disable_functions' /etc/php/${PHP_VER}/cli/php.ini \ + | sed -r 's/pcntl_(fork|signal|signal_dispatch|waitpid),//g' \ + > /etc/php/${PHP_VER}/cli/conf.d/99-boris.ini fi -# Wait for MySQL... -counter=1 -while ! mysql -h mysql -u "$MYSQL_USER" -p"$MYSQL_PASSWORD" -e "show databases;" > /dev/null 2>&1; do - sleep 1 - counter=$((counter + 1)) - if [ $((counter % 20)) -eq 0 ]; then - mysql -h mysql -u "$MYSQL_USER" -p"$MYSQL_PASSWORD" -e "show databases;" - >&2 echo "Still waiting for MySQL (Count: $counter)." - fi; +while ! nc -z mysql 3306 +do + echo "Waiting for MySQL..." + sleep 10 done -[ -f /var/www/lib/override.config.php ] || bash /var/www/.docker/web/generate-config.sh - echo "Run migrations..." if ! FKEY_MY_DATABASE=1 LOCK_MY_DATABASE=1 /var/www/vendor/bin/phinx migrate; then echo "PHINX FAILED TO RUN MIGRATIONS" exit 1 fi -echo -e "\n" - -if [ ! -f /srv/gazelle.txt ]; then +if [ ! -f /var/www/db/seeded.txt ]; then echo "Run seed:run..." - if ! /var/www/vendor/bin/phinx seed:run -s InitialUserSeeder; then + if ! /var/www/vendor/bin/phinx seed:run; then echo "PHINX FAILED TO SEED" exit 1 fi - touch /srv/gazelle.txt - echo -e "\n" + echo "Seeds have been run, delete to rerun" > /var/www/db/seeded.txt + chmod 400 /var/www/db/seeded.txt fi if [ ! -d /var/lib/gazelle/torrent ]; then @@ -53,11 +48,10 @@ if [ ! -d /var/lib/gazelle/torrent ]; then chown -R gazelle /var/lib/gazelle fi -if [ ! -f /etc/php/${PHP_VER}/cli/conf.d/99-boris.ini ]; then - echo "Initialize Boris..." - grep '^disable_functions' /etc/php/${PHP_VER}/cli/php.ini \ - | sed -r 's/pcntl_(fork|signal|signal_dispatch|waitpid),//g' \ - > /etc/php/${PHP_VER}/cli/conf.d/99-boris.ini +if [ "$ENV" == "prod" ]; then + su -c 'composer --version && composer install --no-progress --no-dev --optimize-autoloader --no-suggest; yarn --prod; npx browserslist@latest --update-db; yarn prod' gazelle +else + su -c 'composer --version && composer install --no-progress; yarn; npx browserslist@latest --update-db; yarn dev' gazelle fi echo "Start services..." diff --git a/.gitignore b/.gitignore index 0b4b24999..1c1b157c0 100644 --- a/.gitignore +++ b/.gitignore @@ -7,7 +7,6 @@ .cache/ .config/ .docker/data/ -.docker/pg/data .idea/ .vscode/ .local/ @@ -20,6 +19,7 @@ __MACOSX/ /cache +/db/seeded.txt /node_modules /public/static/font/ /public/static/local/ @@ -29,6 +29,9 @@ __MACOSX/ /mix.js.map /yarn-error.log +.docker/mysql-home/.mysql_history +!.docker/mysql-home/.my.cnf + /public/static/styles/**/*.css /public/static/styles/**/*.css.map !/public/static/styles/opendyslexic/style.css diff --git a/Dockerfile b/Dockerfile index 87d223f03..3828e5ce5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -17,8 +17,8 @@ RUN apt-get update \ && apt-get install -y --no-install-recommends \ cron \ make \ - mariadb-client \ nginx \ + netcat \ php8.1 \ php8.1-cli \ php8.1-curl \ diff --git a/README.md b/README.md index 542c0fe08..84226d35e 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ needs. Gazelle is written in PHP, Twig, JavaScript, and MySQL. ## Gazelle Runtime Dependencies * [Nginx](http://wiki.nginx.org/Main) (recommended) -* [PHP 7.4.27+](https://www.php.net/) (required) +* [PHP 8.1.4+](https://www.php.net/) (required) * [NodeJS 12+](https://nodejs.org/en/) (required) * [Memcached](http://memcached.org/) (required) * [Sphinx 2.0.6 or newer](http://sphinxsearch.com/) (required) @@ -80,7 +80,7 @@ page and tick everything. ### Ports The following ports are forwarded: -* 80 -> 8080 (web) +* 80 -> 7001 (web) * 3306 -> 36000 (mysql) * 34000 -> 34000 (ocelot) @@ -107,19 +107,12 @@ Edit the resulting file and then apply it: `docker exec -it $WEBCONT vendor/bin/phinx migrate` -To access the database, save the following in `~root/.my.cnf` of -the database container: - -``` - [mysql] - user = root - password = password - database = gazelle -``` +To access the database, look at `.docker/mysql-home/.my.cnf` +The credentials should match those used in the `docker-compose.yml` file. And then: -`docker exec -it $(docker ps|awk '$2 ~ /^mariadb/ {print $1}') mysql` +`docker exec -it $MYSQLCONT mysql` In the same vein, you can use `mysqldump` to perform a backup. diff --git a/db/migrations/20180104060449_tables.php b/db/migrations/20180104060449_tables.php index 17b95503d..411bb226e 100644 --- a/db/migrations/20180104060449_tables.php +++ b/db/migrations/20180104060449_tables.php @@ -30,12 +30,13 @@ DROP FUNCTION binomial_ci;"); // database engine, you can move forward by uncommenting the following line // and then iterating until things work. // $this->down(); + // + // Another alternative is to connect to the mysql container and run 'drop database gazelle; create database gazelle;' $this->execute("ALTER DATABASE CHARACTER SET 'utf8';"); $this->execute("ALTER DATABASE COLLATE='utf8_swedish_ci';"); $this->execute(" -CREATE FUNCTION IF NOT EXISTS `binomial_ci`(p int, n int) RETURNS float - DETERMINISTIC +CREATE FUNCTION `binomial_ci`(p int, n int) RETURNS float DETERMINISTIC RETURN IF(n = 0,0.0,((p + 1.35336) / n - 1.6452 * SQRT((p * (n-p)) / n + 0.67668) / n) / (1 + 2.7067 / n)); "); @@ -1927,7 +1928,7 @@ RETURN IF(n = 0,0.0,((p + 1.35336) / n - 1.6452 * SQRT((p * (n-p)) / n + 0.67668 'encoding' => 'utf8', ]) ->addColumn('StartTime', 'datetime', [ - 'null' => true, + 'null' => false, ]) ->addColumn('EndTime', 'datetime', [ 'null' => true, @@ -8926,11 +8927,6 @@ RETURN IF(n = 0,0.0,((p + 1.35336) / n - 1.6452 * SQRT((p * (n-p)) / n + 0.67668 $this->table('wiki_revisions')->insert([ ['ID' => 1, 'Revision' => 1, 'Title' => 'Wiki', 'Body' => 'Welcome to your new wiki! Hope this works.', 'Date' => '2019-01-01 12:59:59', 'Author' => 1] ])->save(); - $this->table('tags')->insert([ - ['Name' => 'rock', 'TagType' => 'genre', 'Uses' => 0, 'UserID' => 1], - ['Name' => 'pop', 'TagType' => 'genre', 'Uses' => 0, 'UserID' => 1], - ['Name' => 'female.fronted.symphonic.death.metal', 'TagType' => 'genre', 'Uses' => 0, 'UserID' => 1] - ])->save(); $this->table('stylesheets')->insert([ ['Name' => 'Layer cake', 'Description' => 'Grey stylesheet by Emm'], diff --git a/db/migrations/20181219220422_request_checksum.php b/db/migrations/20181219220422_request_checksum.php index a9f1fd5be..4d6d5602f 100644 --- a/db/migrations/20181219220422_request_checksum.php +++ b/db/migrations/20181219220422_request_checksum.php @@ -28,19 +28,9 @@ class RequestChecksum extends AbstractMigration */ public function up() { - $this->table('requests') - ->addColumn('Checksum', 'boolean', ['default' => false]) - ->update(); - $this->execute('ALTER TABLE requests MODIFY TimeFilled datetime'); - $this->execute("UPDATE requests SET TimeFilled = null WHERE TimeFilled = '0000-00-00 00:00:00'"); } public function down() { - $this->execute("UPDATE requests SET TimeFilled = '0000-00-00 00:00:00' WHERE TimeFilled IS NULL"); - $this->execute("ALTER TABLE requests MODIFY TimeFilled datetime NOT NULL DEFAULT '0000-00-00 00:00:00'"); - $this->table('requests') - ->removeColumn('Checksum') - ->update(); } } diff --git a/db/migrations/20181229185143_delete_torrent.php b/db/migrations/20181229185143_delete_torrent.php index 473b7c93e..5c15d0b7b 100644 --- a/db/migrations/20181229185143_delete_torrent.php +++ b/db/migrations/20181229185143_delete_torrent.php @@ -29,7 +29,6 @@ class DeleteTorrent extends AbstractMigration $this->table('torrents') ->changeColumn('last_action', 'datetime', ['null' => true]) ->update(); - $this->execute("UPDATE torrents SET last_action = NULL WHERE last_action = '0000-00-00 00:00:00'"); $this->table('deleted_torrents', ['id' => false, 'primary_key' => 'ID']) ->addColumn('ID', 'integer', ['length' => 10]) @@ -119,7 +118,6 @@ class DeleteTorrent extends AbstractMigration } public function down() { - $this->execute("UPDATE torrents SET last_action = '0000-00-00 00:00:00' WHERE last_action IS NULL"); $this->table('torrents') ->changeColumn('last_action', 'datetime', ['null' => false]) ->update(); diff --git a/db/migrations/20191103064312_drop_donation_email.php b/db/migrations/20191103064312_drop_donation_email.php index 55dcc984b..ce16154b2 100644 --- a/db/migrations/20191103064312_drop_donation_email.php +++ b/db/migrations/20191103064312_drop_donation_email.php @@ -31,9 +31,15 @@ class DropDonationEmail extends AbstractMigration * with the Table class. */ public function up() { - $this->execute("ALTER TABLE users_donor_ranks DROP COLUMN IF EXISTS Email"); + /* + $this->execute(" + ALTER TABLE users_donor_ranks DROP COLUMN Email + "); + */ } public function down() { - $this->execute("ALTER TABLE users_donor_ranks ADD COLUMN Email varchar(255)"); + $this->execute(" + ALTER TABLE users_donor_ranks ADD COLUMN Email varchar(255) + "); } } diff --git a/db/migrations/20200219075508_drop_secret.php b/db/migrations/20200219075508_drop_secret.php index b2814246f..a18b3dce7 100644 --- a/db/migrations/20200219075508_drop_secret.php +++ b/db/migrations/20200219075508_drop_secret.php @@ -17,14 +17,14 @@ class DropSecret extends AbstractMigration die("Migration cannot proceed, use the source: " . __FILE__ . "\n"); } $this->table('users_main') - ->removeColumn('Secret') + // ->removeColumn('Secret') ->changeColumn('Title', 'string', ['limit' => 255, 'default' => '']) ->update(); $this->table('users_info') - ->changeColumn('Info', 'text', ['limit' => 65536, 'default' => '']) - ->changeColumn('AdminComment', 'text', ['limit' => 65536, 'default' => '']) - ->changeColumn('SiteOptions', 'text', ['limit' => 65536, 'default' => '']) + ->changeColumn('Info', 'text', ['limit' => 65536]) + ->changeColumn('AdminComment', 'text', ['limit' => 65536]) + ->changeColumn('SiteOptions', 'text', ['limit' => 65536]) ->changeColumn('Warned', 'timestamp', ['null' => true]) ->changeColumn('Avatar', 'string', ['limit' => 255, 'default' => '']) ->changeColumn('SupportFor', 'string', ['limit' => 255, 'default' => '']) diff --git a/db/migrations/20200314171641_migrate_leech_stat_tables.php b/db/migrations/20200314171641_migrate_leech_stat_tables.php index 1459a053c..4700c0ec3 100644 --- a/db/migrations/20200314171641_migrate_leech_stat_tables.php +++ b/db/migrations/20200314171641_migrate_leech_stat_tables.php @@ -61,7 +61,7 @@ class MigrateLeechStatTables extends AbstractMigration ADD COLUMN Leechers int(6) NOT NULL DEFAULT 0, ADD COLUMN Snatched int(10) unsigned NOT NULL DEFAULT 0, ADD COLUMN balance bigint(20) NOT NULL DEFAULT 0, - ADD COLUMN last_action datetime NOT NULL DEFAULT '0000-00-00 00:00:00' + ADD COLUMN last_action datetime NOT NULL DEFAULT NULL "); $this->execute("UPDATE torrents INNER JOIN torrents_leech_stats tls ON (tls.TorrentID = torrents.ID) SET diff --git a/db/migrations/20200321180548_user_last_access_update.php b/db/migrations/20200321180548_user_last_access_update.php index a9ba731dd..ab533a3dc 100644 --- a/db/migrations/20200321180548_user_last_access_update.php +++ b/db/migrations/20200321180548_user_last_access_update.php @@ -34,7 +34,7 @@ class UserLastAccessUpdate extends AbstractMigration INSERT INTO user_last_access SELECT ID, LastAccess FROM users_main - WHERE LastAccess != '0000-00-00 00:00:00' + WHERE LastAccess IS NOT NULL ON DUPLICATE KEY UPDATE user_id = user_id "); } diff --git a/db/migrations/20200420143817_payment_cost.php b/db/migrations/20200420143817_payment_cost.php index 29d7b4053..3e2a29000 100644 --- a/db/migrations/20200420143817_payment_cost.php +++ b/db/migrations/20200420143817_payment_cost.php @@ -4,12 +4,16 @@ use Phinx\Migration\AbstractMigration; class PaymentCost extends AbstractMigration { public function up() { - $this->execute("ALTER TABLE payment_reminders MODIFY Expiry date NOT NULL DEFAULT current_date, ADD COLUMN AnnualRent integer NOT NULL DEFAULT 0"); - $this->execute("UPDATE payment_reminders SET Expiry = NULL WHERE Expiry = '0000-00-00'"); + $this->execute(" + ALTER TABLE payment_reminders + MODIFY Expiry date NOT NULL DEFAULT (current_date), + ADD COLUMN AnnualRent integer NOT NULL DEFAULT 0 + "); } public function down() { - $this->execute("ALTER TABLE payment_reminders MODIFY Expiry datetime default '0000-00-00 00:00:00', DROP COLUMN AnnualRent"); - $this->execute("UPDATE payment_reminders SET Expiry = '0000-00-00 00:00:00' WHERE Expiry is NULL"); + $this->execute(" + ALTER TABLE payment_reminders MODIFY Expiry datetime, DROP COLUMN AnnualRent + "); } } diff --git a/db/migrations/20200421092111_annual_rent_float.php b/db/migrations/20200421092111_annual_rent_float.php index 45fc074c6..edac6cd6d 100644 --- a/db/migrations/20200421092111_annual_rent_float.php +++ b/db/migrations/20200421092111_annual_rent_float.php @@ -4,9 +4,17 @@ use Phinx\Migration\AbstractMigration; class AnnualRentFloat extends AbstractMigration { public function up() { - $this->execute("ALTER TABLE payment_reminders MODIFY AnnualRent float(24,12) NOT NULL DEFAULT 0, MODIFY `cc` enum('BTC', 'EUR','USD') NOT NULL DEFAULT 'USD'"); + $this->execute(" + ALTER TABLE payment_reminders + MODIFY AnnualRent float(24,12) NOT NULL DEFAULT 0, + MODIFY `cc` enum('BTC', 'EUR','USD') NOT NULL DEFAULT 'USD' + "); } public function down() { - $this->execute("ALTER TABLE payment_reminders MODIFY AnnualRent int(11) NOT NULL DEFAULT 0, MODIFY `cc` enum('EUR','USD') NOT NULL DEFAULT 'USD'"); + $this->execute(" + ALTER TABLE payment_reminders + MODIFY AnnualRent int(11) NOT NULL DEFAULT 0, + MODIFY `cc` enum('EUR','USD') NOT NULL DEFAULT 'USD' + "); } } diff --git a/db/migrations/20200427085116_index_refactor.php b/db/migrations/20200427085116_index_refactor.php index 5ebebd64a..cb1cb5db6 100644 --- a/db/migrations/20200427085116_index_refactor.php +++ b/db/migrations/20200427085116_index_refactor.php @@ -55,7 +55,7 @@ class IndexRefactor extends AbstractMigration { ], [ 't' => 'collages_torrents', - 'old' => "AddedOn datetime NOT NULL DEFAULT '0000-00-00 00:00:00'", + 'old' => "AddedOn datetime NOT NULL", 'new' => "AddedOn datetime NOT NULL DEFAULT current_timestamp()", ], [ @@ -66,7 +66,7 @@ class IndexRefactor extends AbstractMigration { [ 't' => 'forums', 'old' => "CategoryID tinyint(4) DEFAULT NULL", - 'new' => "CategoryID tinyint(2) DEFAULT NULL", + 'new' => "CategoryID tinyint(2) DEFAULT NULL", ], [ 't' => 'forums_polls_votes', @@ -85,7 +85,7 @@ class IndexRefactor extends AbstractMigration { ], [ 't' => 'forums_topics', - 'old' => "CreatedTime datetime NOT NULL DEFAULT '0000-00-00 00:00:00'", + 'old' => "CreatedTime datetime NOT NULL", 'new' => "CreatedTime datetime NOT NULL DEFAULT current_timestamp()", ], [ @@ -95,7 +95,7 @@ class IndexRefactor extends AbstractMigration { ], [ 't' => 'forums_topics', - 'old' => "CreatedTime datetime NOT NULL DEFAULT '0000-00-00 00:00:00'", + 'old' => "CreatedTime datetime NOT NULL", 'new' => "CreatedTime datetime DEFAULT current_timestamp()", ], [ @@ -175,8 +175,8 @@ class IndexRefactor extends AbstractMigration { ], [ 't' => 'top10_history_torrents', - 'old' => "Rank tinyint(4) NOT NULL DEFAULT 0", - 'new' => "Rank tinyint(2) NOT NULL DEFAULT 0", + 'old' => "`Rank` tinyint(4) NOT NULL DEFAULT 0", + 'new' => "`Rank` tinyint(2) NOT NULL DEFAULT 0", ], [ 't' => 'torrents', @@ -185,12 +185,12 @@ class IndexRefactor extends AbstractMigration { ], [ 't' => 'torrents', - 'old' => "Time datetime NOT NULL DEFAULT '0000-00-00 00:00:00'", + 'old' => "Time datetime NOT NULL", 'new' => "Time datetime DEFAULT NULL", ], [ 't' => 'torrents', - 'old' => "LastReseedRequest datetime NOT NULL DEFAULT '0000-00-00 00:00:00'", + 'old' => "LastReseedRequest datetime NOT NULL", 'new' => "LastReseedRequest datetime DEFAULT NULL", ], [ @@ -210,8 +210,8 @@ class IndexRefactor extends AbstractMigration { ], [ 't' => 'users_donor_ranks', - 'old' => "Rank tinyint(4) NOT NULL DEFAULT 0", - 'new' => "Rank tinyint(2) NOT NULL DEFAULT 0", + 'old' => "`Rank` tinyint(4) NOT NULL DEFAULT 0", + 'new' => "`Rank` tinyint(2) NOT NULL DEFAULT 0", ], [ 't' => 'users_donor_ranks', @@ -270,38 +270,38 @@ class IndexRefactor extends AbstractMigration { return [ [ 't' => 'artists_alias', - 'old' => "DROP KEY IF EXISTS name_idx", /* if rollback */ - 'new' => "ADD KEY IF NOT EXISTS name_idx (Name)", /* if migrate */ + 'old' => "DROP KEY /* IF EXISTS */ name_idx", /* if rollback */ + 'new' => "ADD KEY /* IF NOT EXISTS */ name_idx (Name)", /* if migrate */ ], [ 't' => 'artists_similar', - 'old' => "ADD KEY IF NOT EXISTS ArtistID (ArtistID, SimilarID)", - 'new' => "DROP KEY IF EXISTS ArtistID", + 'old' => "ADD KEY /* IF NOT EXISTS */ ArtistID (ArtistID, SimilarID)", + 'new' => "DROP KEY /* IF EXISTS */ ArtistID", ], [ 't' => 'artists_similar', - 'old' => "DROP KEY IF EXISTS as_similarid_idx", - 'new' => "ADD KEY IF NOT EXISTS as_similarid_idx (SimilarID)", + 'old' => "DROP KEY /* IF EXISTS */ as_similarid_idx", + 'new' => "ADD KEY /* IF NOT EXISTS */ as_similarid_idx (SimilarID)", ], [ 't' => 'collages_torrents', - 'old' => "DROP KEY IF EXISTS group_idx", - 'new' => "ADD KEY IF NOT EXISTS group_idx (GroupID)", + 'old' => "DROP KEY /* IF EXISTS */ group_idx", + 'new' => "ADD KEY /* IF NOT EXISTS */ group_idx (GroupID)", ], [ 't' => 'contest', - 'old' => "DROP KEY IF EXISTS dateend_idx", - 'new' => "ADD KEY IF NOT EXISTS dateend_idx (DateEnd)", + 'old' => "DROP KEY /* IF EXISTS */ dateend_idx", + 'new' => "ADD KEY /* IF NOT EXISTS */ dateend_idx (DateEnd)", ], [ 't' => 'do_not_upload', - 'old' => "DROP KEY IF EXISTS sequence_idx", - 'new' => "ADD KEY IF NOT EXISTS sequence_idx (Sequence)", + 'old' => "DROP KEY /* IF EXISTS */ sequence_idx", + 'new' => "ADD KEY /* IF NOT EXISTS */ sequence_idx (Sequence)", ], [ 't' => 'donations', - 'old' => "ADD COLUMN IF NOT EXISTS Email varchar(255) NOT NULL", - 'new' => "DROP COLUMN IF EXISTS Email", + 'old' => "ADD COLUMN /* IF NOT EXISTS */ Email varchar(255) NOT NULL", + 'new' => "DROP COLUMN /* IF EXISTS */ Email", ], [ 't' => 'featured_albums', @@ -315,74 +315,74 @@ class IndexRefactor extends AbstractMigration { ], [ 't' => 'login_attempts', - 'old' => "DROP KEY IF EXISTS attempts_idx", - 'new' => "ADD KEY IF NOT EXISTS attempts_idx (Attempts)", + 'old' => "DROP KEY /* IF EXISTS */ attempts_idx", + 'new' => "ADD KEY /* IF NOT EXISTS */ attempts_idx (Attempts)", ], [ 't' => 'permissions', - 'old' => "DROP KEY IF EXISTS secondary_name_idx", - 'new' => "ADD KEY IF NOT EXISTS secondary_name_idx (Secondary, Name)", + 'old' => "DROP KEY /* IF EXISTS */ secondary_name_idx", + 'new' => "ADD KEY /* IF NOT EXISTS */ secondary_name_idx (Secondary, Name)", ], [ 't' => 'pm_conversations_users', - 'old' => "DROP KEY IF EXISTS pcu_userid_unread_ininbox", - 'new' => "ADD KEY IF NOT EXISTS pcu_userid_unread_ininbox (UserID, UnRead, InInbox)", + 'old' => "DROP KEY /* IF EXISTS */ pcu_userid_unread_ininbox", + 'new' => "ADD KEY /* IF NOT EXISTS */ pcu_userid_unread_ininbox (UserID, UnRead, InInbox)", ], [ 't' => 'referral_users', - 'old' => "DROP KEY IF EXISTS ru_invitekey_idx", - 'new' => "ADD KEY IF NOT EXISTS ru_invitekey_idx (InviteKey)", + 'old' => "DROP KEY /* IF EXISTS */ ru_invitekey_idx", + 'new' => "ADD KEY /* IF NOT EXISTS */ ru_invitekey_idx (InviteKey)", ], [ 't' => 'reportsv2', - 'old' => "ADD KEY IF NOT EXISTS ResolverID (ResolverID)", - 'new' => "DROP KEY IF EXISTS ResolverID", + 'old' => "ADD KEY /* IF NOT EXISTS */ ResolverID (ResolverID)", + 'new' => "DROP KEY /* IF EXISTS */ ResolverID", ], [ 't' => 'reportsv2', - 'old' => "DROP KEY IF EXISTS resolver_idx", - 'new' => "ADD KEY IF NOT EXISTS resolver_idx (ResolverID)", + 'old' => "DROP KEY /* IF EXISTS */ resolver_idx", + 'new' => "ADD KEY /* IF NOT EXISTS */ resolver_idx (ResolverID)", ], [ 't' => 'reportsv2', - 'old' => "DROP KEY IF EXISTS r2_torrentid_status", - 'new' => "ADD KEY IF NOT EXISTS r2_torrentid_status (TorrentID, Status)", + 'old' => "DROP KEY /* IF EXISTS */ r2_torrentid_status", + 'new' => "ADD KEY /* IF NOT EXISTS */ r2_torrentid_status (TorrentID, Status)", ], [ 't' => 'reportsv2', - 'old' => "DROP KEY IF EXISTS r2_lastchange_resolver_idx", - 'new' => "ADD KEY IF NOT EXISTS r2_lastchange_resolver_idx (LastChangeTime, ResolverID)", + 'old' => "DROP KEY /* IF EXISTS */ r2_lastchange_resolver_idx", + 'new' => "ADD KEY /* IF NOT EXISTS */ r2_lastchange_resolver_idx (LastChangeTime, ResolverID)", ], [ 't' => 'requests_artists', - 'old' => "DROP KEY IF EXISTS artistid_idx", - 'new' => "ADD KEY IF NOT EXISTS artistid_idx (ArtistID)", + 'old' => "DROP KEY /* IF EXISTS */ artistid_idx", + 'new' => "ADD KEY /* IF NOT EXISTS */ artistid_idx (ArtistID)", ], [ 't' => 'requests_artists', - 'old' => "DROP KEY IF EXISTS aliasid_idx", - 'new' => "ADD KEY IF NOT EXISTS aliasid_idx (AliasID)", + 'old' => "DROP KEY /* IF EXISTS */ aliasid_idx", + 'new' => "ADD KEY /* IF NOT EXISTS */ aliasid_idx (AliasID)", ], [ 't' => 'staff_blog_visits', - 'old' => "ADD UNIQUE KEY IF NOT EXISTS UserID (UserID)", - 'new' => "DROP KEY IF EXISTS UserID", + 'old' => "ADD UNIQUE KEY /* IF NOT EXISTS */ UserID (UserID)", + 'new' => "DROP KEY /* IF EXISTS */ UserID", ], [ 't' => 'staff_pm_conversations', - 'old' => "DROP KEY IF EXISTS spc_user_unr_idx", - 'new' => "ADD KEY IF NOT EXISTS spc_user_unr_idx (UserID, Unread)", + 'old' => "DROP KEY /* IF EXISTS */ spc_user_unr_idx", + 'new' => "ADD KEY /* IF NOT EXISTS */ spc_user_unr_idx (UserID, Unread)", ], [ 't' => 'staff_pm_messages', - 'old' => "DROP KEY IF EXISTS convid_idx", - 'new' => "ADD KEY IF NOT EXISTS convid_idx (ConvID)", + 'old' => "DROP KEY /* IF EXISTS */ convid_idx", + 'new' => "ADD KEY /* IF NOT EXISTS */ convid_idx (ConvID)", ], [ 't' => 'stylesheets', - 'old' => "DROP KEY IF EXISTS default_idx", - 'new' => "ADD KEY IF NOT EXISTS default_idx (`Default`)", + 'old' => "DROP KEY /* IF EXISTS */ default_idx", + 'new' => "ADD KEY /* IF NOT EXISTS */ default_idx (`Default`)", ], [ 't' => 'torrents_bad_files', @@ -426,38 +426,38 @@ class IndexRefactor extends AbstractMigration { ], [ 't' => 'users_info', - 'old' => "DROP KEY IF EXISTS ui_bandate_idx", - 'new' => "ADD KEY IF NOT EXISTS ui_bandate_idx (BanDate)", + 'old' => "DROP KEY /* IF EXISTS */ ui_bandate_idx", + 'new' => "ADD KEY /* IF NOT EXISTS */ ui_bandate_idx (BanDate)", ], [ 't' => 'users_main', - 'old' => "ADD KEY IF NOT EXISTS PassHash (PassHash)", - 'new' => "DROP KEY IF EXISTS PassHash", + 'old' => "ADD KEY /* IF NOT EXISTS */ PassHash (PassHash)", + 'new' => "DROP KEY /* IF EXISTS */ PassHash", ], [ 't' => 'users_notify_quoted', - 'old' => "DROP KEY IF EXISTS page_pageid_idx", - 'new' => "ADD KEY IF NOT EXISTS page_pageid_idx (Page,PageID)", + 'old' => "DROP KEY /* IF EXISTS */ page_pageid_idx", + 'new' => "ADD KEY /* IF NOT EXISTS */ page_pageid_idx (Page,PageID)", ], [ 't' => 'users_subscriptions', - 'old' => "DROP KEY IF EXISTS us_topicid_idx", - 'new' => "ADD KEY IF NOT EXISTS us_topicid_idx (TopicID)", + 'old' => "DROP KEY /* IF EXISTS */ us_topicid_idx", + 'new' => "ADD KEY /* IF NOT EXISTS */ us_topicid_idx (TopicID)", ], [ 't' => 'users_subscriptions_comments', - 'old' => "DROP KEY IF EXISTS usc_pageid_idx", - 'new' => "ADD KEY IF NOT EXISTS usc_pageid_idx (PageID)", + 'old' => "DROP KEY /* IF EXISTS */ usc_pageid_idx", + 'new' => "ADD KEY /* IF NOT EXISTS */ usc_pageid_idx (PageID)", ], [ 't' => 'wiki_aliases', - 'old' => "DROP KEY IF EXISTS article_idx", - 'new' => "ADD KEY IF NOT EXISTS article_idx (ArticleID)", + 'old' => "DROP KEY /* IF EXISTS */ article_idx", + 'new' => "ADD KEY /* IF NOT EXISTS */ article_idx (ArticleID)", ], [ 't' => 'xbt_files_history', - 'old' => "DROP KEY IF EXISTS xfh_uid_fid_idx", - 'new' => "ADD UNIQUE KEY IF NOT EXISTS xfh_uid_fid_idx (uid,fid)", + 'old' => "DROP KEY /* IF EXISTS */ xfh_uid_fid_idx", + 'new' => "ADD UNIQUE KEY /* IF NOT EXISTS */ xfh_uid_fid_idx (uid,fid)", ], [ 't' => 'xbt_files_users', @@ -466,13 +466,13 @@ class IndexRefactor extends AbstractMigration { ], [ 't' => 'xbt_files_users', - 'old' => "ADD KEY IF NOT EXISTS remaining_idx (remaining), ADD KEY IF NOT EXISTS uid_active (uid, active)", - 'new' => "DROP KEY IF EXISTS remaining_idx, DROP KEY IF EXISTS uid_active", + 'old' => "ADD KEY /* IF NOT EXISTS */ remaining_idx (remaining), ADD KEY /* IF NOT EXISTS */ uid_active (uid, active)", + 'new' => "DROP KEY /* IF EXISTS */ remaining_idx, DROP KEY /* IF EXISTS */ uid_active", ], [ 't' => 'xbt_files_users', - 'old' => "DROP KEY IF EXISTS uid_active_remain_mtime_idx, DROP KEY IF EXISTS remain_mtime_idx", - 'new' => "ADD KEY IF NOT EXISTS uid_active_remain_mtime_idx (uid, active, remaining, mtime), ADD KEY IF NOT EXISTS remain_mtime_idx (remaining, mtime)", + 'old' => "DROP KEY /* IF EXISTS */ uid_active_remain_mtime_idx, DROP KEY /* IF EXISTS */ remain_mtime_idx", + 'new' => "ADD KEY /* IF NOT EXISTS */ uid_active_remain_mtime_idx (uid, active, remaining, mtime), ADD KEY /* IF NOT EXISTS */ remain_mtime_idx (remaining, mtime)", ], [ 't' => 'contest', diff --git a/db/migrations/20200511211633_drop_unused_indexes.php b/db/migrations/20200511211633_drop_unused_indexes.php index b0b56c154..ab830cb19 100644 --- a/db/migrations/20200511211633_drop_unused_indexes.php +++ b/db/migrations/20200511211633_drop_unused_indexes.php @@ -23,101 +23,101 @@ class DropUnusedIndexes extends AbstractMigration { if (!getenv('LOCK_MY_DATABASE')) { die("Migration cannot proceed, use the source: " . __FILE__ . "\n"); } - $this->execute("ALTER TABLE comments_edits DROP KEY IF EXISTS EditUser"); - $this->execute("ALTER TABLE collages_artists DROP KEY IF EXISTS Sort"); - $this->execute("ALTER TABLE collages_torrents DROP KEY IF EXISTS Sort"); - $this->execute("ALTER TABLE donations DROP KEY IF EXISTS Amount"); - $this->execute("ALTER TABLE forums DROP KEY IF EXISTS MinClassRead, DROP KEY IF EXISTS Sort"); - $this->execute("ALTER TABLE forums_categories DROP KEY IF EXISTS Sort"); - $this->execute("ALTER TABLE forums_topics DROP KEY IF EXISTS Title"); - $this->execute("ALTER TABLE forums_topic_notes DROP KEY IF EXISTS AuthorID"); - $this->execute("ALTER TABLE friends DROP KEY IF EXISTS UserID"); - $this->execute("ALTER TABLE group_log DROP KEY IF EXISTS UserID"); - $this->execute("ALTER TABLE invite_tree DROP KEY IF EXISTS InviterID"); - $this->execute("ALTER TABLE ip_bans DROP KEY IF EXISTS ToIP"); - $this->execute("ALTER TABLE irc_channels DROP KEY IF EXISTS Name"); - $this->execute("ALTER TABLE login_attempts DROP KEY IF EXISTS UserID"); - $this->execute("ALTER TABLE news DROP KEY IF EXISTS UserID"); - $this->execute("ALTER TABLE pm_conversations_users DROP KEY IF EXISTS ForwardedTo, DROP KEY IF EXISTS InSentbox, DROP KEY IF EXISTS ReceivedDate, DROP KEY IF EXISTS SentDate, DROP KEY IF EXISTS Sticky"); - $this->execute("ALTER TABLE reports DROP KEY IF EXISTS ResolvedTime, DROP KEY IF EXISTS Type"); - $this->execute("ALTER TABLE requests DROP KEY IF EXISTS LastVote, DROP KEY IF EXISTS Name, DROP KEY IF EXISTS TimeFilled, DROP KEY IF EXISTS Year"); - $this->execute("ALTER TABLE sphinx_a DROP KEY IF EXISTS gid"); - $this->execute("ALTER TABLE sphinx_requests DROP KEY IF EXISTS Filled, DROP KEY IF EXISTS FillerID, DROP KEY IF EXISTS LastVote, DROP KEY IF EXISTS Name, DROP KEY IF EXISTS TimeAdded, DROP KEY IF EXISTS TimeFilled, DROP KEY IF EXISTS Userid, DROP KEY IF EXISTS Year"); - $this->execute("ALTER TABLE sphinx_requests_delta DROP KEY IF EXISTS Filled, DROP KEY IF EXISTS FillerID, DROP KEY IF EXISTS LastVote, DROP KEY IF EXISTS Name, DROP KEY IF EXISTS TimeFilled, DROP KEY IF EXISTS Year"); - $this->execute("ALTER TABLE sphinx_t DROP KEY IF EXISTS format"); - $this->execute("ALTER TABLE staff_blog DROP KEY IF EXISTS UserID"); - $this->execute("ALTER TABLE tags DROP KEY IF EXISTS UserID"); - $this->execute("ALTER TABLE torrents DROP KEY IF EXISTS FileCount, DROP KEY IF EXISTS Size, DROP KEY IF EXISTS Year"); - $this->execute("ALTER TABLE torrents_cassette_approved DROP KEY IF EXISTS TimeAdded"); - $this->execute("ALTER TABLE torrents_group DROP KEY IF EXISTS RevisionID, DROP KEY IF EXISTS Time"); - $this->execute("ALTER TABLE torrents_leech_stats DROP KEY IF EXISTS tls_leechers_idx"); - $this->execute("ALTER TABLE torrents_lossymaster_approved DROP KEY IF EXISTS TimeAdded"); - $this->execute("ALTER TABLE torrents_lossyweb_approved DROP KEY IF EXISTS TimeAdded"); - $this->execute("ALTER TABLE torrents_peerlists DROP KEY IF EXISTS GroupID"); - $this->execute("ALTER TABLE torrents_peerlists_compare DROP KEY IF EXISTS GroupID, DROP KEY IF EXISTS Stats"); - $this->execute("ALTER TABLE torrents_tags DROP KEY IF EXISTS PositiveVotes, DROP KEY IF EXISTS UserID"); - $this->execute("ALTER TABLE users_freeleeches DROP KEY IF EXISTS Time"); - $this->execute("ALTER TABLE users_info DROP KEY IF EXISTS AuthKey, DROP KEY IF EXISTS BitcoinAddress, DROP KEY IF EXISTS DisableInvites, DROP KEY IF EXISTS RatioWatchDownload"); - $this->execute("ALTER TABLE users_history_ips DROP KEY IF EXISTS StartTime"); - $this->execute("ALTER TABLE users_leech_stats DROP KEY IF EXISTS uls_uploaded_idx"); - $this->execute("ALTER TABLE users_main DROP KEY IF EXISTS Invites, DROP KEY IF EXISTS IP"); - $this->execute("ALTER TABLE users_notify_filters DROP KEY IF EXISTS ToYear"); - $this->execute("ALTER TABLE users_sessions DROP KEY IF EXISTS LastUpdate"); - $this->execute("ALTER TABLE users_torrent_history DROP KEY IF EXISTS Date, DROP KEY IF EXISTS Finished"); - $this->execute("ALTER TABLE users_votes DROP KEY IF EXISTS Time, DROP KEY IF EXISTS Type"); - $this->execute("ALTER TABLE wiki_artists DROP KEY IF EXISTS Time, DROP KEY IF EXISTS UserID"); - $this->execute("ALTER TABLE wiki_torrents DROP KEY IF EXISTS Time, DROP KEY IF EXISTS UserID"); - $this->execute("ALTER TABLE xbt_snatched DROP KEY IF EXISTS tstamp"); + $this->execute("ALTER TABLE comments_edits DROP KEY /* IF EXISTS */ EditUser"); + $this->execute("ALTER TABLE collages_artists DROP KEY /* IF EXISTS */ Sort"); + $this->execute("ALTER TABLE collages_torrents DROP KEY /* IF EXISTS */ Sort"); + $this->execute("ALTER TABLE donations DROP KEY /* IF EXISTS */ Amount"); + $this->execute("ALTER TABLE forums DROP KEY /* IF EXISTS */ MinClassRead, DROP KEY /* IF EXISTS */ Sort"); + $this->execute("ALTER TABLE forums_categories DROP KEY /* IF EXISTS */ Sort"); + $this->execute("ALTER TABLE forums_topics DROP KEY /* IF EXISTS */ Title"); + $this->execute("ALTER TABLE forums_topic_notes DROP KEY /* IF EXISTS */ AuthorID"); + $this->execute("ALTER TABLE friends DROP KEY /* IF EXISTS */ UserID"); + $this->execute("ALTER TABLE group_log DROP KEY /* IF EXISTS */ UserID"); + $this->execute("ALTER TABLE invite_tree DROP KEY /* IF EXISTS */ InviterID"); + $this->execute("ALTER TABLE ip_bans DROP KEY /* IF EXISTS */ ToIP"); + $this->execute("ALTER TABLE irc_channels DROP KEY /* IF EXISTS */ Name"); + $this->execute("ALTER TABLE login_attempts DROP KEY /* IF EXISTS */ UserID"); + $this->execute("ALTER TABLE news DROP KEY /* IF EXISTS */ UserID"); + $this->execute("ALTER TABLE pm_conversations_users DROP KEY /* IF EXISTS */ ForwardedTo, DROP KEY /* IF EXISTS */ InSentbox, DROP KEY /* IF EXISTS */ ReceivedDate, DROP KEY /* IF EXISTS */ SentDate, DROP KEY /* IF EXISTS */ Sticky"); + $this->execute("ALTER TABLE reports DROP KEY /* IF EXISTS */ ResolvedTime, DROP KEY /* IF EXISTS */ Type"); + $this->execute("ALTER TABLE requests DROP KEY /* IF EXISTS */ LastVote, DROP KEY /* IF EXISTS */ Name, DROP KEY /* IF EXISTS */ TimeFilled, DROP KEY /* IF EXISTS */ Year"); + $this->execute("ALTER TABLE sphinx_a DROP KEY /* IF EXISTS */ gid"); + $this->execute("ALTER TABLE sphinx_requests DROP KEY /* IF EXISTS */ Filled, DROP KEY /* IF EXISTS */ FillerID, DROP KEY /* IF EXISTS */ LastVote, DROP KEY /* IF EXISTS */ Name, DROP KEY /* IF EXISTS */ TimeAdded, DROP KEY /* IF EXISTS */ TimeFilled, DROP KEY /* IF EXISTS */ Userid, DROP KEY /* IF EXISTS */ Year"); + $this->execute("ALTER TABLE sphinx_requests_delta DROP KEY /* IF EXISTS */ Filled, DROP KEY /* IF EXISTS */ FillerID, DROP KEY /* IF EXISTS */ LastVote, DROP KEY /* IF EXISTS */ Name, DROP KEY /* IF EXISTS */ TimeFilled, DROP KEY /* IF EXISTS */ Year"); + $this->execute("ALTER TABLE sphinx_t DROP KEY /* IF EXISTS */ format"); + $this->execute("ALTER TABLE staff_blog DROP KEY /* IF EXISTS */ UserID"); + $this->execute("ALTER TABLE tags DROP KEY /* IF EXISTS */ UserID"); + $this->execute("ALTER TABLE torrents DROP KEY /* IF EXISTS */ FileCount, DROP KEY /* IF EXISTS */ Size, DROP KEY /* IF EXISTS */ Year"); + $this->execute("ALTER TABLE torrents_cassette_approved DROP KEY /* IF EXISTS */ TimeAdded"); + $this->execute("ALTER TABLE torrents_group DROP KEY /* IF EXISTS */ RevisionID, DROP KEY /* IF EXISTS */ Time"); + $this->execute("ALTER TABLE torrents_leech_stats DROP KEY /* IF EXISTS */ tls_leechers_idx"); + $this->execute("ALTER TABLE torrents_lossymaster_approved DROP KEY /* IF EXISTS */ TimeAdded"); + $this->execute("ALTER TABLE torrents_lossyweb_approved DROP KEY /* IF EXISTS */ TimeAdded"); + $this->execute("ALTER TABLE torrents_peerlists DROP KEY /* IF EXISTS */ GroupID"); + $this->execute("ALTER TABLE torrents_peerlists_compare DROP KEY /* IF EXISTS */ GroupID, DROP KEY /* IF EXISTS */ Stats"); + $this->execute("ALTER TABLE torrents_tags DROP KEY /* IF EXISTS */ PositiveVotes, DROP KEY /* IF EXISTS */ UserID"); + $this->execute("ALTER TABLE users_freeleeches DROP KEY /* IF EXISTS */ Time"); + $this->execute("ALTER TABLE users_info DROP KEY /* IF EXISTS */ AuthKey, DROP KEY /* IF EXISTS */ BitcoinAddress, DROP KEY /* IF EXISTS */ DisableInvites, DROP KEY /* IF EXISTS */ RatioWatchDownload"); + $this->execute("ALTER TABLE users_history_ips DROP KEY /* IF EXISTS */ StartTime"); + $this->execute("ALTER TABLE users_leech_stats DROP KEY /* IF EXISTS */ uls_uploaded_idx"); + $this->execute("ALTER TABLE users_main DROP KEY /* IF EXISTS */ Invites, DROP KEY /* IF EXISTS */ IP"); + $this->execute("ALTER TABLE users_notify_filters DROP KEY /* IF EXISTS */ ToYear"); + $this->execute("ALTER TABLE users_sessions DROP KEY /* IF EXISTS */ LastUpdate"); + $this->execute("ALTER TABLE users_torrent_history DROP KEY /* IF EXISTS */ Date, DROP KEY /* IF EXISTS */ Finished"); + $this->execute("ALTER TABLE users_votes DROP KEY /* IF EXISTS */ Time, DROP KEY /* IF EXISTS */ Type"); + $this->execute("ALTER TABLE wiki_artists DROP KEY /* IF EXISTS */ Time, DROP KEY /* IF EXISTS */ UserID"); + $this->execute("ALTER TABLE wiki_torrents DROP KEY /* IF EXISTS */ Time, DROP KEY /* IF EXISTS */ UserID"); + $this->execute("ALTER TABLE xbt_snatched DROP KEY /* IF EXISTS */ tstamp"); } public function down() { if (!getenv('LOCK_MY_DATABASE')) { die("Migration cannot proceed, use the source: " . __FILE__ . "\n"); } - $this->execute("ALTER TABLE comments_edits ADD KEY IF NOT EXISTS EditUser (EditUser)"); - $this->execute("ALTER TABLE collages_artists ADD KEY IF NOT EXISTS Sort (Sort)"); - $this->execute("ALTER TABLE collages_torrents ADD KEY IF NOT EXISTS Sort (Sort)"); - $this->execute("ALTER TABLE donations ADD KEY IF NOT EXISTS Amount (Amount)"); - $this->execute("ALTER TABLE forums ADD KEY IF NOT EXISTS MinClassRead (MinClassRead), ADD KEY IF NOT EXISTS Sort (Sort)"); - $this->execute("ALTER TABLE forums_categories ADD KEY IF NOT EXISTS Sort (Sort)"); - $this->execute("ALTER TABLE forums_topics ADD KEY IF NOT EXISTS Title (Title)"); - $this->execute("ALTER TABLE forums_topic_notes ADD KEY IF NOT EXISTS AuthorID (AuthorID)"); - $this->execute("ALTER TABLE friends ADD KEY IF NOT EXISTS UserID (UserID)"); - $this->execute("ALTER TABLE group_log ADD KEY IF NOT EXISTS UserID (UserID)"); - $this->execute("ALTER TABLE invite_tree ADD KEY IF NOT EXISTS InviterID (InviterID)"); - $this->execute("ALTER TABLE ip_bans ADD KEY IF NOT EXISTS ToIP (ToIP)"); - $this->execute("ALTER TABLE irc_channels ADD KEY IF NOT EXISTS Name (Name)"); - $this->execute("ALTER TABLE login_attempts ADD KEY IF NOT EXISTS UserID (UserID)"); - $this->execute("ALTER TABLE news ADD KEY IF NOT EXISTS UserID (UserID)"); - $this->execute("ALTER TABLE pm_conversations_users ADD KEY IF NOT EXISTS ForwardedTo (ForwardedTo), ADD KEY IF NOT EXISTS InSentbox (InSentbox), ADD KEY IF NOT EXISTS ReceivedDate (ReceivedDate), ADD KEY IF NOT EXISTS SentDate (SentDate), ADD KEY IF NOT EXISTS Sticky (Sticky)"); - $this->execute("ALTER TABLE reports ADD KEY IF NOT EXISTS ResolvedTime (ResolvedTime), ADD KEY IF NOT EXISTS Type (Type)"); - $this->execute("ALTER TABLE requests ADD KEY IF NOT EXISTS LastVote (LastVote), ADD KEY IF NOT EXISTS Name (Title), ADD KEY IF NOT EXISTS TimeFilled (TimeFilled), ADD KEY IF NOT EXISTS Year (Year)"); - $this->execute("ALTER TABLE sphinx_a ADD KEY IF NOT EXISTS gid (gid)"); - $this->execute("ALTER TABLE sphinx_requests ADD KEY IF NOT EXISTS Filled (TorrentID), ADD KEY IF NOT EXISTS FillerID (FillerID), ADD KEY IF NOT EXISTS LastVote (LastVote), ADD KEY IF NOT EXISTS Name (Title), ADD KEY IF NOT EXISTS TimeAdded (TimeAdded), ADD KEY IF NOT EXISTS TimeFilled (TimeFilled), ADD KEY IF NOT EXISTS Userid (Userid), ADD KEY IF NOT EXISTS Year (Year)"); - $this->execute("ALTER TABLE sphinx_requests_delta ADD KEY IF NOT EXISTS Filled (TorrentID), ADD KEY IF NOT EXISTS FillerID (FillerID), ADD KEY IF NOT EXISTS LastVote (LastVote), ADD KEY IF NOT EXISTS Name (Title), ADD KEY IF NOT EXISTS TimeFilled (TimeFilled), ADD KEY IF NOT EXISTS Year (Year)"); - $this->execute("ALTER TABLE sphinx_t ADD KEY IF NOT EXISTS format (format)"); - $this->execute("ALTER TABLE staff_blog ADD KEY IF NOT EXISTS UserID (UserID)"); - $this->execute("ALTER TABLE tags ADD KEY IF NOT EXISTS UserID (UserID)"); - $this->execute("ALTER TABLE torrents ADD KEY IF NOT EXISTS FileCount (FileCount), ADD KEY IF NOT EXISTS Size (Size), ADD KEY IF NOT EXISTS Year (RemasterYear)"); - $this->execute("ALTER TABLE torrents_cassette_approved ADD KEY IF NOT EXISTS TimeAdded (TimeAdded)"); - $this->execute("ALTER TABLE torrents_group ADD KEY IF NOT EXISTS RevisionID (RevisionID), ADD KEY IF NOT EXISTS Time (Time)"); - $this->execute("ALTER TABLE torrents_leech_stats ADD KEY IF NOT EXISTS tls_leechers_idx (Leechers)"); - $this->execute("ALTER TABLE torrents_lossymaster_approved ADD KEY IF NOT EXISTS TimeAdded (TimeAdded)"); - $this->execute("ALTER TABLE torrents_lossyweb_approved ADD KEY IF NOT EXISTS TimeAdded (TimeAdded)"); - $this->execute("ALTER TABLE torrents_peerlists ADD KEY IF NOT EXISTS GroupID (GroupID)"); - $this->execute("ALTER TABLE torrents_peerlists_compare ADD KEY IF NOT EXISTS GroupID (GroupID), ADD KEY IF NOT EXISTS Stats (TorrentID, Seeders, Leechers, Snatches)"); - $this->execute("ALTER TABLE torrents_tags ADD KEY IF NOT EXISTS PositiveVotes (PositiveVotes), ADD KEY IF NOT EXISTS UserID (UserID)"); - $this->execute("ALTER TABLE users_freeleeches ADD KEY IF NOT EXISTS Time (Time)"); - $this->execute("ALTER TABLE users_info ADD KEY IF NOT EXISTS AuthKey (AuthKey), ADD KEY IF NOT EXISTS BitcoinAddress (BitcoinAddress), ADD KEY IF NOT EXISTS DisableInvites (DisableInvites), ADD KEY IF NOT EXISTS RatioWatchDownload (RatioWatchDownload)"); - $this->execute("ALTER TABLE users_history_ips ADD KEY IF NOT EXISTS StartTime (StartTime)"); - $this->execute("ALTER TABLE users_leech_stats ADD KEY IF NOT EXISTS uls_uploaded_idx (Uploaded)"); - $this->execute("ALTER TABLE users_main ADD KEY IF NOT EXISTS Invites (Invites), ADD KEY IF NOT EXISTS IP (IP)"); - $this->execute("ALTER TABLE users_notify_filters ADD KEY IF NOT EXISTS ToYear (ToYear)"); - $this->execute("ALTER TABLE users_sessions ADD KEY IF NOT EXISTS LastUpdate (LastUpdate)"); - $this->execute("ALTER TABLE users_torrent_history ADD KEY IF NOT EXISTS Date (Date), ADD KEY IF NOT EXISTS Finished (Finished)"); - $this->execute("ALTER TABLE users_votes ADD KEY IF NOT EXISTS Time (Time), ADD KEY IF NOT EXISTS Type (Type)"); - $this->execute("ALTER TABLE wiki_artists ADD KEY IF NOT EXISTS Time (Time), ADD KEY IF NOT EXISTS UserID (UserID)"); - $this->execute("ALTER TABLE wiki_torrents ADD KEY IF NOT EXISTS Time (Time), ADD KEY IF NOT EXISTS UserID (UserID)"); - $this->execute("ALTER TABLE xbt_snatched ADD KEY IF NOT EXISTS tstamp (tstamp)"); + $this->execute("ALTER TABLE comments_edits ADD KEY /* IF NOT EXISTS */ EditUser (EditUser)"); + $this->execute("ALTER TABLE collages_artists ADD KEY /* IF NOT EXISTS */ Sort (Sort)"); + $this->execute("ALTER TABLE collages_torrents ADD KEY /* IF NOT EXISTS */ Sort (Sort)"); + $this->execute("ALTER TABLE donations ADD KEY /* IF NOT EXISTS */ Amount (Amount)"); + $this->execute("ALTER TABLE forums ADD KEY /* IF NOT EXISTS */ MinClassRead (MinClassRead), ADD KEY /* IF NOT EXISTS */ Sort (Sort)"); + $this->execute("ALTER TABLE forums_categories ADD KEY /* IF NOT EXISTS */ Sort (Sort)"); + $this->execute("ALTER TABLE forums_topics ADD KEY /* IF NOT EXISTS */ Title (Title)"); + $this->execute("ALTER TABLE forums_topic_notes ADD KEY /* IF NOT EXISTS */ AuthorID (AuthorID)"); + $this->execute("ALTER TABLE friends ADD KEY /* IF NOT EXISTS */ UserID (UserID)"); + $this->execute("ALTER TABLE group_log ADD KEY /* IF NOT EXISTS */ UserID (UserID)"); + $this->execute("ALTER TABLE invite_tree ADD KEY /* IF NOT EXISTS */ InviterID (InviterID)"); + $this->execute("ALTER TABLE ip_bans ADD KEY /* IF NOT EXISTS */ ToIP (ToIP)"); + $this->execute("ALTER TABLE irc_channels ADD KEY /* IF NOT EXISTS */ Name (Name)"); + $this->execute("ALTER TABLE login_attempts ADD KEY /* IF NOT EXISTS */ UserID (UserID)"); + $this->execute("ALTER TABLE news ADD KEY /* IF NOT EXISTS */ UserID (UserID)"); + $this->execute("ALTER TABLE pm_conversations_users ADD KEY /* IF NOT EXISTS */ ForwardedTo (ForwardedTo), ADD KEY /* IF NOT EXISTS */ InSentbox (InSentbox), ADD KEY /* IF NOT EXISTS */ ReceivedDate (ReceivedDate), ADD KEY /* IF NOT EXISTS */ SentDate (SentDate), ADD KEY /* IF NOT EXISTS */ Sticky (Sticky)"); + $this->execute("ALTER TABLE reports ADD KEY /* IF NOT EXISTS */ ResolvedTime (ResolvedTime), ADD KEY /* IF NOT EXISTS */ Type (Type)"); + $this->execute("ALTER TABLE requests ADD KEY /* IF NOT EXISTS */ LastVote (LastVote), ADD KEY /* IF NOT EXISTS */ Name (Title), ADD KEY /* IF NOT EXISTS */ TimeFilled (TimeFilled), ADD KEY /* IF NOT EXISTS */ Year (Year)"); + $this->execute("ALTER TABLE sphinx_a ADD KEY /* IF NOT EXISTS */ gid (gid)"); + $this->execute("ALTER TABLE sphinx_requests ADD KEY /* IF NOT EXISTS */ Filled (TorrentID), ADD KEY /* IF NOT EXISTS */ FillerID (FillerID), ADD KEY /* IF NOT EXISTS */ LastVote (LastVote), ADD KEY /* IF NOT EXISTS */ Name (Title), ADD KEY /* IF NOT EXISTS */ TimeAdded (TimeAdded), ADD KEY /* IF NOT EXISTS */ TimeFilled (TimeFilled), ADD KEY /* IF NOT EXISTS */ Userid (Userid), ADD KEY /* IF NOT EXISTS */ Year (Year)"); + $this->execute("ALTER TABLE sphinx_requests_delta ADD KEY /* IF NOT EXISTS */ Filled (TorrentID), ADD KEY /* IF NOT EXISTS */ FillerID (FillerID), ADD KEY /* IF NOT EXISTS */ LastVote (LastVote), ADD KEY /* IF NOT EXISTS */ Name (Title), ADD KEY /* IF NOT EXISTS */ TimeFilled (TimeFilled), ADD KEY /* IF NOT EXISTS */ Year (Year)"); + $this->execute("ALTER TABLE sphinx_t ADD KEY /* IF NOT EXISTS */ format (format)"); + $this->execute("ALTER TABLE staff_blog ADD KEY /* IF NOT EXISTS */ UserID (UserID)"); + $this->execute("ALTER TABLE tags ADD KEY /* IF NOT EXISTS */ UserID (UserID)"); + $this->execute("ALTER TABLE torrents ADD KEY /* IF NOT EXISTS */ FileCount (FileCount), ADD KEY /* IF NOT EXISTS */ Size (Size), ADD KEY /* IF NOT EXISTS */ Year (RemasterYear)"); + $this->execute("ALTER TABLE torrents_cassette_approved ADD KEY /* IF NOT EXISTS */ TimeAdded (TimeAdded)"); + $this->execute("ALTER TABLE torrents_group ADD KEY /* IF NOT EXISTS */ RevisionID (RevisionID), ADD KEY /* IF NOT EXISTS */ Time (Time)"); + $this->execute("ALTER TABLE torrents_leech_stats ADD KEY /* IF NOT EXISTS */ tls_leechers_idx (Leechers)"); + $this->execute("ALTER TABLE torrents_lossymaster_approved ADD KEY /* IF NOT EXISTS */ TimeAdded (TimeAdded)"); + $this->execute("ALTER TABLE torrents_lossyweb_approved ADD KEY /* IF NOT EXISTS */ TimeAdded (TimeAdded)"); + $this->execute("ALTER TABLE torrents_peerlists ADD KEY /* IF NOT EXISTS */ GroupID (GroupID)"); + $this->execute("ALTER TABLE torrents_peerlists_compare ADD KEY /* IF NOT EXISTS */ GroupID (GroupID), ADD KEY /* IF NOT EXISTS */ Stats (TorrentID, Seeders, Leechers, Snatches)"); + $this->execute("ALTER TABLE torrents_tags ADD KEY /* IF NOT EXISTS */ PositiveVotes (PositiveVotes), ADD KEY /* IF NOT EXISTS */ UserID (UserID)"); + $this->execute("ALTER TABLE users_freeleeches ADD KEY /* IF NOT EXISTS */ Time (Time)"); + $this->execute("ALTER TABLE users_info ADD KEY /* IF NOT EXISTS */ AuthKey (AuthKey), ADD KEY /* IF NOT EXISTS */ BitcoinAddress (BitcoinAddress), ADD KEY /* IF NOT EXISTS */ DisableInvites (DisableInvites), ADD KEY /* IF NOT EXISTS */ RatioWatchDownload (RatioWatchDownload)"); + $this->execute("ALTER TABLE users_history_ips ADD KEY /* IF NOT EXISTS */ StartTime (StartTime)"); + $this->execute("ALTER TABLE users_leech_stats ADD KEY /* IF NOT EXISTS */ uls_uploaded_idx (Uploaded)"); + $this->execute("ALTER TABLE users_main ADD KEY /* IF NOT EXISTS */ Invites (Invites), ADD KEY /* IF NOT EXISTS */ IP (IP)"); + $this->execute("ALTER TABLE users_notify_filters ADD KEY /* IF NOT EXISTS */ ToYear (ToYear)"); + $this->execute("ALTER TABLE users_sessions ADD KEY /* IF NOT EXISTS */ LastUpdate (LastUpdate)"); + $this->execute("ALTER TABLE users_torrent_history ADD KEY /* IF NOT EXISTS */ Date (Date), ADD KEY /* IF NOT EXISTS */ Finished (Finished)"); + $this->execute("ALTER TABLE users_votes ADD KEY /* IF NOT EXISTS */ Time (Time), ADD KEY /* IF NOT EXISTS */ Type (Type)"); + $this->execute("ALTER TABLE wiki_artists ADD KEY /* IF NOT EXISTS */ Time (Time), ADD KEY /* IF NOT EXISTS */ UserID (UserID)"); + $this->execute("ALTER TABLE wiki_torrents ADD KEY /* IF NOT EXISTS */ Time (Time), ADD KEY /* IF NOT EXISTS */ UserID (UserID)"); + $this->execute("ALTER TABLE xbt_snatched ADD KEY /* IF NOT EXISTS */ tstamp (tstamp)"); } } diff --git a/db/migrations/20200516165234_unicode_discogs_artists.php b/db/migrations/20200516165234_unicode_discogs_artists.php index 1bc3b87ec..45e65f56b 100644 --- a/db/migrations/20200516165234_unicode_discogs_artists.php +++ b/db/migrations/20200516165234_unicode_discogs_artists.php @@ -7,7 +7,7 @@ class UnicodeDiscogsArtists extends AbstractMigration { $this->execute("ALTER TABLE artist_discogs MODIFY `stem` varchar(100) CHARACTER SET utf8mb4 NOT NULL COLLATE utf8mb4_bin, MODIFY `name` varchar(100) CHARACTER SET utf8mb4 NOT NULL COLLATE utf8mb4_bin, - ADD KEY IF NOT EXISTS ad_stem_idx (stem) + ADD KEY /* IF NOT EXISTS */ ad_stem_idx (stem) "); } @@ -15,7 +15,7 @@ class UnicodeDiscogsArtists extends AbstractMigration { $this->execute("ALTER TABLE artist_discogs MODIFY `stem` varchar(100) CHARACTER SET utf8mb4 NOT NULL, MODIFY `name` varchar(100) CHARACTER SET utf8mb4 NOT NULL, - DROP KEY IF EXISTS ad_stem_idx + DROP KEY /* IF EXISTS */ ad_stem_idx "); } } diff --git a/db/migrations/20200523094019_drop_user_main_columns.php b/db/migrations/20200523094019_drop_user_main_columns.php index c6711c459..db868a059 100644 --- a/db/migrations/20200523094019_drop_user_main_columns.php +++ b/db/migrations/20200523094019_drop_user_main_columns.php @@ -18,8 +18,8 @@ class DropUserMainColumns extends AbstractMigration { public function down() { $this->execute(" ALTER TABLE users_main - ADD COLUMN LastLogin datetime NOT NULL DEFAULT '0000-00-00 00:00:00', - ADD COLUMN LastAccess datetime NOT NULL DEFAULT '0000-00-00 00:00:00', + ADD COLUMN LastLogin datetime NOT NULL DEFAULT NULL, + ADD COLUMN LastAccess datetime NOT NULL DEFAULT NULL, ADD COLUMN BonusPoints float(20,5) NOT NULL DEFAULT 0.00000, ADD COLUMN RequiredRatioWork double(12,8) NOT NULL DEFAULT 0.00000000, ADD COLUMN FLTokens int(10) NOT NULL DEFAULT 0, diff --git a/db/migrations/20200523171912_no_zerodate_users_info.php b/db/migrations/20200523171912_no_zerodate_users_info.php index e2e2e192d..4dd3b752c 100644 --- a/db/migrations/20200523171912_no_zerodate_users_info.php +++ b/db/migrations/20200523171912_no_zerodate_users_info.php @@ -11,20 +11,15 @@ class NoZerodateUsersInfo extends AbstractMigration { MODIFY RatioWatchEnds datetime DEFAULT NULL, MODIFY BanDate datetime DEFAULT NULL "); - $this->execute("UPDATE users_info SET Warned = NULL WHERE Warned = '0000-00-00 00:00:00'"); - $this->execute("UPDATE users_info SET ResetExpires = NULL WHERE ResetExpires = '0000-00-00 00:00:00'"); - $this->execute("UPDATE users_info SET JoinDate = now() WHERE JoinDate = '0000-00-00 00:00:00'"); - $this->execute("UPDATE users_info SET RatioWatchEnds = NULL WHERE RatioWatchEnds = '0000-00-00 00:00:00'"); - $this->execute("UPDATE users_info SET BanDate = NULL WHERE BanDate = '0000-00-00 00:00:00'"); } public function down() { $this->execute("ALTER TABLE users_info - MODIFY Warned timestamp NOT NULL DEFAULT '0000-00-00 00:00:00', - MODIFY ResetExpires datetime NOT NULL DEFAULT '0000-00-00 00:00:00', - MODIFY JoinDate datetime NOT NULL DEFAULT '0000-00-00 00:00:00', - MODIFY RatioWatchEnds datetime NOT NULL DEFAULT '0000-00-00 00:00:00', - MODIFY BanDate datetime NOT NULL DEFAULT '0000-00-00 00:00:00' + MODIFY Warned timestamp NOT NULL, + MODIFY ResetExpires datetime NOT NULL, + MODIFY JoinDate datetime NOT NULL, + MODIFY RatioWatchEnds datetime NOT NULL, + MODIFY BanDate datetime "); } } diff --git a/db/migrations/20200524174548_no_zerodate_blog.php b/db/migrations/20200524174548_no_zerodate_blog.php index 6c913ed65..6c84989a1 100644 --- a/db/migrations/20200524174548_no_zerodate_blog.php +++ b/db/migrations/20200524174548_no_zerodate_blog.php @@ -8,6 +8,6 @@ class NoZerodateBlog extends AbstractMigration { } public function down() { - $this->execute("ALTER TABLE blog MODIFY Time datetime NOT NULL DEFAULT '0000-00-00 00:00:00'"); + $this->execute("ALTER TABLE blog MODIFY Time datetime NOT NULL"); } } diff --git a/db/migrations/20200524180602_no_zerodate_changelog.php b/db/migrations/20200524180602_no_zerodate_changelog.php index 231270d1c..8a903396b 100644 --- a/db/migrations/20200524180602_no_zerodate_changelog.php +++ b/db/migrations/20200524180602_no_zerodate_changelog.php @@ -8,6 +8,6 @@ class NoZerodateChangelog extends AbstractMigration { } public function down() { - $this->execute("ALTER TABLE changelog MODIFY Time datetime NOT NULL DEFAULT '0000-00-00 00:00:00'"); + $this->execute("ALTER TABLE changelog MODIFY Time datetime NOT NULL"); } } diff --git a/db/migrations/20200524181025_no_zerodate_collages_artists.php b/db/migrations/20200524181025_no_zerodate_collages_artists.php index 306aadf3a..233facdc4 100644 --- a/db/migrations/20200524181025_no_zerodate_collages_artists.php +++ b/db/migrations/20200524181025_no_zerodate_collages_artists.php @@ -8,6 +8,6 @@ class NoZerodateCollagesArtists extends AbstractMigration { } public function down() { - $this->execute("ALTER TABLE collages_artists MODIFY AddedOn datetime NOT NULL DEFAULT '0000-00-00 00:00:00'"); + $this->execute("ALTER TABLE collages_artists MODIFY AddedOn datetime NOT NULL"); } } diff --git a/db/migrations/20200524193513_no_zerodate_comments.php b/db/migrations/20200524193513_no_zerodate_comments.php index 6f1d6148c..d957e0b4c 100644 --- a/db/migrations/20200524193513_no_zerodate_comments.php +++ b/db/migrations/20200524193513_no_zerodate_comments.php @@ -8,7 +8,7 @@ class NoZerodateComments extends AbstractMigration { } public function down() { - $this->execute("ALTER TABLE comments MODIFY AddedTime datetime NOT NULL DEFAULT '0000-00-00 00:00:00'"); + $this->execute("ALTER TABLE comments MODIFY AddedTime datetime NOT NULL"); } } diff --git a/db/migrations/20200524213738_no_zerodate_donotupload.php b/db/migrations/20200524213738_no_zerodate_donotupload.php index 58d51002e..693cb143b 100644 --- a/db/migrations/20200524213738_no_zerodate_donotupload.php +++ b/db/migrations/20200524213738_no_zerodate_donotupload.php @@ -8,6 +8,6 @@ class NoZerodateDonotupload extends AbstractMigration { } public function down() { - $this->execute("ALTER TABLE do_not_upload MODIFY Time datetime NOT NULL DEFAULT '0000-00-00 00:00:00'"); + $this->execute("ALTER TABLE do_not_upload MODIFY Time datetime NOT NULL"); } } diff --git a/db/migrations/20200527073712_no_zerodate_featured_albums.php b/db/migrations/20200527073712_no_zerodate_featured_albums.php index f7447a280..e43192199 100644 --- a/db/migrations/20200527073712_no_zerodate_featured_albums.php +++ b/db/migrations/20200527073712_no_zerodate_featured_albums.php @@ -8,13 +8,12 @@ class NoZerodateFeaturedAlbums extends AbstractMigration { MODIFY Started datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, MODIFY Ended datetime DEFAULT NULL "); - $this->execute("UPDATE featured_albums SET Ended = NULL WHERE Ended = '0000-00-00 00:00:00'"); } public function down() { $this->execute("ALTER TABLE featured_albums - MODIFY Started datetime NOT NULL DEFAULT '0000-00-00 00:00:00', - MODIFY Ended datetime NOT NULL DEFAULT '0000-00-00 00:00:00' + MODIFY Started datetime NOT NULL, + MODIFY Ended datetime NOT NULL "); } } diff --git a/db/migrations/20200527083228_no_zerodate_forums.php b/db/migrations/20200527083228_no_zerodate_forums.php index befa825d1..4b0aafe7a 100644 --- a/db/migrations/20200527083228_no_zerodate_forums.php +++ b/db/migrations/20200527083228_no_zerodate_forums.php @@ -7,12 +7,11 @@ class NoZerodateForums extends AbstractMigration { $this->execute("ALTER TABLE forums MODIFY LastPostTime datetime DEFAULT NULL "); - $this->execute("UPDATE forums SET LastPostTime = NULL WHERE LastPostTime = '0000-00-00 00:00:00'"); } public function down() { $this->execute("ALTER TABLE forums - MODIFY LastPostTime datetime NOT NULL DEFAULT '0000-00-00 00:00:00' + MODIFY LastPostTime datetime "); } } diff --git a/db/migrations/20200527084845_no_zerodate_forums_polls.php b/db/migrations/20200527084845_no_zerodate_forums_polls.php index aa8e2d8dd..927936a28 100644 --- a/db/migrations/20200527084845_no_zerodate_forums_polls.php +++ b/db/migrations/20200527084845_no_zerodate_forums_polls.php @@ -7,12 +7,11 @@ class NoZerodateForumsPolls extends AbstractMigration { $this->execute("ALTER TABLE forums_polls MODIFY Featured datetime DEFAULT NULL "); - $this->execute("UPDATE forums_polls SET Featured = NULL WHERE Featured = '0000-00-00 00:00:00'"); } public function down() { $this->execute("ALTER TABLE forums_polls - MODIFY Featured datetime NOT NULL DEFAULT '0000-00-00 00:00:00' + MODIFY Featured datetime NOT NULL "); } } diff --git a/db/migrations/20200527090654_no_zerodate_forums_posts.php b/db/migrations/20200527090654_no_zerodate_forums_posts.php index 6e7a04f40..7968014f5 100644 --- a/db/migrations/20200527090654_no_zerodate_forums_posts.php +++ b/db/migrations/20200527090654_no_zerodate_forums_posts.php @@ -11,7 +11,7 @@ class NoZerodateForumsPosts extends AbstractMigration { public function down() { $this->execute("ALTER TABLE forums_posts - MODIFY AddedTime datetime NOT NULL DEFAULT '0000-00-00 00:00:00' + MODIFY AddedTime datetime NOT NULL "); } } diff --git a/db/migrations/20200527155134_no_zerodate_forums_topics.php b/db/migrations/20200527155134_no_zerodate_forums_topics.php index 329417f21..94941e220 100644 --- a/db/migrations/20200527155134_no_zerodate_forums_topics.php +++ b/db/migrations/20200527155134_no_zerodate_forums_topics.php @@ -7,12 +7,11 @@ class NoZerodateForumsTopics extends AbstractMigration { $this->execute("ALTER TABLE forums_topics MODIFY LastPostTime datetime NOT NULL DEFAULT CURRENT_TIMESTAMP "); - $this->execute("UPDATE forums_topics SET LastPostTime = CreatedTime WHERE LastPostTime = '0000-00-00 00:00:00'"); } public function down() { $this->execute("ALTER TABLE forums_topics - MODIFY LastPostTime datetime NOT NULL DEFAULT '0000-00-00 00:00:00' + MODIFY LastPostTime datetime NOT NULL "); } } diff --git a/db/migrations/20200529071346_no_zerodate_reportsv2.php b/db/migrations/20200529071346_no_zerodate_reportsv2.php index 5d608574f..768a32202 100644 --- a/db/migrations/20200529071346_no_zerodate_reportsv2.php +++ b/db/migrations/20200529071346_no_zerodate_reportsv2.php @@ -8,13 +8,12 @@ class NoZerodateReportsv2 extends AbstractMigration { MODIFY ReportedTime datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, MODIFY LastChangeTime datetime NOT NULL DEFAULT CURRENT_TIMESTAMP "); - $this->execute("UPDATE reportsv2 SET LastChangeTime = ReportedTime WHERE LastChangeTime = '0000-00-00 00:00:00'"); } public function down() { $this->execute("ALTER TABLE reportsv2 - MODIFY ReportedTime datetime NOT NULL DEFAULT '0000-00-00 00:00:00', - MODIFY LastChangeTime datetime NOT NULL DEFAULT '0000-00-00 00:00:00' + MODIFY ReportedTime datetime, + MODIFY LastChangeTime datetim "); } } diff --git a/db/migrations/20200529180733_no_zerodate_group_log.php b/db/migrations/20200529180733_no_zerodate_group_log.php index 4607013da..eea8383bc 100644 --- a/db/migrations/20200529180733_no_zerodate_group_log.php +++ b/db/migrations/20200529180733_no_zerodate_group_log.php @@ -7,12 +7,11 @@ class NoZerodateGroupLog extends AbstractMigration { $this->execute("ALTER TABLE group_log MODIFY Time datetime NOT NULL DEFAULT CURRENT_TIMESTAMP "); - $this->execute("UPDATE group_log SET Time = now() WHERE Time = '0000-00-00 00:00:00'"); } public function down() { $this->execute("ALTER TABLE group_log - MODIFY Time datetime NOT NULL DEFAULT '0000-00-00 00:00:00' + MODIFY Time datetime "); } } diff --git a/db/migrations/20200530095934_no_zerodate_invites.php b/db/migrations/20200530095934_no_zerodate_invites.php index 4cfd2e70f..7db6ee5af 100644 --- a/db/migrations/20200530095934_no_zerodate_invites.php +++ b/db/migrations/20200530095934_no_zerodate_invites.php @@ -7,13 +7,11 @@ class NoZerodateInvites extends AbstractMigration { $this->execute("ALTER TABLE invites MODIFY Expires datetime NOT NULL DEFAULT CURRENT_TIMESTAMP "); - // unlikely, but whatever - $this->execute("UPDATE invites SET Expires = now() + INTERVAL 1 DAY WHERE Expires = '0000-00-00 00:00:00'"); } public function down() { $this->execute("ALTER TABLE invites - MODIFY Expires datetime NOT NULL DEFAULT '0000-00-00 00:00:00' + MODIFY Expires datetime "); } } diff --git a/db/migrations/20200530141341_no_zerodate_log.php b/db/migrations/20200530141341_no_zerodate_log.php index 906e2dbbb..b760bdbda 100644 --- a/db/migrations/20200530141341_no_zerodate_log.php +++ b/db/migrations/20200530141341_no_zerodate_log.php @@ -11,7 +11,7 @@ class NoZerodateLog extends AbstractMigration { public function down() { $this->execute("ALTER TABLE log - MODIFY Time datetime NOT NULL DEFAULT '0000-00-00 00:00:00' + MODIFY Time datetime "); } } diff --git a/db/migrations/20200530143312_no_zerodate_login_attempts.php b/db/migrations/20200530143312_no_zerodate_login_attempts.php index c751b7118..c287bf4d3 100644 --- a/db/migrations/20200530143312_no_zerodate_login_attempts.php +++ b/db/migrations/20200530143312_no_zerodate_login_attempts.php @@ -9,14 +9,12 @@ class NoZerodateLoginAttempts extends AbstractMigration { MODIFY BannedUntil datetime DEFAULT NULL, MODIFY Attempts int(10) unsigned NOT NULL DEFAULT 1 "); - $this->execute("UPDATE login_attempts SET LastAttempt = now() WHERE LastAttempt = '0000-00-00 00:00:00'"); - $this->execute("UPDATE login_attempts SET BannedUntil = NULL WHERE BannedUntil = '0000-00-00 00:00:00'"); } public function down() { $this->execute("ALTER TABLE login_attempts - MODIFY LastAttempt datetime NOT NULL DEFAULT '0000-00-00 00:00:00', - MODIFY BannedUntil datetime NOT NULL DEFAULT '0000-00-00 00:00:00', + MODIFY LastAttempt datetime, + MODIFY BannedUntil datetime, MODIFY Attempts int(10) unsigned NOT NULL "); } diff --git a/db/migrations/20200530194736_no_zerodate_news.php b/db/migrations/20200530194736_no_zerodate_news.php index 2124a3d4e..e0d239ff6 100644 --- a/db/migrations/20200530194736_no_zerodate_news.php +++ b/db/migrations/20200530194736_no_zerodate_news.php @@ -7,12 +7,11 @@ class NoZerodateNews extends AbstractMigration { $this->execute("ALTER TABLE news MODIFY Time datetime NOT NULL DEFAULT CURRENT_TIMESTAMP "); - $this->execute("UPDATE news SET Time = now() WHERE Time = '0000-00-00 00:00:00'"); } public function down() { $this->execute("ALTER TABLE news - MODIFY Time datetime NOT NULL DEFAULT '0000-00-00 00:00:00' + MODIFY Time datetime "); } } diff --git a/db/migrations/20200530220245_no_zerodate_pm_conversations_users.php b/db/migrations/20200530220245_no_zerodate_pm_conversations_users.php index b7475be6d..949206d3e 100644 --- a/db/migrations/20200530220245_no_zerodate_pm_conversations_users.php +++ b/db/migrations/20200530220245_no_zerodate_pm_conversations_users.php @@ -9,13 +9,12 @@ class NoZerodatePmConversationsUsers extends AbstractMigration { MODIFY SentDate datetime NOT NULL DEFAULT CURRENT_TIMESTAMP "); // not sure how this could have happened - $this->execute("UPDATE pm_conversations_users SET SentDate = ReceivedDate WHERE SentDate = '0000-00-00 00:00:00'"); } public function down() { $this->execute("ALTER TABLE pm_conversations_users - MODIFY ReceivedDate datetime NOT NULL DEFAULT '0000-00-00 00:00:00', - MODIFY SentDate datetime NOT NULL DEFAULT '0000-00-00 00:00:00' + MODIFY ReceivedDate datetime, + MODIFY SentDate datetime "); } } diff --git a/db/migrations/20200531170129_no_zerodate_pm_messages.php b/db/migrations/20200531170129_no_zerodate_pm_messages.php index b37ef7aab..40194f03c 100644 --- a/db/migrations/20200531170129_no_zerodate_pm_messages.php +++ b/db/migrations/20200531170129_no_zerodate_pm_messages.php @@ -11,7 +11,7 @@ class NoZerodatePmMessages extends AbstractMigration { public function down() { $this->execute("ALTER TABLE pm_messages - MODIFY SentDate datetime NOT NULL DEFAULT '0000-00-00 00:00:00' + MODIFY SentDate datetime "); } } diff --git a/db/migrations/20200531171102_no_zerodate_reports.php b/db/migrations/20200531171102_no_zerodate_reports.php index 170284406..9fd5d0fd5 100644 --- a/db/migrations/20200531171102_no_zerodate_reports.php +++ b/db/migrations/20200531171102_no_zerodate_reports.php @@ -8,13 +8,12 @@ class NoZerodateReports extends AbstractMigration { MODIFY ReportedTime datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, MODIFY ResolvedTime datetime DEFAULT NULL "); - $this->execute("UPDATE reports SET ResolvedTime = NULL WHERE ResolvedTime = '0000-00-00 00:00:00'"); } public function down() { $this->execute("ALTER TABLE reports - MODIFY ReportedTime datetime NOT NULL DEFAULT '0000-00-00 00:00:00' - MODIFY ResolvedTime datetime NOT NULL DEFAULT '0000-00-00 00:00:00' + MODIFY ReportedTime datetime + MODIFY ResolvedTime datetime "); } } diff --git a/db/migrations/20200531172951_no_zerodate_staff_blog.php b/db/migrations/20200531172951_no_zerodate_staff_blog.php index 5a9eddc00..1046d1fe3 100644 --- a/db/migrations/20200531172951_no_zerodate_staff_blog.php +++ b/db/migrations/20200531172951_no_zerodate_staff_blog.php @@ -7,19 +7,17 @@ class NoZerodateStaffBlog extends AbstractMigration { $this->execute("ALTER TABLE staff_blog MODIFY Time datetime NOT NULL DEFAULT CURRENT_TIMESTAMP "); - $this->execute("UPDATE staff_blog SET Time = now() WHERE Time = '0000-00-00 00:00:00'"); $this->execute("ALTER TABLE staff_blog_visits MODIFY Time datetime NOT NULL DEFAULT CURRENT_TIMESTAMP "); - $this->execute("UPDATE staff_blog_visits SET Time = now() WHERE Time = '0000-00-00 00:00:00'"); } public function down() { $this->execute("ALTER TABLE staff_blog - MODIFY Time datetime NOT NULL DEFAULT '0000-00-00 00:00:00' + MODIFY Time datetime "); $this->execute("ALTER TABLE staff_blog_visits - MODIFY Time datetime NOT NULL DEFAULT '0000-00-00 00:00:00' + MODIFY Time datetime "); } } diff --git a/db/migrations/20200531174053_no_zerodate_torrent_flag.php b/db/migrations/20200531174053_no_zerodate_torrent_flag.php index 6ccfae0bf..137078895 100644 --- a/db/migrations/20200531174053_no_zerodate_torrent_flag.php +++ b/db/migrations/20200531174053_no_zerodate_torrent_flag.php @@ -13,7 +13,6 @@ class NoZerodateTorrentFlag extends AbstractMigration { $this->execute("ALTER TABLE $table MODIFY TimeAdded datetime NOT NULL DEFAULT CURRENT_TIMESTAMP "); - $this->execute("UPDATE $table SET TimeAdded = now() WHERE TimeAdded = '0000-00-00 00:00:00'"); } } @@ -21,7 +20,7 @@ class NoZerodateTorrentFlag extends AbstractMigration { foreach ($this->torrentTables() as $table) { echo "=> $table\n"; $this->execute("ALTER TABLE $table - MODIFY TimeAdded datetime NOT NULL DEFAULT '0000-00-00 00:00:00' + MODIFY TimeAdded datetime "); } } diff --git a/db/migrations/20200531192647_no_zerodate_users_history_ips.php b/db/migrations/20200531192647_no_zerodate_users_history_ips.php index 709246bb0..ba1b4349f 100644 --- a/db/migrations/20200531192647_no_zerodate_users_history_ips.php +++ b/db/migrations/20200531192647_no_zerodate_users_history_ips.php @@ -7,12 +7,11 @@ class NoZerodateUsersHistoryIps extends AbstractMigration { $this->execute("ALTER TABLE users_history_ips MODIFY StartTime datetime NOT NULL DEFAULT CURRENT_TIMESTAMP "); - $this->execute("UPDATE users_history_ips SET StartTime = now() WHERE StartTime = '0000-00-00 00:00:00'"); } public function down() { $this->execute("ALTER TABLE users_history_ips - MODIFY StartTime datetime NOT NULL DEFAULT '0000-00-00 00:00:00' + MODIFY StartTime datetime NOT NULL "); } } diff --git a/db/migrations/20200601124602_no_zerodate_torrents_group.php b/db/migrations/20200601124602_no_zerodate_torrents_group.php index d834af4ca..6cc83aac0 100644 --- a/db/migrations/20200601124602_no_zerodate_torrents_group.php +++ b/db/migrations/20200601124602_no_zerodate_torrents_group.php @@ -11,7 +11,7 @@ class NoZerodateTorrentsGroup extends AbstractMigration { public function down() { $this->execute("ALTER TABLE torrents_group - MODIFY Time datetime NOT NULL DEFAULT '0000-00-00 00:00:00' + MODIFY Time datetime "); } } diff --git a/db/migrations/20200601141946_no_zerodate_users_notify_quoted.php b/db/migrations/20200601141946_no_zerodate_users_notify_quoted.php index 8c72e04ef..dbd690670 100644 --- a/db/migrations/20200601141946_no_zerodate_users_notify_quoted.php +++ b/db/migrations/20200601141946_no_zerodate_users_notify_quoted.php @@ -11,7 +11,7 @@ class NoZerodateUsersNotifyQuoted extends AbstractMigration { public function down() { $this->execute("ALTER TABLE users_notify_quoted - MODIFY Date datetime NOT NULL DEFAULT '0000-00-00 00:00:00' + MODIFY Date datetime "); } } diff --git a/db/migrations/20200601164248_no_zerodate_users_top10_history.php b/db/migrations/20200601164248_no_zerodate_users_top10_history.php index c3a3a3171..a8a051900 100644 --- a/db/migrations/20200601164248_no_zerodate_users_top10_history.php +++ b/db/migrations/20200601164248_no_zerodate_users_top10_history.php @@ -11,7 +11,7 @@ class NoZerodateUsersTop10History extends AbstractMigration { public function down() { $this->execute("ALTER TABLE top10_history - MODIFY Date datetime NOT NULL DEFAULT '0000-00-00 00:00:00' + MODIFY Date datetime "); } } diff --git a/db/migrations/20200601164854_no_zerodate_wiki.php b/db/migrations/20200601164854_no_zerodate_wiki.php index 9e5ecee09..b2503fc0c 100644 --- a/db/migrations/20200601164854_no_zerodate_wiki.php +++ b/db/migrations/20200601164854_no_zerodate_wiki.php @@ -14,10 +14,10 @@ class NoZerodateWiki extends AbstractMigration { public function down() { $this->execute("ALTER TABLE wiki_artists - MODIFY Time datetime NOT NULL DEFAULT '0000-00-00 00:00:00' + MODIFY Time datetime "); $this->execute("ALTER TABLE wiki_torrents - MODIFY Time datetime NOT NULL DEFAULT '0000-00-00 00:00:00' + MODIFY Time datetime "); } } diff --git a/db/migrations/20200617210347_nuke_recommendations.php b/db/migrations/20200617210347_nuke_recommendations.php index b0413945e..f75a03f80 100644 --- a/db/migrations/20200617210347_nuke_recommendations.php +++ b/db/migrations/20200617210347_nuke_recommendations.php @@ -29,8 +29,7 @@ class NukeRecommendations extends AbstractMigration { 'limit' => '10', ]) ->addColumn('Time', 'datetime', [ - 'null' => false, - 'default' => '0000-00-00 00:00:00', + 'null' => true, ]) ->addIndex(['Time'], [ 'name' => 'Time', diff --git a/db/migrations/20200814203732_null_date_columns.php b/db/migrations/20200814203732_null_date_columns.php index 05df61e9a..a3c37b5f8 100644 --- a/db/migrations/20200814203732_null_date_columns.php +++ b/db/migrations/20200814203732_null_date_columns.php @@ -11,9 +11,9 @@ class NullDateColumns extends AbstractMigration { } public function down() { - $this->execute("ALTER TABLE deleted_torrents MODIFY LastReseedRequest datetime NOT NULL DEFAULT '0000-00-00 00:00:00'"); + $this->execute("ALTER TABLE deleted_torrents MODIFY LastReseedRequest datetime"); $this->execute("ALTER TABLE torrents_bad_folders MODIFY TimeAdded datetime NOT NULL"); $this->execute("ALTER TABLE forums_topic_notes MODIFY AddedTime datetime NOT NULL"); - $this->execute("ALTER TABLE referral_users MODIFY Joined timestamp NOT NULL DEFAULT '0000-00-00 00:00:00'"); + $this->execute("ALTER TABLE referral_users MODIFY Joined timestamp"); } } diff --git a/db/migrations/20200820194937_email_history_date.php b/db/migrations/20200820194937_email_history_date.php index 50cbe9456..f0394cdf8 100644 --- a/db/migrations/20200820194937_email_history_date.php +++ b/db/migrations/20200820194937_email_history_date.php @@ -9,7 +9,7 @@ class EmailHistoryDate extends AbstractMigration { INNER JOIN users_info ui USING (UserID) SET uhm.Time = ui.JoinDate - WHERE (uhm.Time = '0000-00-00 00:00:00' OR uhm.Time IS NULL) + WHERE uhm.Time IS NULL "); $this->execute("ALTER TABLE users_history_emails MODIFY Time datetime NOT NULL DEFAULT CURRENT_TIMESTAMP"); } diff --git a/db/migrations/20200912152611_xfu_by_uid.php b/db/migrations/20200912152611_xfu_by_uid.php index f96a766e4..bbcb5e2b1 100644 --- a/db/migrations/20200912152611_xfu_by_uid.php +++ b/db/migrations/20200912152611_xfu_by_uid.php @@ -15,13 +15,13 @@ class XfuByUid extends AbstractMigration { die("Migration cannot proceed, use the source: " . __FILE__ . "\n"); } $this->execute("ALTER TABLE xbt_files_users - ADD KEY IF NOT EXISTS xfu_uid_idx (uid) + ADD KEY /* IF NOT EXISTS */ xfu_uid_idx (uid) "); } public function down() { $this->execute("ALTER TABLE xbt_files_users - DROP KEY IF EXISTS xfu_uid_idx + DROP KEY /* IF EXISTS */ xfu_uid_idx "); } } diff --git a/db/migrations/20200921164238_contest_class_ref.php b/db/migrations/20200921164238_contest_class_ref.php index 01b7afbd1..de227220c 100644 --- a/db/migrations/20200921164238_contest_class_ref.php +++ b/db/migrations/20200921164238_contest_class_ref.php @@ -5,12 +5,12 @@ use Phinx\Migration\AbstractMigration; class ContestClassRef extends AbstractMigration { public function up() { $this->execute(" - ALTER TABLE bonus_pool_contrib DROP FOREIGN KEY IF EXISTS bonus_pool_contrib_ibfk_1; - ALTER TABLE bonus_pool_contrib DROP FOREIGN KEY IF EXISTS bonus_pool_contrib_ibfk_2; + ALTER TABLE bonus_pool_contrib DROP FOREIGN KEY /* IF EXISTS */ bonus_pool_contrib_ibfk_1; + ALTER TABLE bonus_pool_contrib DROP FOREIGN KEY /* IF EXISTS */ bonus_pool_contrib_ibfk_2; "); $this->execute(" - ALTER TABLE contest_has_bonus_pool DROP FOREIGN KEY IF EXISTS contest_has_bonus_pool_ibfk_1; - ALTER TABLE contest_has_bonus_pool DROP FOREIGN KEY IF EXISTS contest_has_bonus_pool_ibfk_2; + ALTER TABLE contest_has_bonus_pool DROP FOREIGN KEY /* IF EXISTS */ contest_has_bonus_pool_ibfk_1; + ALTER TABLE contest_has_bonus_pool DROP FOREIGN KEY /* IF EXISTS */ contest_has_bonus_pool_ibfk_2; "); $this->execute(" ALTER TABLE bonus_pool @@ -44,9 +44,8 @@ class ContestClassRef extends AbstractMigration { ADD CONSTRAINT bonus_pool_contrib_ibfk_2 FOREIGN KEY (user_id) REFERENCES users_main (ID) "); $this->execute(" - ALTER TABLE contest DROP FOREIGN KEY IF EXISTS contest_type_fk; - ALTER TABLE contest_leaderboard DROP FOREIGN KEY IF EXISTS contest_fk; - ALTER TABLE contest_leaderboard DROP FOREIGN KEY IF EXISTS contest_leaderboard_fk; + ALTER TABLE contest DROP FOREIGN KEY /* IF EXISTS */ contest_type_fk; + ALTER TABLE contest_leaderboard DROP FOREIGN KEY /* IF EXISTS */ contest_leaderboard_fk; "); $this->execute(" ALTER TABLE contest_leaderboard @@ -92,12 +91,12 @@ class ContestClassRef extends AbstractMigration { public function down() { $this->execute(" - ALTER TABLE bonus_pool_contrib DROP FOREIGN KEY IF EXISTS bonus_pool_contrib_ibfk_1; - ALTER TABLE bonus_pool_contrib DROP FOREIGN KEY IF EXISTS bonus_pool_contrib_ibfk_2; + ALTER TABLE bonus_pool_contrib DROP FOREIGN KEY /* IF EXISTS */ bonus_pool_contrib_ibfk_1; + ALTER TABLE bonus_pool_contrib DROP FOREIGN KEY /* IF EXISTS */ bonus_pool_contrib_ibfk_2; "); $this->execute(" - ALTER TABLE contest_has_bonus_pool DROP FOREIGN KEY IF EXISTS contest_has_bonus_pool_ibfk_1; - ALTER TABLE contest_has_bonus_pool DROP FOREIGN KEY IF EXISTS contest_has_bonus_pool_ibfk_2; + ALTER TABLE contest_has_bonus_pool DROP FOREIGN KEY /* IF EXISTS */ contest_has_bonus_pool_ibfk_1; + ALTER TABLE contest_has_bonus_pool DROP FOREIGN KEY /* IF EXISTS */ contest_has_bonus_pool_ibfk_2; "); $this->execute(" ALTER TABLE bonus_pool @@ -134,8 +133,8 @@ class ContestClassRef extends AbstractMigration { ALTER TABLE contest_has_bonus_pool ADD CONSTRAINT contest_has_bonus_pool_ibfk_1 FOREIGN KEY (BonusPoolID) REFERENCES bonus_pool (ID); "); $this->execute(" - ALTER TABLE contest DROP FOREIGN KEY IF EXISTS contest_type_fk; - ALTER TABLE contest_leaderboard DROP FOREIGN KEY IF EXISTS contest_leaderboard_fk; + ALTER TABLE contest DROP FOREIGN KEY /* IF EXISTS */ contest_type_fk; + ALTER TABLE contest_leaderboard DROP FOREIGN KEY /* IF EXISTS */ contest_leaderboard_fk; "); $this->execute(" ALTER TABLE contest_leaderboard diff --git a/db/migrations/20201013211254_api_token.php b/db/migrations/20201013211254_api_token.php index 20c17dd57..99f569a49 100644 --- a/db/migrations/20201013211254_api_token.php +++ b/db/migrations/20201013211254_api_token.php @@ -12,7 +12,7 @@ class ApiToken extends AbstractMigration ->addColumn('user_id', 'integer', ['limit' => 10, 'signed' => false]) ->addColumn('name', 'string', ['limit' => 40]) ->addColumn('token', 'string', ['limit' => 255]) - ->addColumn('scope', 'text', ['default' => '']) + ->addColumn('scope', 'text') ->addColumn('created', 'datetime', ['default' => 'CURRENT_TIMESTAMP']) ->addColumn('revoked', 'integer', ['default' => 0, 'limit' => MysqlAdapter::INT_TINY]) ->addIndex(['user_id'], ['unique' => false]) diff --git a/db/migrations/20210116174853_index_xbt_files_users.php b/db/migrations/20210116174853_index_xbt_files_users.php index 48c8bf946..c0f335d1a 100644 --- a/db/migrations/20210116174853_index_xbt_files_users.php +++ b/db/migrations/20210116174853_index_xbt_files_users.php @@ -18,8 +18,8 @@ final class IndexXbtFilesUsers extends AbstractMigration } $this->execute(" ALTER TABLE xbt_files_users - DROP KEY IF EXISTS xfu_uid_idx, - DROP KEY IF EXISTS fid_idx, + DROP KEY /* IF EXISTS */ xfu_uid_idx, + DROP KEY /* IF EXISTS */ fid_idx, DROP PRIMARY KEY, ADD PRIMARY KEY (fid, uid, peer_id) "); diff --git a/db/migrations/20210119182816_user_downloads_drop_unused.php b/db/migrations/20210119182816_user_downloads_drop_unused.php index 4241f43fb..5ade154f4 100644 --- a/db/migrations/20210119182816_user_downloads_drop_unused.php +++ b/db/migrations/20210119182816_user_downloads_drop_unused.php @@ -17,7 +17,7 @@ final class UserDownloadsDropUnused extends AbstractMigration die("Migration cannot proceed, use the source: " . __FILE__ . "\n"); } $this->execute(" - ALTER TABLE users_downloads DROP KEY IF EXISTS UserID + ALTER TABLE users_downloads DROP KEY /* IF EXISTS */ UserID "); } @@ -26,7 +26,7 @@ final class UserDownloadsDropUnused extends AbstractMigration die("Migration cannot proceed, use the source: " . __FILE__ . "\n"); } $this->execute(" - ALTER TABLE users_downloads ADD KEY IF NOT EXISTS UserID (UserID) + ALTER TABLE users_downloads ADD KEY /* IF NOT EXISTS */ UserID (UserID) "); } } diff --git a/db/migrations/20210121165826_reindex_users_comments.php b/db/migrations/20210121165826_reindex_users_comments.php index 341b060ca..9ef9fe03f 100644 --- a/db/migrations/20210121165826_reindex_users_comments.php +++ b/db/migrations/20210121165826_reindex_users_comments.php @@ -19,7 +19,7 @@ final class ReindexUsersComments extends AbstractMigration $this->execute(" ALTER TABLE users_comments_last_read DROP PRIMARY KEY, - DROP KEY IF EXISTS Page, + DROP KEY /* IF EXISTS */ Page, ADD PRIMARY KEY (Page, PageID, UserID), ADD KEY uclr_user_idx (UserID) "); @@ -32,7 +32,7 @@ final class ReindexUsersComments extends AbstractMigration $this->execute(" ALTER TABLE users_comments_last_read DROP PRIMARY KEY, - DROP KEY IF EXISTS uclr_user_idx, + DROP KEY /* IF EXISTS */ uclr_user_idx, ADD PRIMARY KEY (UserID, Page, PageID), ADD KEY Page (Page, PageID) "); diff --git a/db/migrations/20211029082456_post_edit_time.php b/db/migrations/20211029082456_post_edit_time.php index d105539d1..7435ac436 100644 --- a/db/migrations/20211029082456_post_edit_time.php +++ b/db/migrations/20211029082456_post_edit_time.php @@ -6,8 +6,6 @@ use Phinx\Migration\AbstractMigration; final class PostEditTime extends AbstractMigration { public function up(): void { - $this->execute("UPDATE comments_edits SET EditTime = now() WHERE EditTime IS NULL OR EditTime = '0000-00-00 00:00:00'"); - $this->table('comments_edits') ->changeColumn('EditTime', 'datetime', ['default' => 'CURRENT_TIMESTAMP']) ->save(); diff --git a/db/migrations/20211206083341_deleted_torrent_group.php b/db/migrations/20211206083341_deleted_torrent_group.php index 9eaf1e124..2a1e6a75a 100644 --- a/db/migrations/20211206083341_deleted_torrent_group.php +++ b/db/migrations/20211206083341_deleted_torrent_group.php @@ -20,7 +20,7 @@ final class DeletedTorrentGroup extends AbstractMigration ->addColumn('TagList', 'string', ['length' => 500, 'default' => '']) ->addColumn('Time', 'datetime', ['default' => 'CURRENT_TIMESTAMP']) ->addColumn('RevisionID', 'integer', ['length' => 12, 'null' => true]) - ->addColumn('WikiBody', 'string', ['limit' => MysqlAdapter::TEXT_MEDIUM]) + ->addColumn('WikiBody', 'text', ['limit' => MysqlAdapter::TEXT_MEDIUM]) ->addColumn('WikiImage', 'string', ['length' => 255]) ->addColumn('VanityHouse', 'integer', ['length' => 1, 'default' => 0, 'limit' => MysqlAdapter::INT_TINY]) ->save(); diff --git a/db/migrations/20211231215237_error_log_vars.php b/db/migrations/20211231215237_error_log_vars.php index e8a9a1c31..40d0a7eaa 100644 --- a/db/migrations/20211231215237_error_log_vars.php +++ b/db/migrations/20211231215237_error_log_vars.php @@ -8,11 +8,11 @@ final class ErrorLogVars extends AbstractMigration public function up(): void { $this->table('error_log') - ->addColumn('logged_var', 'json', ['null' => true, 'default' => '[]']) + ->addColumn('logged_var', 'json', ['null' => true]) ->save(); $this->query("UPDATE error_log SET logged_var = '[]'"); $this->table('error_log') - ->changeColumn('logged_var', 'json', ['null' => false, 'default' => '[]']) + ->changeColumn('logged_var', 'json', ['null' => false]) ->save(); } diff --git a/db/migrations/20220208091300_mysql_utf_8mb_4.php b/db/migrations/20220208091300_mysql_utf_8mb_4.php index ffcaf9c96..49ded8edd 100644 --- a/db/migrations/20220208091300_mysql_utf_8mb_4.php +++ b/db/migrations/20220208091300_mysql_utf_8mb_4.php @@ -26,14 +26,14 @@ final class MysqlUtf8mb4 extends AbstractMigration invites ip_bans irc_channels label_aliases lastfm_users log login_attempts nav_items news payment_reminders periodic_task periodic_task_history periodic_task_history_event permissions phinxlog - pm_conversations_users push_notifications_usage recovery recovery_buffer + pm_conversations_users push_notifications_usage recovery_buffer referral_accounts referral_users release_type reports reportsv2 requests requests_artists site_options sphinx_a sphinx_delta sphinx_index_last_pos sphinx_requests sphinx_requests_delta sphinx_t sphinx_tg staff_blog staff_groups staff_pm_conversations stylesheets tag_aliases tags thread_note thread_type top10_history top10_history_torrents torrent_attr torrent_group_attr torrents - torrents_artists torrents_logs torrents_tags_votes user user_attr + torrents_artists torrents_logs torrents_tags_votes user_attr user_seedbox users_comments_last_read users_enable_requests users_geodistribution users_history_emails users_history_ips users_history_passkeys users_history_passwords users_info users_main diff --git a/db/seeds/InitialUserSeeder.php b/db/seeds/AaaInitialUserSeeder.php similarity index 89% rename from db/seeds/InitialUserSeeder.php rename to db/seeds/AaaInitialUserSeeder.php index 0294e94ca..b04e1c6b7 100644 --- a/db/seeds/InitialUserSeeder.php +++ b/db/seeds/AaaInitialUserSeeder.php @@ -5,7 +5,7 @@ use Phinx\Util\Literal; require_once(__DIR__ . '/../../lib/util.php'); // for randomString() -class InitialUserSeeder extends AbstractSeed { +class AaaInitialUserSeeder extends AbstractSeed { public function run() { /** @var \PDOStatement $stmt */ $stmt = $this->getAdapter()->getConnection()->prepare(" @@ -25,6 +25,7 @@ class InitialUserSeeder extends AbstractSeed { 'Username' => 'admin', 'Email' => 'admin@example.com', 'PassHash' => password_hash(hash('sha256','password'), PASSWORD_DEFAULT), + 'Secret' => randomString(32), 'torrent_pass' => randomString(32), 'PermissionID' => SYSOP, 'Invites' => STARTING_INVITES, @@ -36,6 +37,7 @@ class InitialUserSeeder extends AbstractSeed { 'Username' => 'user', 'Email' => 'user@example.com', 'PassHash' => password_hash(hash('sha256','password'), PASSWORD_DEFAULT), + 'Secret' => randomString(32), 'torrent_pass' => randomString(32), 'PermissionID' => USER, 'Invites' => STARTING_INVITES, @@ -53,11 +55,9 @@ class InitialUserSeeder extends AbstractSeed { $this->table('user_last_access')->insert([ [ 'user_id' => $adminId, - 'last_access' => Literal::from('now()'), ], [ 'user_id' => $userId, - 'last_access' => Literal::from('now()'), ], ])->saveData(); @@ -80,6 +80,9 @@ class InitialUserSeeder extends AbstractSeed { 'ShowTags' => 1, 'AuthKey' => '7d3b4750ea71502d25051875a250b71a', 'Inviter' => 0, + 'Info' => 'Created by installation script', + 'AdminComment' => '', + 'SiteOptions' => serialize([]), ], [ 'UserID' => $userId, @@ -88,6 +91,9 @@ class InitialUserSeeder extends AbstractSeed { 'ShowTags' => 1, 'AuthKey' => 'a1189fa8554776c6de31b6b4e2d0faea', 'Inviter' => 0, + 'Info' => 'Created by installation script', + 'AdminComment' => '', + 'SiteOptions' => serialize([]), ] ])->saveData(); @@ -95,14 +101,12 @@ class InitialUserSeeder extends AbstractSeed { [ 'UserID' => $adminId, 'Email' => 'admin@example.com', - 'Time' => Literal::from('now()'), 'IP' => '127.0.0.1', 'useragent' => 'initial-seed', ], [ 'UserID' => $userId, 'Email' => 'user@example.com', - 'Time' => Literal::from('now()'), 'IP' => '127.0.0.1', 'useragent' => 'initial-seed', ] diff --git a/db/seeds/TagSeeder.php b/db/seeds/TagSeeder.php deleted file mode 100644 index 15e95e507..000000000 --- a/db/seeds/TagSeeder.php +++ /dev/null @@ -1,46 +0,0 @@ -table('tags')->insert([ - 'Name' => $tag, - 'TagType' => 'genre', - 'UserID' => 1, - ])->save(); - } - - foreach ([ - 'abstract', 'acid', 'black.metal', 'bluegrass', 'contemporary.jazz', - 'death.metal', 'downtempo', 'drone', 'dub', 'dubstep', - 'female.vocalist', 'free.improvisation', 'french', 'fusion', - 'heavy.metal', 'japanese', 'latin', 'modern.classical', 'post.hardcore', - 'progressive.metal', 'psychedelic.rock', 'score', 'vocal', - ] as $tag) { - $this->table('tags')->insert([ - 'Name' => $tag, - 'TagType' => 'other', - 'UserID' => 1, - ])->save(); - } - - } -} diff --git a/db/seeds/TorrentSeeder.php b/db/seeds/TorrentSeeder.php index e63b436d4..8d0158795 100644 --- a/db/seeds/TorrentSeeder.php +++ b/db/seeds/TorrentSeeder.php @@ -26,7 +26,7 @@ TRUNCATE users_notifications_settings; SET FOREIGN_KEY_CHECKS = 1; */ const DISCOGS_MAX = 11747136; - const TORRENTS = 20; + const TORRENTS = 10; private function getRandomDiscogsAlbum() { $id = rand(1, self::DISCOGS_MAX); @@ -63,14 +63,9 @@ SET FOREIGN_KEY_CHECKS = 1; $artists = []; $groups = []; - $tags = [ - 'rock' => ['id' => 1, 'genre' => 'rock'], - 'pop' => ['id' => 2, 'genre' => 'pop'], - 'female.fronted.symphonic.death.metal' => ['id' => 3, 'genre' => 'female.fronted.symphonic.death.metal'] - ]; + $tags = []; - $i = 0; - while ($i < self::TORRENTS) { + while (count($insertData['torrents']) <= self::TORRENTS) { // Avoid rate limit of 25 albums per minute sleep(2); $album = $this->getRandomDiscogsAlbum(); @@ -78,7 +73,7 @@ SET FOREIGN_KEY_CHECKS = 1; continue; } $user_id = rand($lowerUserId, $upperUserId); - $this->output->writeln("Found torrent {$i}..."); + $this->output->writeln("Found torrent ..."); $artist = $album->artists[0]; if (!isset($artists[$artist->name])) { @@ -114,7 +109,6 @@ SET FOREIGN_KEY_CHECKS = 1; 'Year' => $album->year, 'CatalogueNumber' => $album->labels[0]->catno, 'RecordLabel' => $album->labels[0]->name, - 'Time' => '2018-03-22 02:24:19', 'RevisionID' => count($groups) + 1, 'WikiBody' => $wikiBody, 'WikiImage' => '', @@ -127,7 +121,6 @@ SET FOREIGN_KEY_CHECKS = 1; 'Body' => $wikiBody, 'UserID' => $user_id, 'Summary' => 'Uploaded new torrent', - 'Time' => '2018-03-22 02:24:19', 'Image' => '' ]; @@ -149,7 +142,7 @@ SET FOREIGN_KEY_CHECKS = 1; $groups[$album->title] = ['id' => count($groups) + 1, 'album' => $album]; } - $media = ($album->formats[0]->name === 'Vinyl') ? 'Vinyl' : 'CD'; + $media = (isset($album->formats[0]) && $album->formats[0]->name === 'Vinyl') ? 'Vinyl' : 'CD'; $torrent_id = count($insertData['torrents']) + 1; $files = []; @@ -203,11 +196,6 @@ SET FOREIGN_KEY_CHECKS = 1; 'FreeTorrent' => 0, 'FreeLeechType' => 0 ]; - - $insertData['torrents_leech_stats'][] = [ - 'TorrentID' => count($insertData['torrents']) + 1, - ]; - $i++; } foreach ($insertData as $table => $data) { @@ -215,5 +203,6 @@ SET FOREIGN_KEY_CHECKS = 1; } $this->execute('UPDATE tags SET Uses = ( SELECT COUNT(*) FROM torrents_tags WHERE torrents_tags.TagID = tags.ID GROUP BY TagID)'); + $this->execute('INSERT INTO torrents_leech_stats (TorrentID) SELECT ID FROM torrents'); } } diff --git a/docker-compose.yml b/docker-compose.yml index 03f9dfba2..945dbfe7a 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -4,45 +4,52 @@ services: web: build: . ports: - - 8080:80 + - 127.0.0.1:7001:80 depends_on: - memcached - mysql + - pg volumes: - .:/var/www - .docker/web/nginx.conf:/etc/nginx/sites-available/gazelle.conf environment: - - ENV + - ENV=dev # These should match what you set for your mysql container below - MYSQL_USER=gazelle - MYSQL_PASSWORD=password memcached: - image: memcached:1.6.12-alpine + image: memcached:1.6.14-alpine pg: image: postgres:14 ports: - - 54321:5432 + - 127.0.0.1:54321:5432 volumes: - - ./.docker/pg/data:/var/lib/postgresql/data + - ./.docker/data/pg:/var/lib/postgresql/data environment: - POSTGRES_DB=gzpg - POSTGRES_PASSWORD=gazpg - POSTGRES_USER=gus mysql: - image: mariadb:10.5.13-focal + image: percona:ps-8.0 ports: - - 36000:3306 + - 127.0.0.1:36000:3306 volumes: - - ./.docker/mysql/mysqld_sql_mode.cnf:/etc/mysql/conf.d/mysqld_sql_mode.cnf - ./.docker/data/mysql:/var/lib/mysql + - ./.docker/mysql-home:/home/mysql environment: - MYSQL_DATABASE=gazelle - MYSQL_USER=gazelle - MYSQL_PASSWORD=password - - MYSQL_ROOT_PASSWORD=em%G9Lrey4^N + - MYSQL_ROOT_PASSWORD=sc5tlc9JSCC6 + command: + - /usr/sbin/mysqld + - --group-concat-max-len=1048576 + - --character-set-server=utf8mb4 + - --userstat=on + - --sql-mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION sphinxsearch: build: ./.docker/sphinxsearch @@ -60,7 +67,7 @@ services: ocelot: image: ocelot ports: - - 34000:34000 + - 127.0.0.1:34000:34000 depends_on: - mysql volumes: diff --git a/gazelle.php b/gazelle.php index 89be6cd73..e97a6e4d7 100644 --- a/gazelle.php +++ b/gazelle.php @@ -4,8 +4,8 @@ use Gazelle\Util\Crypto; // 1. Basic sanity checks and initialization -if (PHP_VERSION_ID < 70427) { - die("Gazelle (Orpheus fork) requires at least PHP version 7.4.27 or 8.1.2"); +if (PHP_VERSION_ID < 80104) { + die("Gazelle (Orpheus fork) requires at least PHP version 8.1.4"); } foreach (['memcached', 'mysqli'] as $e) { if (!extension_loaded($e)) { diff --git a/lib/devel.example.config.php b/lib/devel.example.config.php index 4e4dbd034..9f375ab9a 100644 --- a/lib/devel.example.config.php +++ b/lib/devel.example.config.php @@ -23,5 +23,8 @@ define('RSS_HASH', ""); define('SEEDBOX_SALT', ""); define('AVATAR_SALT', ""); +define('SQL_PHINX_USER', 'root'); +define('SQL_PHINX_PASS', 'sc5tlc9JSCC6'); + // Docker setup runs the scheduler only once every 15 minutes define('SCHEDULER_DELAY', 1200); diff --git a/yarn.lock b/yarn.lock index e1282d824..0a8cc63d0 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2160,9 +2160,9 @@ caniuse-api@^3.0.0: lodash.uniq "^4.5.0" caniuse-lite@^1.0.0, caniuse-lite@^1.0.30001039, caniuse-lite@^1.0.30001109, caniuse-lite@^1.0.30001248: - version "1.0.30001251" - resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001251.tgz#6853a606ec50893115db660f82c094d18f096d85" - integrity sha512-HOe1r+9VkU4TFmnU70z+r7OLmtR+/chB1rdcJUeQlAinjEeb0cKL20tlAtOagNZhbrtLnCvV19B4FmF1rgzl6A== + version "1.0.30001320" + resolved "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001320.tgz" + integrity sha512-MWPzG54AGdo3nWx7zHZTefseM5Y1ccM7hlQKHRqJkPozUaw3hNbBTMmLn16GG2FUzjR13Cr3NPfhIieX5PzXDA== ccount@^1.0.0: version "1.0.5"