Open Monograph Press  3.3.0
LogMigration.inc.php
1 <?php
2 
14 use Illuminate\Database\Migrations\Migration;
15 use Illuminate\Database\Schema\Builder;
16 use Illuminate\Database\Schema\Blueprint;
17 use Illuminate\Database\Capsule\Manager as Capsule;
18 
19 class LogMigration extends Migration {
24  public function up() {
25  // A log of all events associated with an object.
26  Capsule::schema()->create('event_log', function (Blueprint $table) {
27  $table->bigInteger('log_id')->autoIncrement();
28  $table->bigInteger('assoc_type');
29  $table->bigInteger('assoc_id');
30  $table->bigInteger('user_id');
31  $table->datetime('date_logged');
32  $table->bigInteger('event_type')->nullable();
33  $table->text('message')->nullable();
34  $table->smallInteger('is_translated')->nullable();
35  $table->index(['assoc_type', 'assoc_id'], 'event_log_assoc');
36  });
37 
38  // Event log associative data
39  Capsule::schema()->create('event_log_settings', function (Blueprint $table) {
40  $table->bigInteger('log_id');
41  $table->string('setting_name', 255);
42  $table->text('setting_value')->nullable();
43  $table->string('setting_type', 6)->comment('(bool|int|float|string|object)');
44  $table->index(['log_id'], 'event_log_settings_log_id');
45  $table->unique(['log_id', 'setting_name'], 'event_log_settings_pkey');
46  });
47 
48  // A log of all emails sent out related to an object.
49  Capsule::schema()->create('email_log', function (Blueprint $table) {
50  $table->bigInteger('log_id')->autoIncrement();
51  $table->bigInteger('assoc_type');
52  $table->bigInteger('assoc_id');
53  $table->bigInteger('sender_id');
54  $table->datetime('date_sent');
55  $table->bigInteger('event_type')->nullable();
56  $table->string('from_address', 255)->nullable();
57  $table->text('recipients')->nullable();
58  $table->text('cc_recipients')->nullable();
59  $table->text('bcc_recipients')->nullable();
60  $table->string('subject', 255)->nullable();
61  $table->text('body')->nullable();
62  $table->index(['assoc_type', 'assoc_id'], 'email_log_assoc');
63  });
64 
65  // Associations for email logs within a user.
66  Capsule::schema()->create('email_log_users', function (Blueprint $table) {
67  $table->bigInteger('email_log_id');
68  $table->bigInteger('user_id');
69  $table->unique(['email_log_id', 'user_id'], 'email_log_user_id');
70  });
71  }
72 
77  public function down() {
78  Capsule::schema()->drop('email_log_users');
79  Capsule::schema()->drop('email_log');
80  Capsule::schema()->drop('event_log_settings');
81  Capsule::schema()->drop('event_log');
82  }
83 }
LogMigration\down
down()
Definition: LogMigration.inc.php:77
LogMigration
Describe database table structures.
Definition: LogMigration.inc.php:19
LogMigration\up
up()
Definition: LogMigration.inc.php:24