clrghouz/database/migrations/2022_01_01_235631_create_mail.php

138 lines
4.4 KiB
PHP

<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateMail extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('echomails', function (Blueprint $table) {
$table->id();
$table->timestamps();
$table->softDeletes();
$table->string('mid')->nullable();
$table->string('to',128);
$table->string('from',128);
$table->string('subject',256);
$table->dateTimeTz('datetime');
$table->tinyInteger('tzoffset');
$table->string('msgid')->nullable();
$table->string('replyid')->nullable();
$table->text('msg');
$table->text('msg_src')->nullable();
$table->string('msg_crc')->nullable();
$table->string('tagline')->nullable();
$table->string('tearline')->nullable();
$table->string('origin')->nullable();
$table->tinyInteger('flags')->nullable();
$table->jsonb('rogue_path')->nullable();
$table->jsonb('rogue_seenby')->nullable();
$table->jsonb('kludges')->nullable();
$table->integer('echoarea_id');
$table->foreign('echoarea_id')->references('id')->on('echoareas');
$table->integer('fftn_id');
$table->foreign('fftn_id')->references('id')->on('addresses');
});
DB::statement("ALTER TABLE address_echomail RENAME COLUMN echomail_id TO mid");
DB::statement("ALTER TABLE address_echomail ALTER COLUMN mid DROP NOT NULL");
DB::statement("ALTER TABLE address_echomail RENAME COLUMN export_date TO export_at");
DB::statement("ALTER TABLE address_echomail ALTER COLUMN export_at DROP NOT NULL");
DB::statement("ALTER TABLE address_echomail RENAME COLUMN sent_date TO sent_at");
DB::statement("ALTER TABLE address_echomail RENAME TO echomail_seenby");
Schema::table('echomail_seenby', function (Blueprint $table) {
$table->integer('echomail_id')->nullable()->first();
$table->string('packet')->nullable();
$table->foreign('echomail_id')->references('id')->on('echomails');
});
Schema::create('echomail_path', function (Blueprint $table) {
$table->id();
$table->integer('address_id');
$table->foreign('address_id')->references('id')->on('addresses');
$table->unique(['id','echomail_id']);
$table->unique(['echomail_id','address_id','parent_id']);
$table->integer('parent_id')->nullable();
$table->foreign(['parent_id','echomail_id'])->references(['id','echomail_id'])->on('echomail_path');
$table->integer('echomail_id');
$table->foreign('echomail_id')->references('id')->on('echomails');
});
Schema::create('netmails', function (Blueprint $table) {
$table->id();
$table->timestamps();
$table->softDeletes();
$table->string('mid')->nullable();
$table->string('to',128);
$table->string('from',128);
$table->string('subject',256);
$table->dateTimeTz('datetime');
$table->tinyInteger('tzoffset')->nullable();
$table->tinyInteger('flags')->nullable();
$table->tinyInteger('cost')->nullable();
$table->string('msgid')->nullable();
$table->string('replyid')->nullable();
$table->text('msg');
$table->text('msg_src')->nullable();
$table->string('msg_crc')->nullable();
$table->string('tagline')->nullable();
$table->string('tearline')->nullable();
$table->boolean('local')->default(FALSE);
$table->string('recv_pkt')->nullable();
$table->string('sent_pkt')->nullable();
$table->dateTimeTz('sent_at')->nullable();
$table->integer('fftn_id');
$table->integer('tftn_id');
$table->foreign('fftn_id')->references('id')->on('addresses');
$table->foreign('tftn_id')->references('id')->on('addresses');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('echomail_seenby', function (Blueprint $table) {
$table->dropForeign(['echomail_id']);
$table->dropColumn(['packet','echomail_id']);
});
DB::commit();
DB::statement("ALTER TABLE echomail_seenby RENAME TO address_echomail");
DB::statement("ALTER TABLE address_echomail RENAME COLUMN mid TO echomail_id;");
DB::statement("ALTER TABLE address_echomail RENAME COLUMN export_at TO export_date;");
DB::statement("ALTER TABLE address_echomail RENAME COLUMN sent_at TO sent_date;");
Schema::dropIfExists('echomail_path');
Schema::dropIfExists('echomails');
Schema::dropIfExists('netmails');
}
}