#211 CustBulkCmdModel migration

This commit is contained in:
Daniel Brendel
2025-02-03 15:43:23 +01:00
parent 5aff2259d6
commit 892a3e7c15
3 changed files with 11 additions and 15 deletions
+6
View File
@@ -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;
}
}
/**
+1 -1
View File
@@ -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');
+4 -14
View File
@@ -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';
}
}