commit21
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('users', function (Blueprint $table) {
|
||||
$table->text('two_factor_secret')->nullable();
|
||||
$table->text('two_factor_recovery_codes')->nullable();
|
||||
$table->timestamp('two_factor_confirmed_at')->nullable();
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('users', fn (Blueprint $table) => $table->dropColumn(['two_factor_secret', 'two_factor_recovery_codes', 'two_factor_confirmed_at']));
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('receipt_documents', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('tenant_id')->constrained();
|
||||
$table->foreignId('goods_receipt_id')->constrained();
|
||||
$table->foreignId('uploaded_by')->constrained('users');
|
||||
$table->string('document_type', 30);
|
||||
$table->string('original_name', 180);
|
||||
$table->string('path');
|
||||
$table->string('mime_type', 100);
|
||||
$table->unsignedInteger('size');
|
||||
$table->string('sha256', 64);
|
||||
$table->timestamp('created_at');
|
||||
$table->unique(['tenant_id', 'goods_receipt_id', 'document_type', 'sha256'], 'receipt_document_content_unique');
|
||||
});
|
||||
if (DB::getDriverName() === 'pgsql') {
|
||||
DB::unprepared("CREATE FUNCTION receipt_documents_immutable() RETURNS trigger LANGUAGE plpgsql AS $$ BEGIN RAISE EXCEPTION 'Receipt documents are append only'; END; $$;
|
||||
CREATE TRIGGER receipt_documents_immutable BEFORE UPDATE OR DELETE ON receipt_documents FOR EACH ROW EXECUTE FUNCTION receipt_documents_immutable();");
|
||||
} elseif (DB::getDriverName() === 'sqlite') {
|
||||
foreach (['UPDATE', 'DELETE'] as $event) {
|
||||
DB::unprepared('CREATE TRIGGER receipt_documents_'.strtolower($event)." BEFORE $event ON receipt_documents BEGIN SELECT RAISE(ABORT, 'Receipt documents are append only'); END");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('receipt_documents');
|
||||
if (DB::getDriverName() === 'pgsql') {
|
||||
DB::unprepared('DROP FUNCTION IF EXISTS receipt_documents_immutable()');
|
||||
}
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user