|
| 1 | +<?php |
| 2 | +defined('BASEPATH') OR exit('No direct script access allowed'); |
| 3 | + |
| 4 | +/** |
| 5 | + * Additive administration schema. Explicit migration only. |
| 6 | + * No accounts, credentials or access grants are created here. |
| 7 | + */ |
| 8 | +class Migration_Admin_credentials extends CI_Migration |
| 9 | +{ |
| 10 | + public function up() |
| 11 | + { |
| 12 | + $this->load->dbforge(); |
| 13 | + $this->dbforge->add_field(array( |
| 14 | + 'id' => array('type' => 'CHAR', 'constraint' => 64), |
| 15 | + 'username' => array('type' => 'VARCHAR', 'constraint' => 128), |
| 16 | + 'enabled' => array('type' => 'INT', 'default' => 0), |
| 17 | + 'created_at' => array('type' => 'BIGINT'), |
| 18 | + )); |
| 19 | + $this->dbforge->add_key('id', TRUE); |
| 20 | + if (!$this->dbforge->create_table('admin_users', TRUE)) { |
| 21 | + throw new RuntimeException('Cannot create admin_users'); |
| 22 | + } |
| 23 | + |
| 24 | + $this->dbforge->add_field(array( |
| 25 | + 'credential_hash' => array('type' => 'CHAR', 'constraint' => 64), |
| 26 | + 'user_id' => array('type' => 'CHAR', 'constraint' => 64), |
| 27 | + 'credential_json' => array('type' => 'TEXT'), |
| 28 | + 'created_at' => array('type' => 'BIGINT'), |
| 29 | + 'last_used_at' => array('type' => 'BIGINT', 'null' => TRUE), |
| 30 | + 'revoked_at' => array('type' => 'BIGINT', 'null' => TRUE), |
| 31 | + )); |
| 32 | + $this->dbforge->add_key('credential_hash', TRUE); |
| 33 | + $this->dbforge->add_key('user_id'); |
| 34 | + if (!$this->dbforge->create_table('admin_credentials', TRUE)) { |
| 35 | + throw new RuntimeException('Cannot create admin_credentials'); |
| 36 | + } |
| 37 | + |
| 38 | + $this->dbforge->add_field(array( |
| 39 | + 'id' => array('type' => 'CHAR', 'constraint' => 64), |
| 40 | + 'user_id' => array('type' => 'CHAR', 'constraint' => 64, 'null' => TRUE), |
| 41 | + 'event' => array('type' => 'VARCHAR', 'constraint' => 64), |
| 42 | + 'occurred_at' => array('type' => 'BIGINT'), |
| 43 | + )); |
| 44 | + $this->dbforge->add_key('id', TRUE); |
| 45 | + $this->dbforge->add_key('occurred_at'); |
| 46 | + if (!$this->dbforge->create_table('admin_audit_log', TRUE)) { |
| 47 | + throw new RuntimeException('Cannot create admin_audit_log'); |
| 48 | + } |
| 49 | + } |
| 50 | + |
| 51 | + public function down() |
| 52 | + { |
| 53 | + // Never silently erase administrator credentials or audit history. |
| 54 | + throw new RuntimeException('Automatic destructive rollback is disabled; use an approved recovery procedure.'); |
| 55 | + } |
| 56 | +} |
0 commit comments