From 892a3e7c156af42ebbe89cf36313dbcb895c8a04 Mon Sep 17 00:00:00 2001 From: Daniel Brendel Date: Mon, 3 Feb 2025 15:43:23 +0100 Subject: [PATCH] #211 CustBulkCmdModel migration --- app/commands/MigrationUpgrade.php | 6 ++++++ app/migrations/CustBulkCmdModel.php | 2 +- app/models/CustBulkCmdModel.php | 18 ++++-------------- 3 files changed, 11 insertions(+), 15 deletions(-) diff --git a/app/commands/MigrationUpgrade.php b/app/commands/MigrationUpgrade.php index 7ec6eb4..0c52968 100644 --- a/app/commands/MigrationUpgrade.php +++ b/app/commands/MigrationUpgrade.php @@ -54,6 +54,12 @@ class MigrationUpgrade implements Asatru\Commands\Command { } catch (\Exception $e) { echo $e->getMessage() . PHP_EOL; } + + try { + CustBulkCmdModel::raw('RENAME TABLE `custbulkcmd` TO `@THIS`'); + } catch (\Exception $e) { + echo $e->getMessage() . PHP_EOL; + } } /** diff --git a/app/migrations/CustBulkCmdModel.php b/app/migrations/CustBulkCmdModel.php index 1eb664b..fbe19cd 100644 --- a/app/migrations/CustBulkCmdModel.php +++ b/app/migrations/CustBulkCmdModel.php @@ -25,7 +25,7 @@ class CustBulkCmdModel_Migration { */ public function up() { - $this->database = new Asatru\Database\Migration('custbulkcmd', $this->connection); + $this->database = new Asatru\Database\Migration('CustBulkCmdModel', $this->connection); $this->database->drop(); $this->database->add('id INT NOT NULL AUTO_INCREMENT PRIMARY KEY'); $this->database->add('label VARCHAR(512) NOT NULL'); diff --git a/app/models/CustBulkCmdModel.php b/app/models/CustBulkCmdModel.php index 577b78d..2664915 100644 --- a/app/models/CustBulkCmdModel.php +++ b/app/models/CustBulkCmdModel.php @@ -12,7 +12,7 @@ class CustBulkCmdModel extends \Asatru\Database\Model { public static function getCmdList() { try { - return static::raw('SELECT * FROM `' . self::tableName() . '`'); + return static::raw('SELECT * FROM `@THIS`'); } catch (\Exception $e) { throw $e; } @@ -28,7 +28,7 @@ class CustBulkCmdModel extends \Asatru\Database\Model { public static function addCmd($label, $attribute, $styles) { try { - static::raw('INSERT INTO `' . self::tableName() . '` (label, attribute, styles) VALUES(?, ?, ?)', [ + static::raw('INSERT INTO `@THIS` (label, attribute, styles) VALUES(?, ?, ?)', [ $label, $attribute, $styles ]); } catch (\Exception $e) { @@ -47,7 +47,7 @@ class CustBulkCmdModel extends \Asatru\Database\Model { public static function editCmd($id, $label, $attribute, $styles) { try { - static::raw('UPDATE `' . self::tableName() . '` SET label = ?, attribute = ?, styles = ? WHERE id = ?', [ + static::raw('UPDATE `@THIS` SET label = ?, attribute = ?, styles = ? WHERE id = ?', [ $label, $attribute, $styles, $id ]); } catch (\Exception $e) { @@ -63,19 +63,9 @@ class CustBulkCmdModel extends \Asatru\Database\Model { public static function removeCmd($id) { try { - static::raw('DELETE FROM `' . self::tableName() . '` WHERE id = ?', [$id]); + static::raw('DELETE FROM `@THIS` WHERE id = ?', [$id]); } catch (\Exception $e) { throw $e; } } - - /** - * Return the associated table name of the migration - * - * @return string - */ - public static function tableName() - { - return 'custbulkcmd'; - } } \ No newline at end of file