mirror of
https://github.com/crater-invoice/crater.git
synced 2025-10-27 11:41:09 -04:00
solve migration issue
This commit is contained in:
@ -15,24 +15,24 @@ class CreateBouncerTables extends Migration
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
if (Schema::hasTable('roles')) {
|
||||
Schema::drop(Models::table('roles'));
|
||||
}
|
||||
|
||||
if (Schema::hasTable('permissions')) {
|
||||
Schema::drop(Models::table('permissions'));
|
||||
}
|
||||
|
||||
if (Schema::hasTable('model_has_permissions')) {
|
||||
Schema::drop(Models::table('model_has_permissions'));
|
||||
if (Schema::hasTable('role_has_permissions')) {
|
||||
Schema::drop(Models::table('role_has_permissions'));
|
||||
}
|
||||
|
||||
if (Schema::hasTable('model_has_roles')) {
|
||||
Schema::drop(Models::table('model_has_roles'));
|
||||
}
|
||||
|
||||
if (Schema::hasTable('role_has_permissions')) {
|
||||
Schema::drop(Models::table('role_has_permissions'));
|
||||
if (Schema::hasTable('model_has_permissions')) {
|
||||
Schema::drop(Models::table('model_has_permissions'));
|
||||
}
|
||||
|
||||
if (Schema::hasTable('permissions')) {
|
||||
Schema::drop(Models::table('permissions'));
|
||||
}
|
||||
|
||||
if (Schema::hasTable('roles')) {
|
||||
Schema::drop(Models::table('roles'));
|
||||
}
|
||||
|
||||
Schema::create(Models::table('abilities'), function (Blueprint $table) {
|
||||
|
||||
@ -1,7 +1,13 @@
|
||||
<?php
|
||||
|
||||
use Crater\Models\Address;
|
||||
use Crater\Models\Customer;
|
||||
use Crater\Models\CustomField;
|
||||
use Crater\Models\CustomFieldValue;
|
||||
use Crater\Models\Estimate;
|
||||
use Crater\Models\Expense;
|
||||
use Crater\Models\Invoice;
|
||||
use Crater\Models\Payment;
|
||||
use Crater\Models\User;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
@ -26,68 +32,46 @@ class UpdateCustomerIdInAllTables extends Migration
|
||||
foreach ($users as $user) {
|
||||
$newCustomer = Customer::create($user->toArray());
|
||||
|
||||
Address::where('user_id', $user->id)->update([
|
||||
'customer_id' => $newCustomer->id,
|
||||
'user_id' => null
|
||||
]);
|
||||
|
||||
Expense::where('user_id', $user->id)->update([
|
||||
'customer_id' => $newCustomer->id,
|
||||
'user_id' => null
|
||||
]);
|
||||
|
||||
Estimate::where('user_id', $user->id)->update([
|
||||
'customer_id' => $newCustomer->id,
|
||||
'user_id' => null
|
||||
]);
|
||||
|
||||
Invoice::where('user_id', $user->id)->update([
|
||||
'customer_id' => $newCustomer->id,
|
||||
'user_id' => null
|
||||
]);
|
||||
|
||||
Payment::where('user_id', $user->id)->update([
|
||||
'customer_id' => $newCustomer->id,
|
||||
'user_id' => null
|
||||
]);
|
||||
|
||||
CustomFieldValue::where('custom_field_valuable_id', $user->id)
|
||||
->where('custom_field_valuable_type', 'Crater\Models\User')
|
||||
->update([
|
||||
'custom_field_valuable_type' => 'Crater\Models\Customer',
|
||||
'custom_field_valuable_id' => $newCustomer->id
|
||||
]);
|
||||
}
|
||||
|
||||
$customFields = CustomField::where('model_type', 'User')->get();
|
||||
|
||||
if ($customFields) {
|
||||
$user->fields->map(function ($customFieldValue) use ($newCustomer) {
|
||||
$customFieldValue->custom_field_valuable_type = "Crater\Models\Customer";
|
||||
$customFieldValue->custom_field_valuable_id = $newCustomer->id;
|
||||
$customFieldValue->save();
|
||||
|
||||
$customField = $customFieldValue->customField;
|
||||
foreach ($customFields as $customField) {
|
||||
$customField->model_type = "Customer";
|
||||
$customField->slug = Str::upper('CUSTOM_'.$customField->model_type.'_'.Str::slug($customField->label, '_'));
|
||||
$customField->save();
|
||||
});
|
||||
}
|
||||
|
||||
if ($user->addresses()->exists()) {
|
||||
$user->addresses->map(function ($address) use ($newCustomer) {
|
||||
if ($address) {
|
||||
$address->customer_id = $newCustomer->id;
|
||||
$address->user_id = null;
|
||||
$address->save();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if ($user->expenses()->exists()) {
|
||||
$user->expenses->map(function ($expense) use ($newCustomer) {
|
||||
if ($expense) {
|
||||
$expense->customer_id = $newCustomer->id;
|
||||
$expense->user_id = null;
|
||||
$expense->save();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if ($user->estimates()->exists()) {
|
||||
$user->estimates->map(function ($estimate) use ($newCustomer) {
|
||||
if ($estimate) {
|
||||
$estimate->customer_id = $newCustomer->id;
|
||||
$estimate->user_id = null;
|
||||
$estimate->save();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if ($user->invoices()->exists()) {
|
||||
$user->invoices->map(function ($invoice) use ($newCustomer) {
|
||||
if ($invoice) {
|
||||
$invoice->customer_id = $newCustomer->id;
|
||||
$invoice->user_id = null;
|
||||
$invoice->save();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if ($user->payments()->exists()) {
|
||||
$user->payments->map(function ($payment) use ($newCustomer) {
|
||||
if ($payment) {
|
||||
$payment->customer_id = $newCustomer->id;
|
||||
$payment->save();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user