feat: create the model and migration for parameters

This commit is contained in:
b1ek 2024-08-19 19:24:25 +10:00
parent 24d38f199d
commit 252b4ccffc
Signed by: blek
GPG Key ID: 14546221E3595D0C
2 changed files with 92 additions and 0 deletions

View File

@ -0,0 +1,45 @@
<?php
use yii\db\cubrid\Schema;
use yii\db\Migration;
/**
* Class m240819_084542_parameters
*/
class m240819_084542_parameters extends Migration
{
/**
* {@inheritdoc}
*/
public function safeUp()
{
$this->createTable('parameters', [
'id' => Schema::TYPE_PK,
'title' => Schema::TYPE_STRING . ' NOT NULL',
'type' => 'TINYINT NOT NULL CHECK (type IN (1, 2))',
]);
}
/**
* {@inheritdoc}
*/
public function safeDown()
{
$this->dropTable('parameters');
}
/*
// Use up()/down() to run migration code without a transaction.
public function up()
{
}
public function down()
{
echo "m240819_084542_parameters cannot be reverted.\n";
return false;
}
*/
}

47
models/Parameters.php Normal file
View File

@ -0,0 +1,47 @@
<?php
namespace app\models;
use Yii;
/**
* This is the model class for table "parameters".
*
* @property int $id
* @property string $title
* @property int $type
*/
class Parameters extends \yii\db\ActiveRecord
{
/**
* {@inheritdoc}
*/
public static function tableName()
{
return 'parameters';
}
/**
* {@inheritdoc}
*/
public function rules()
{
return [
[['title', 'type'], 'required'],
[['type'], 'integer'],
[['title'], 'string', 'max' => 255],
];
}
/**
* {@inheritdoc}
*/
public function attributeLabels()
{
return [
'id' => 'ID',
'title' => 'Title',
'type' => 'Type',
];
}
}