From 01578c36b601f6015bb99f0b782eda2a7043d932 Mon Sep 17 00:00:00 2001 From: Derek Crannaford Date: Wed, 11 Sep 2024 07:43:11 +1000 Subject: [PATCH 1/3] InboxRemoveTable conditional row deletion --- .../install/migrations/20240218223900-InboxRemoveTable.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/system/modules/admin/install/migrations/20240218223900-InboxRemoveTable.php b/system/modules/admin/install/migrations/20240218223900-InboxRemoveTable.php index b196444cf..37284d7c2 100644 --- a/system/modules/admin/install/migrations/20240218223900-InboxRemoveTable.php +++ b/system/modules/admin/install/migrations/20240218223900-InboxRemoveTable.php @@ -12,8 +12,10 @@ public function up(): void $this->dropTable('inbox_message'); //Clear out the related user roles - $this->w->db->delete('user_role')->where('role', 'inbox_sender')->execute(); - $this->w->db->delete('user_role')->where('role', 'inbox_reader')->execute(); + if ($this->hasTable('user_role')) { + $this->w->db->delete('user_role')->where('role', 'inbox_sender')->execute(); + $this->w->db->delete('user_role')->where('role', 'inbox_reader')->execute(); + } } public function down(): void From d12ffafbd3502b8600bb8dfaaa095518644e2c0c Mon Sep 17 00:00:00 2001 From: Derek Crannaford Date: Wed, 11 Sep 2024 11:14:52 +1000 Subject: [PATCH 2/3] Make base install migration table independant of module install ordering --- ...21-AdminAddMigrationMessageTextColumns.php | 35 ++++++++++++------- ...40911010101-AdminStableMigrationSchema.php | 34 ++++++++++++++++++ .../modules/admin/models/MigrationService.php | 3 +- 3 files changed, 59 insertions(+), 13 deletions(-) create mode 100644 system/modules/admin/install/migrations/20240911010101-AdminStableMigrationSchema.php diff --git a/system/modules/admin/install/migrations/20190117125821-AdminAddMigrationMessageTextColumns.php b/system/modules/admin/install/migrations/20190117125821-AdminAddMigrationMessageTextColumns.php index aa2ea6373..a855baf3c 100644 --- a/system/modules/admin/install/migrations/20190117125821-AdminAddMigrationMessageTextColumns.php +++ b/system/modules/admin/install/migrations/20190117125821-AdminAddMigrationMessageTextColumns.php @@ -1,28 +1,39 @@ addColumnToTable('migration', 'pretext', 'string', ['default' => null, 'null' => true]); - $this->addColumnToTable('migration', 'posttext', 'string', ['default' => null, 'null' => true]); - $this->addColumnToTable('migration', 'description', 'string', ['default' => null, 'null' => true]); + public function up() + { + + if ($this->hasTable('migration') && !$this->table("migration")->hasColumn("pretext")) { + $this->addColumnToTable('migration', 'pretext', 'string', ['default' => null, 'null' => true]); + $this->addColumnToTable('migration', 'posttext', 'string', ['default' => null, 'null' => true]); + $this->addColumnToTable('migration', 'description', 'string', ['default' => null, 'null' => true]); + } } - public function down() { - $this->removeColumnFromTable('migration', 'pretext'); - $this->removeColumnFromTable('migration', 'posttext'); - $this->removeColumnFromTable('migration', 'description'); + public function down() + { + if ($this->hasTable('migration') && $this->table("migration")->hasColumn("pretext")) { + $this->removeColumnFromTable('migration', 'pretext'); + $this->removeColumnFromTable('migration', 'posttext'); + $this->removeColumnFromTable('migration', 'description'); + } } - public function preText() { + public function preText() + { return ""; } - public function postText() { + public function postText() + { return ""; } - public function description() { + public function description() + { return ""; } } diff --git a/system/modules/admin/install/migrations/20240911010101-AdminStableMigrationSchema.php b/system/modules/admin/install/migrations/20240911010101-AdminStableMigrationSchema.php new file mode 100644 index 000000000..b2fc56cf6 --- /dev/null +++ b/system/modules/admin/install/migrations/20240911010101-AdminStableMigrationSchema.php @@ -0,0 +1,34 @@ +addColumnToTable('migration', 'pretext', 'string', ['default' => null, 'null' => true]); + $this->addColumnToTable('migration', 'posttext', 'string', ['default' => null, 'null' => true]); + $this->addColumnToTable('migration', 'description', 'string', ['default' => null, 'null' => true]); + } + + public function down() + { + $this->removeColumnFromTable('migration', 'pretext'); + $this->removeColumnFromTable('migration', 'posttext'); + $this->removeColumnFromTable('migration', 'description'); + } + + public function preText() + { + return ""; + } + + public function postText() + { + return ""; + } + + public function description() + { + return ""; + } +} diff --git a/system/modules/admin/models/MigrationService.php b/system/modules/admin/models/MigrationService.php index ddf8e54d4..6f4c1a1e2 100644 --- a/system/modules/admin/models/MigrationService.php +++ b/system/modules/admin/models/MigrationService.php @@ -549,7 +549,8 @@ public function installInitialMigration() { $filenames = [ "AdminInitialMigration" => "20151030134124-AdminInitialMigration.php", - "AdminMigrationSeed" => "20170123091600-AdminMigrationSeed.php" + "AdminMigrationSeed" => "20170123091600-AdminMigrationSeed.php", + "AdminStableMigrationSchema" => "20240911010101-AdminStableMigrationSchema.php", ]; $directory = SYSTEM_MODULE_DIRECTORY . DS . "admin" . DS . MIGRATION_DIRECTORY; From 2f0bd2fb5c08755bfad7948bfe693e33243681f4 Mon Sep 17 00:00:00 2001 From: Derek Crannaford Date: Wed, 11 Sep 2024 11:32:35 +1000 Subject: [PATCH 3/3] lint/layout on changes only --- .../migrations/20240218223900-InboxRemoveTable.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/system/modules/admin/install/migrations/20240218223900-InboxRemoveTable.php b/system/modules/admin/install/migrations/20240218223900-InboxRemoveTable.php index 37284d7c2..78d96aa50 100644 --- a/system/modules/admin/install/migrations/20240218223900-InboxRemoveTable.php +++ b/system/modules/admin/install/migrations/20240218223900-InboxRemoveTable.php @@ -1,4 +1,5 @@ dropTable('inbox_message'); //Clear out the related user roles - if ($this->hasTable('user_role')) { + if ($this->hasTable('user_role')) { $this->w->db->delete('user_role')->where('role', 'inbox_sender')->execute(); $this->w->db->delete('user_role')->where('role', 'inbox_reader')->execute(); } } - public function down(): void - { - } + public function down(): void {} - public function description() { + public function description() + { return 'Remove inbox table and roles'; } }