table('polls') ->addColumn('title', 'string', ['limit' => 200, 'null' => false]) ->addColumn('email', 'string', ['limit' => 255, 'null' => false]) // sha256 of the secret admin token; the token itself is only sent by mail ->addColumn('admin_token_hash', 'string', ['limit' => 64, 'null' => false]) // token encrypted with Security.salt so the recovery mail can resend the same link ->addColumn('admin_token_encrypted', 'text', ['null' => false]) // short public code participants use to join, e.g. "K7P2QX" ->addColumn('join_code', 'string', ['limit' => 12, 'null' => false]) ->addColumn('current_slide_id', 'integer', ['null' => true, 'default' => null]) ->addColumn('is_active', 'boolean', ['null' => false, 'default' => true]) ->addColumn('show_results_to_participants', 'boolean', ['null' => false, 'default' => true]) ->addColumn('last_admin_access', 'datetime', ['null' => true, 'default' => null]) ->addColumn('created', 'datetime', ['null' => false]) ->addColumn('modified', 'datetime', ['null' => false]) ->addIndex(['admin_token_hash'], ['unique' => true]) ->addIndex(['join_code'], ['unique' => true]) ->addIndex(['email']) ->create(); $this->table('slides') ->addColumn('poll_id', 'integer', ['null' => false]) // choice | wordcloud | open | scale | content ->addColumn('type', 'string', ['limit' => 20, 'null' => false]) ->addColumn('question', 'string', ['limit' => 500, 'null' => false]) ->addColumn('description', 'text', ['null' => true, 'default' => null]) ->addColumn('position', 'integer', ['null' => false, 'default' => 0]) // JSON encoded type specific settings (multiple, scale_min, scale_max, ...) ->addColumn('settings', 'text', ['null' => true, 'default' => null]) ->addColumn('is_voting_open', 'boolean', ['null' => false, 'default' => true]) ->addColumn('created', 'datetime', ['null' => false]) ->addColumn('modified', 'datetime', ['null' => false]) ->addIndex(['poll_id', 'position']) ->addForeignKey('poll_id', 'polls', 'id', ['delete' => 'CASCADE', 'update' => 'NO_ACTION']) ->create(); $this->table('slide_options') ->addColumn('slide_id', 'integer', ['null' => false]) ->addColumn('label', 'string', ['limit' => 255, 'null' => false]) ->addColumn('position', 'integer', ['null' => false, 'default' => 0]) ->addIndex(['slide_id', 'position']) ->addForeignKey('slide_id', 'slides', 'id', ['delete' => 'CASCADE', 'update' => 'NO_ACTION']) ->create(); $this->table('responses') ->addColumn('slide_id', 'integer', ['null' => false]) // sha256 of the participant cookie id - anonymous, only used to prevent double voting ->addColumn('participant_hash', 'string', ['limit' => 64, 'null' => false]) ->addColumn('slide_option_id', 'integer', ['null' => true, 'default' => null]) ->addColumn('text_value', 'string', ['limit' => 500, 'null' => true, 'default' => null]) ->addColumn('numeric_value', 'integer', ['null' => true, 'default' => null]) ->addColumn('created', 'datetime', ['null' => false]) ->addIndex(['slide_id', 'participant_hash']) ->addIndex(['slide_option_id']) ->addForeignKey('slide_id', 'slides', 'id', ['delete' => 'CASCADE', 'update' => 'NO_ACTION']) ->addForeignKey('slide_option_id', 'slide_options', 'id', ['delete' => 'CASCADE', 'update' => 'NO_ACTION']) ->create(); } }