diff --git a/INSTALL/mysql.sql b/INSTALL/mysql.sql index e5dcd7a..6bd956c 100644 --- a/INSTALL/mysql.sql +++ b/INSTALL/mysql.sql @@ -393,14 +393,14 @@ CREATE TABLE `meta_template_fields` ( CREATE TABLE IF NOT EXISTS `audit_logs` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `created` datetime NOT NULL, - `user_id` int(10) unsigned NOT NULL, - `authkey_id` int(11) DEFAULT NULL, - `ip` varbinary(16) DEFAULT NULL, + `user_id` int(10) unsigned DEFAULT NULL, + `authkey_id` int(10) unsigned DEFAULT NULL, + `request_ip` varbinary(16) DEFAULT NULL, `request_type` tinyint NOT NULL, `request_id` varchar(191) DEFAULT NULL, - `action` varchar(20) NOT NULL, + `request_action` varchar(20) NOT NULL, `model` varchar(80) NOT NULL, - `model_id` int(10) unsigned NOT NULL, + `model_id` int(10) unsigned DEFAULT NULL, `model_title` text DEFAULT NULL, `change` blob, PRIMARY KEY (`id`), @@ -409,6 +409,7 @@ CREATE TABLE IF NOT EXISTS `audit_logs` ( KEY `model` (`model`), KEY `action` (`action`), KEY `model_id` (`model_id`) + KEY `created` (`created`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; /*!40101 SET SQL_MODE=@OLD_SQL_MODE */; diff --git a/config/Migrations/20211117135403_audit_logs.php b/config/Migrations/20211117135403_audit_logs.php new file mode 100644 index 0000000..c44847b --- /dev/null +++ b/config/Migrations/20211117135403_audit_logs.php @@ -0,0 +1,96 @@ +hasTable('audit_logs'); + if (!$exists) { + $table = $this->table('audit_logs', [ + 'signed' => false, + 'collation' => 'utf8mb4_unicode_ci' + ]); + $table + ->addColumn('id', 'integer', [ + 'autoIncrement' => true, + 'limit' => 10, + 'signed' => false, + ]) + ->addPrimaryKey('id') + ->addColumn('user_id', 'integer', [ + 'default' => null, + 'null' => true, + 'signed' => false, + 'length' => 10 + ]) + ->addColumn('authkey_id', 'integer', [ + 'default' => null, + 'null' => true, + 'signed' => false, + 'length' => 10 + ]) + ->addColumn('request_ip', 'varbinary', [ + 'default' => null, + 'null' => true, + 'length' => 16 + ]) + ->addColumn('request_type', 'boolean', [ + 'null' => false + ]) + ->addColumn('request_id', 'integer', [ + 'default' => null, + 'null' => true, + 'signed' => false, + 'length' => 10 + ]) + ->addColumn('request_action', 'string', [ + 'null' => false, + 'length' => 20 + ]) + ->addColumn('model', 'string', [ + 'null' => false, + 'length' => 80 + ]) + ->addColumn('model_id', 'integer', [ + 'default' => null, + 'null' => true, + 'signed' => false, + 'length' => 10 + ]) + ->addColumn('model_title', 'text', [ + 'default' => null, + 'null' => true + ]) + ->addColumn('change', 'blob', [ + ]) + ->addColumn('created', 'datetime', [ + 'default' => null, + 'null' => false, + ]) + ->addIndex('user_id') + ->addIndex('request_ip') + ->addIndex('model') + ->addIndex('model_id') + ->addIndex('request_action') + ->addIndex('created'); + $table->create(); + } + } +}