0

I have two sites site1.dev and site2.dev pointing to the same application. What I want is connect site1.dev to one database (db1) and site2.dev to other(db2) and sync db1 to db2 . well I found out that using more than two databases is possible , but what I actually want is syncing all activites of db1 to db2 . I have also created a logs table for recording activites for create, edit and delete. This is the schema of the table

    Schema::create('sync_logs', function (Blueprint $table) {
        $table->increments('id');
        $table->integer('model_id')->nullable()->default(null);
        $table->string('model')->nullable()->default(null);
        $table->integer('action')->comment('0=>Create, 1=>Update, 2=>Delete');
        $table->text('data');
        $table->boolean('synced')->default(0);
        $table->timestamps();
    });

I am planning to retrieve all the unsynced data and insert the data to db2 in loop. Is this possible ? What are the ways to do that ?

3
  • Have you tried database replication or you are trying to implement this yourself. If it is the second one please give us more information on when you want to replicate the databases and a bit more for the setup you are expecting. for example will the databases always be on the same machine? Commented Feb 13, 2017 at 8:32
  • The databases will not always be on the same machine . db1 will be on the client machine and db2 on the cloud server, but for development purpose I want both of them on my machine for now. When the application is installed on the client machine , all activities are recorded in db1 and db2 will be updated every day at one time. Commented Feb 13, 2017 at 8:39
  • Ok so you can use laravel.com/docs/5.3/scheduling for the timing and tan serialize all the models that haven't been synchronized Commented Feb 13, 2017 at 11:03

1 Answer 1

1

You can do this by recording the track of the data which is synced to the database. Like, save the last id for an employee table in the tracking table and run a cronjob everyday to check if the employee table id is greater than the tracking table foreign key (employee_id) then sync the un-synced employee data to DB2.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.