Command line utility to synchronize and version control relational database objects across databases.
$ yarn add @leapfrogtechnology/sync-db
Global Installation
$ yarn global add @leapfrogtechnology/sync-db
Install node database driver(s) of the database(s) that are to be synced, for example this is how you would install the mssql driver:
$ yarn add mssql
Note: If sync-db is installed globally, install database driver(s) globally too.
Create connections-sync-db.json
in your project folder and configure your database connection(s) to be synced.
{
"connections": [
{
"id": "db1",
"host": "localhost",
"port": 1433,
"user": "db1user",
"database": "db1",
"password": "password",
"client": "mssql"
},
{
"id": "db2",
"host": "localhost",
"port": 1433,
"user": "db2user",
"database": "db2",
"password": "password",
"client": "mssql"
}
]
}
- Copy the SQL files in your project in following folder structure.
└─ sql
├─ schema
│ ├─ schema1.sql
│ ├─ schema2.sql
│ ├─ schema3.sql
│ └─ ...
│
├─ function
│ ├─ schema1
│ │ ├─ function1.sql
│ │ ├─ function2.sql
│ │ └─ ...
│ ├─ schema2
│ │ ├─ function3.sql
│ │ ├─ function4.sql
│ │ └─ ...
│ ├─ function5.sql
│ └─ ...
│
├─ procedure
│ ├─ schema1
│ │ ├─ procedure1.sql
│ │ ├─ procedure2.sql
│ │ └─ ...
│ ├─ schema2
│ │ ├─ procedure3.sql
│ │ ├─ procedure4.sql
│ │ └─ ...
│ ├─ procedure5.sql
│ └─ ...
│
└─...
Note: When procedures and functions aren't placed inside a schema folder, they are associated with the default schema.
- Create
sync-db.yml
file in your project folder.
basePath: /path/to/sql
sql:
- schema/<schema_name>.sql
- function/<schema_name>/<function_name>.sql
- procedure/<schema_name>/<procedure_name>.sql
Note: Default basePath is src/sql
.
-
Specify the base path of the folder for SQL files in
basePath
key. -
List database objects in the order they need to be synced under the
sql
key.
Add sync-db
script in your package.json
file.
- Add script in your
package.json
{
"scripts": {
"sync-db": "sync-db",
}
}
- Run
$ yarn sync-db
- Install npx globally on your machine
npm install -g npx
- Run
npx sync-db
Licensed under The MIT License.