0

Right now I am building few social networks each having its own domain and database called content and a single common user database that is connected to all of them.

The question is - can I place the migration data concerning users into the users' database, so that every time updates to database are implemented via

php artisan migrate

on each of the social networks, - those would only apply to user database only once.

naneri
  • 3,771
  • 2
  • 29
  • 53
  • So, you would have an app database and a users database. You want to be able to have users database migrations in any of the apps but you want to make sure that all individuals apps keep track of all migrations on users database and do not keep running them out of sync ? – Noman Ur Rehman Feb 05 '15 at 09:01
  • @NomanUrRehman I am not quite sure I've got it right. You see, all the apps have absolutely identical app databases and use the same user database. So I already have an ugly solution - create another laravel project just for running user migrations, but it means that all developers (including front end) will have to also download that second project and additional instruction how they should run this, etc. I was just wondering if there could be less complex solution. – naneri Feb 05 '15 at 09:10
  • So you want a single central migration repo to be shared by multiple projects ? – Noman Ur Rehman Feb 05 '15 at 09:55
  • @NomanUrRehman it is what I have. The thing is, that I want to run app database migration several times, but it won't because the user database is the same for all apps, and on the second time it already says, that such a database already exists. – naneri Feb 05 '15 at 10:40

1 Answers1

4

I have done this on a project in the past, but you need to be careful with the Artisan commands you run.

Working with your example I would do the following;

  • app/database/migrations/users - Migrations for your user database live here
  • app/database/migrations/content - Migrations for your content database live here

You will also need to create appropriate database connections to your config;

In app/config/database.php;

<?php
return [
    'connections' => [
        'users' => [
            // Usual database connection details here
        ],
        'content_site1' => [
            // Usual database connection details here
        ],
        'content_site2' => [
            // Usual database connection details here
        ]
    ]
];

Once you have this all configured you should be able to run php artisan migrate --path app/database/migrations/users --database users to migrate your users database, and php artisan migrate --path app/database/migrations/content --database content_site1 for your content site. Remember change the database param for each connection you want to run the migration on.

marcus.ramsden
  • 2,633
  • 1
  • 22
  • 33