Skip to content
Oxford Harrison edited this page Nov 8, 2024 · 11 revisions

linkedql replicate

Replicate schema histories in a second database.

What it does: diffs two database instances by schema histories and replicates any changes in first database in second database; typically used for migration.

Usage

For online replication, use the --origin flag. (REQUIRED)

npx linkedql replicate --origin

Use the --swap flag to have the databases switch roles:

npx linkedql replicate --origin --swap

For offline replication, use the --histories flag. (REQUIRED)

npx linkedql replicate --histories

Concepts

Target and origin databases

  • Target database: the database where changes are to be replicated; typically, your production database.
  • Origin database: the database where changes have been made; typically, your development database.

Online and offline replication

  • Online replication: "target database" replicates "origin database" using "origin database"'s Linked QL client. This is applicable where "origin database" is reachable from "target database"; e.g. where both databases are online databases or where both are local databases.

    Here, you export the additional database client (i.e. the "origin database"'s Linked QL client) from your driver.js file as origin:

    ./database/driver.js

    export default async function() {
        return // your default Linked QL client (being the "target database")
    }
    export async function origin() {
        return // your origin Linked QL client (being the "origin database")
    }
  • Offline replication: "target database" replicates "origin database" using "origin database"'s histories dump.

    Here, you have your "origin database"'s histories dumped ahead of replication, typically during your application's build process:

    ./package.json

    {
        "scripts": {
            "build": "linkedql dump-histories && other things"
        }
    }

Replication

The actual execution of the linkedql replicate command, typically done as part of your application's deployment process:

./package.json

{
    "scripts": {
        "deploy": "linkedql replicate --origin && other things"
    }
}
Clone this wiki locally