add basic event objects

This commit is contained in:
Roland Schneider
2018-12-12 20:42:17 +01:00
parent 5599d2ef4b
commit b6e590f196
54 changed files with 2811 additions and 0 deletions

View File

@@ -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()
{
}
*/
}