new: [migration] scripts added

- also updated mysql.sql
pull/92/head
iglocska 2021-11-17 15:40:44 +01:00
parent a305bdf9f1
commit 72bd564120
No known key found for this signature in database
GPG Key ID: BEA224F1FEF113AC
2 changed files with 102 additions and 5 deletions

View File

@ -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 */;

View File

@ -0,0 +1,96 @@
<?php
declare(strict_types=1);
use Migrations\AbstractMigration;
final class AuditLogs extends AbstractMigration
{
/**
* Change Method.
*
* Write your reversible migrations using this method.
*
* More information on writing migrations is available here:
* https://book.cakephp.org/phinx/0/en/migrations.html#the-change-method
*
* Remember to call "create()" or "update()" and NOT "save()" when working
* with the Table class.
*/
public $autoId = false; // turn off automatic `id` column create. We want it to be `int(10) unsigned`
public function change(): void
{
$exists = $this->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();
}
}
}