Add Tenant model, controller, and migration; update Producto model to reference tenant_codigo

This commit is contained in:
2026-06-19 11:34:10 -03:00
parent aa49c82543
commit 507b81b54e
7 changed files with 171 additions and 3 deletions

View File

@@ -0,0 +1,30 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('tenants', function (Blueprint $table) {
$table->id();
$table->string('codigo')->unique();
$table->string('nombre');
$table->string('dominio')->nullable();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('tenants');
}
};

View File

@@ -0,0 +1,38 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('productos', function (Blueprint $table) {
$table->dropColumn('tenant_id');
});
Schema::table('productos', function (Blueprint $table) {
$table->string('tenant_codigo')->after('id');
$table->foreign('tenant_codigo')->references('codigo')->on('tenants')->cascadeOnUpdate()->restrictOnDelete();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('productos', function (Blueprint $table) {
$table->dropForeign(['tenant_codigo']);
$table->dropColumn('tenant_codigo');
});
Schema::table('productos', function (Blueprint $table) {
$table->unsignedBigInteger('tenant_id')->after('id');
});
}
};