Switchout DB to CockroachDB

This commit is contained in:
Deon George
2022-01-01 16:59:35 +11:00
parent afaa7d8bc7
commit 424d6ef39d
28 changed files with 1342 additions and 865 deletions

View File

@@ -16,11 +16,10 @@ class UpdateZones extends Migration
DB::statement('ALTER TABLE zones ALTER COLUMN domain_id SET NOT NULL');
Schema::table('zones', function (Blueprint $table) {
$table->integer('system_id');
$table->dropColumn(['description','ipv4','ipv4_mask','ipv6','ipv6_mask','zt_id']);
$table->string('ztid')->nullable();
$table->dropUnique(['domain_id']);
$table->integer('system_id');
$table->foreign('system_id')->references('id')->on('systems');
});
}

View File

@@ -14,8 +14,8 @@ class AddSystemToSetups extends Migration
public function up()
{
Schema::table('setups', function (Blueprint $table) {
$table->integer('options');
$table->integer('system_id');
$table->integer('options');
$table->foreign('system_id')->references('id')->on('systems');
});
}

View File

@@ -0,0 +1,137 @@
<?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->string('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->integer('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');
}
}