1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-09 20:52:56 +01:00

Multi-db support

This commit is contained in:
Hillel Coren 2017-04-30 22:29:15 +03:00
parent 95cbbc2dc9
commit 068666a58b
4 changed files with 23 additions and 9 deletions

View File

@ -106,6 +106,7 @@ class InitLookup extends Command
LookupUser::create([ LookupUser::create([
'lookup_account_id' => $lookupAccount->id, 'lookup_account_id' => $lookupAccount->id,
'email' => $user['email'], 'email' => $user['email'],
'user_id' => $user['user_id'],
]); ]);
} }
foreach ($account['contacts'] as $contact) { foreach ($account['contacts'] as $contact) {
@ -154,24 +155,34 @@ class InitLookup extends Command
'tokens' => [], 'tokens' => [],
]; ];
$users = DB::table('users')->whereAccountId($accountId)->orderBy('id')->get(['email']); $users = DB::table('users')->whereAccountId($accountId)->orderBy('id')->get(['email', 'id']);
foreach ($users as $user) { foreach ($users as $user) {
$data['users'][] = ['email' => $user->email]; $data['users'][] = [
'email' => $user->email,
'user_id' => $user->id,
];
} }
$contacts = DB::table('contacts')->whereAccountId($accountId)->orderBy('id')->get(['contact_key']); $contacts = DB::table('contacts')->whereAccountId($accountId)->orderBy('id')->get(['contact_key']);
foreach ($contacts as $contact) { foreach ($contacts as $contact) {
$data['contacts'][] = ['contact_key' => $contact->contact_key]; $data['contacts'][] = [
'contact_key' => $contact->contact_key,
];
} }
$invitations = DB::table('invitations')->whereAccountId($accountId)->orderBy('id')->get(['invitation_key', 'message_id']); $invitations = DB::table('invitations')->whereAccountId($accountId)->orderBy('id')->get(['invitation_key', 'message_id']);
foreach ($invitations as $invitation) { foreach ($invitations as $invitation) {
$data['invitations'][] = ['invitation_key' => $invitation->invitation_key, 'message_id' => $invitation->message_id]; $data['invitations'][] = [
'invitation_key' => $invitation->invitation_key,
'message_id' => $invitation->message_id,
];
} }
$tokens = DB::table('account_tokens')->whereAccountId($accountId)->orderBy('id')->get(['token']); $tokens = DB::table('account_tokens')->whereAccountId($accountId)->orderBy('id')->get(['token']);
foreach ($tokens as $token) { foreach ($tokens as $token) {
$data['tokens'][] = ['token' => $token->token]; $data['tokens'][] = [
'token' => $token->token,
];
} }
return $data; return $data;

View File

@ -15,6 +15,7 @@ class LookupUser extends LookupModel
protected $fillable = [ protected $fillable = [
'lookup_account_id', 'lookup_account_id',
'email', 'email',
'user_id',
]; ];
} }

View File

@ -415,12 +415,9 @@ class User extends Authenticatable
User::creating(function ($user) User::creating(function ($user)
{ {
if (! $user->registered) {
return;
}
LookupUser::createNew($user->account->account_key, [ LookupUser::createNew($user->account->account_key, [
'email' => $user->email, 'email' => $user->email,
'user_id' => $user->id,
]); ]);
}); });

View File

@ -26,6 +26,11 @@ class AddMultipleDatabaseSupport extends Migration
Schema::table('lookup_users', function ($table) { Schema::table('lookup_users', function ($table) {
$table->string('email')->change()->unique(); $table->string('email')->change()->unique();
$table->unsignedInteger('user_id')->index();
});
Schema::table('lookup_users', function ($table) {
$table->unique(['lookup_account_id', 'user_id']);
}); });
Schema::table('lookup_contacts', function ($table) { Schema::table('lookup_contacts', function ($table) {