add basic event objects
This commit is contained in:
@@ -0,0 +1,96 @@
|
||||
<?php
|
||||
|
||||
use yii\db\Migration;
|
||||
|
||||
class m181129_054015_add_group_training_tables extends Migration
|
||||
{
|
||||
public function up()
|
||||
{
|
||||
$tableOptions = null;
|
||||
if ($this->db->driverName === 'mysql') {
|
||||
// http://stackoverflow.com/questions/766809/whats-the-difference-between-utf8-general-ci-and-utf8-unicode-ci
|
||||
$tableOptions = 'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=InnoDB';
|
||||
}
|
||||
$this->createTable('{{%trainer}}', [
|
||||
'id' => $this->primaryKey(),
|
||||
'name' => $this->string(255),
|
||||
'phone' => $this->string(20),
|
||||
'email' => $this->string(255),
|
||||
'password' => $this->string(255),
|
||||
'active' => $this->integer(),
|
||||
'created_at' => $this->dateTime()->notNull(),
|
||||
'updated_at' => $this->dateTime()->notNull(),
|
||||
], $tableOptions);
|
||||
|
||||
|
||||
$this->createTable('{{%room}}', [
|
||||
'id' => $this->primaryKey(),
|
||||
'name' => $this->string(255),
|
||||
'seat_count' => $this->integer(),
|
||||
'created_at' => $this->dateTime()->notNull(),
|
||||
'updated_at' => $this->dateTime()->notNull(),
|
||||
], $tableOptions);
|
||||
|
||||
$this->createTable('{{%event_type}}', [
|
||||
'id' => $this->primaryKey(),
|
||||
'name' => $this->string(255),
|
||||
'created_at' => $this->dateTime()->notNull(),
|
||||
'updated_at' => $this->dateTime()->notNull(),
|
||||
], $tableOptions);
|
||||
|
||||
$this->createTable('{{%event}}', [
|
||||
'id' => $this->primaryKey(),
|
||||
'start' => $this->integer(),
|
||||
'end' => $this->integer(),
|
||||
'id_room' => $this->integer(),
|
||||
'id_trainer' => $this->integer(),
|
||||
'id_event_type' => $this->integer(),
|
||||
'created_at' => $this->dateTime()->notNull(),
|
||||
'updated_at' => $this->dateTime()->notNull(),
|
||||
], $tableOptions);
|
||||
|
||||
$this->createTable('{{%event_registration}}', [
|
||||
'id' => $this->primaryKey(),
|
||||
'id_event' => $this->integer(),
|
||||
'id_customer' => $this->integer(),
|
||||
'created_at' => $this->dateTime()->notNull(),
|
||||
'updated_at' => $this->dateTime()->notNull(),
|
||||
'canceled_at' => $this->dateTime()->notNull(),
|
||||
], $tableOptions);
|
||||
|
||||
|
||||
// $this->execute("DELIMITER $$
|
||||
//
|
||||
//CREATE TRIGGER event_seat_count_check
|
||||
// AFTER INSERT ON event_registration FOR EACH ROW
|
||||
// BEGIN
|
||||
// IF (SELECT COUNT(id) FROM event_registration
|
||||
// WHERE canceled_at is null AND id_event = NEW.id_event) > ( select
|
||||
// THEN
|
||||
// SIGNAL SQLSTATE '45000'
|
||||
// SET MESSAGE_TEXT = 'Max seat count exceeded!';
|
||||
// END IF;
|
||||
// END;
|
||||
//$$");
|
||||
|
||||
|
||||
}
|
||||
|
||||
public function down()
|
||||
{
|
||||
echo "m181129_054015_add_group_training_tables cannot be reverted.\n";
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
// Use safeUp/safeDown to run migration code within a transaction
|
||||
public function safeUp()
|
||||
{
|
||||
}
|
||||
|
||||
public function safeDown()
|
||||
{
|
||||
}
|
||||
*/
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
use yii\db\Schema;
|
||||
use yii\db\Migration;
|
||||
|
||||
class m181205_050104_create_trigger_event_registration extends Migration
|
||||
{
|
||||
public function up()
|
||||
{
|
||||
$this->addColumn('{{%event}}',"seat_count",$this->integer());
|
||||
$this->execute("CREATE TRIGGER event_seat_count_check
|
||||
AFTER INSERT ON event_registration FOR EACH ROW
|
||||
BEGIN
|
||||
IF (SELECT coalesce(COUNT(id),0) FROM event_registration
|
||||
WHERE canceled_at is null AND id_event = NEW.id_event)
|
||||
>
|
||||
(SELECT coalesce(seat_count,0) from event where id_event = NEW.id_event)
|
||||
THEN
|
||||
SIGNAL SQLSTATE '45000'
|
||||
SET MESSAGE_TEXT = 'MAX_SEAT_COUNT_EXCEEDED';
|
||||
END IF;
|
||||
END;
|
||||
");
|
||||
}
|
||||
|
||||
public function down()
|
||||
{
|
||||
$this->execute("DROP TRIGGER IF EXISTS event_seat_count_check;");
|
||||
}
|
||||
|
||||
/*
|
||||
// Use safeUp/safeDown to run migration code within a transaction
|
||||
public function safeUp()
|
||||
{
|
||||
}
|
||||
|
||||
public function safeDown()
|
||||
{
|
||||
}
|
||||
*/
|
||||
}
|
||||
Reference in New Issue
Block a user