mirror of
https://github.com/OPSnet/Gazelle.git
synced 2026-01-16 18:04:34 -05:00
introduce a second phase of mysql migrations (and drop migrated tables)
This commit is contained in:
@@ -42,6 +42,7 @@
|
|||||||
<rule ref="PSR1.Classes.ClassDeclaration.MissingNamespace">
|
<rule ref="PSR1.Classes.ClassDeclaration.MissingNamespace">
|
||||||
<exclude-pattern>classes/*</exclude-pattern>
|
<exclude-pattern>classes/*</exclude-pattern>
|
||||||
<exclude-pattern>misc/my-migrations/*</exclude-pattern>
|
<exclude-pattern>misc/my-migrations/*</exclude-pattern>
|
||||||
|
<exclude-pattern>misc/my2-migrations/*</exclude-pattern>
|
||||||
<exclude-pattern>misc/pg-migrations/*</exclude-pattern>
|
<exclude-pattern>misc/pg-migrations/*</exclude-pattern>
|
||||||
</rule>
|
</rule>
|
||||||
|
|
||||||
|
|||||||
@@ -76,15 +76,22 @@ EOF
|
|||||||
) | mysql -u root -p"$MYSQL_ROOT_PASSWORD" || exit 1
|
) | mysql -u root -p"$MYSQL_ROOT_PASSWORD" || exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "Run Mysql migrations..."
|
PHINXBIN="${CI_PROJECT_DIR}/vendor/bin/phinx"
|
||||||
if ! FKEY_MY_DATABASE=1 LOCK_MY_DATABASE=1 "${CI_PROJECT_DIR}/vendor/bin/phinx" migrate -e gazelle; then
|
echo "Phase 1 Mysql migrations..."
|
||||||
echo "phinx encountered a fatal error in the 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
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "Run Postgresql migrations..."
|
echo "Postgresql migrations..."
|
||||||
if ! "${CI_PROJECT_DIR}/vendor/bin/phinx" migrate -c ./misc/phinx-pg.php; then
|
if ! $PHINXBIN migrate -c ./misc/phinx-pg.php; then
|
||||||
echo "phinx encountered a fatal error in the Postgresql migrations"
|
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
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ export npm_config_cache
|
|||||||
|
|
||||||
bin/config-css /tmp/config-css.js
|
bin/config-css /tmp/config-css.js
|
||||||
|
|
||||||
npm install -g npm@11.2.0
|
npm install -g npm@11.4.1
|
||||||
npm install sass
|
npm install sass
|
||||||
npx update-browserslist-db@latest
|
npx update-browserslist-db@latest
|
||||||
npx puppeteer browsers install chrome
|
npx puppeteer browsers install chrome
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ if [ ! -e .docker-init-done ] ; then
|
|||||||
bin/local-patch
|
bin/local-patch
|
||||||
echo "Installing node, go grab a coffee"
|
echo "Installing node, go grab a coffee"
|
||||||
bin/config-css /tmp/config-css.js
|
bin/config-css /tmp/config-css.js
|
||||||
npm install -g npm@11.2.0
|
npm install -g npm@11.4.1
|
||||||
npm install cypress
|
npm install cypress
|
||||||
npx update-browserslist-db@latest
|
npx update-browserslist-db@latest
|
||||||
npx puppeteer browsers install chrome
|
npx puppeteer browsers install chrome
|
||||||
@@ -29,15 +29,22 @@ do
|
|||||||
sleep 10
|
sleep 10
|
||||||
done
|
done
|
||||||
|
|
||||||
echo "Run mysql migrations..."
|
PHINXBIN=/var/www/vendor/bin/phinx
|
||||||
if ! FKEY_MY_DATABASE=1 LOCK_MY_DATABASE=1 /var/www/vendor/bin/phinx migrate; then
|
echo "Phase 1 Mysql migrations..."
|
||||||
echo "phinx encountered a fatal error in the 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
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "Run postgres migrations..."
|
echo "Postgresql migrations..."
|
||||||
if ! /var/www/vendor/bin/phinx migrate -c ./misc/phinx-pg.php; then
|
if ! $PHINXBIN migrate -c ./misc/phinx-pg.php; then
|
||||||
echo "phinx encountered a fatal error in the Postgresql migrations"
|
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
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|||||||
100
misc/my2-migrations/20250528000000_drop_migrated_tables.php
Normal file
100
misc/my2-migrations/20250528000000_drop_migrated_tables.php
Normal file
@@ -0,0 +1,100 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
use Phinx\Migration\AbstractMigration;
|
||||||
|
|
||||||
|
final class DropMigratedTables extends AbstractMigration {
|
||||||
|
public function up(): void {
|
||||||
|
foreach (
|
||||||
|
[
|
||||||
|
'blog', 'donations_bitcoin', 'email_blacklist', 'error_log',
|
||||||
|
'news', 'users_history_passkeys',
|
||||||
|
] as $table
|
||||||
|
) {
|
||||||
|
$this->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)
|
||||||
|
)
|
||||||
|
");
|
||||||
|
}
|
||||||
|
}
|
||||||
34
misc/my2-phinx.php
Normal file
34
misc/my2-phinx.php
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
require_once __DIR__ . '/../lib/config.php';
|
||||||
|
|
||||||
|
/* This second batch of Mysql migrations are run after the Postgresql migrations
|
||||||
|
* have been run. This is needed for the CI, to drop tables in the Mysql schema
|
||||||
|
* after they have been relayed to Postgresql. Otherwise they would be dropped
|
||||||
|
* before Pg has the chance to do anything about them (create a foreign table
|
||||||
|
* and/or migrate contents).
|
||||||
|
*/
|
||||||
|
|
||||||
|
return [
|
||||||
|
'paths' => [
|
||||||
|
'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,
|
||||||
|
],
|
||||||
|
];
|
||||||
@@ -4,11 +4,11 @@ require_once __DIR__ . '/lib/config.php';
|
|||||||
|
|
||||||
return [
|
return [
|
||||||
'paths' => [
|
'paths' => [
|
||||||
'migrations' => '%%PHINX_CONFIG_DIR%%/misc/my-migrations',
|
'migrations' => __DIR__ . '/misc/my-migrations',
|
||||||
],
|
],
|
||||||
'environments' => [
|
'environments' => [
|
||||||
'migration_table' => 'phinxlog',
|
'default_migration_table' => 'phinxlog',
|
||||||
'default_environment' => 'gazelle',
|
'default_environment' => 'gazelle',
|
||||||
'gazelle' => [
|
'gazelle' => [
|
||||||
'adapter' => 'mysql',
|
'adapter' => 'mysql',
|
||||||
'host' => MYSQL_HOST,
|
'host' => MYSQL_HOST,
|
||||||
|
|||||||
@@ -9,6 +9,8 @@ use Gazelle\Enum\LeechType;
|
|||||||
use Gazelle\Enum\LeechReason;
|
use Gazelle\Enum\LeechReason;
|
||||||
|
|
||||||
class FeaturedAlbumTest extends TestCase {
|
class FeaturedAlbumTest extends TestCase {
|
||||||
|
use Pg;
|
||||||
|
|
||||||
protected TGroup $tgroup;
|
protected TGroup $tgroup;
|
||||||
protected User $user;
|
protected User $user;
|
||||||
|
|
||||||
@@ -24,10 +26,9 @@ class FeaturedAlbumTest extends TestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function tearDown(): void {
|
public function tearDown(): void {
|
||||||
$db = DB::DB();
|
|
||||||
new Manager\News()->remove(
|
new Manager\News()->remove(
|
||||||
(int)$db->scalar("
|
(int)$this->pg()->scalar("
|
||||||
SELECT ID FROM news WHERE UserID = ?
|
select id_news from news where id_user = ?
|
||||||
", $this->user->id
|
", $this->user->id
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user