dbsm
is a cli DB script manager. It allows for easily managing ad-hoc DB scripts (SQL, NoSQL) as parts of projects and associated with managed environment
configurations.
dbsm
simplifies the management of ad-hoc DB scripts by allowing you to track projects. The three manageable areas are:
-
Projects
Name of the project, e.g.
webapp1
-
Environments
Any enrionment name, used for organizing DB connections, e.g
dev
,stage
,test
,prod
, etc...
-
-
Scripts
Name of DB script. These are stored in
~/.dbsm/projects/project/scriptname.sql|js|etc.
Each script is edited using $EDITOR editor. -
Database Connections
Specify a Database type for each Project Environment, e.g.
mysql
,postgresql
,mongodb
, etc.
Usage:
dbsm [--generate=<Any>] [--pw_len=<Any>] init <project_name> <environment> <db_type>
dbsm project list
dbsm project echovars <project_name> <environment> [<echopass>]
dbsm script add <project_name> <script_name>
dbsm script run <project_name> <environment> <script_name>
dbsm script list <project_name>
dbsm git init
dbsm git remote origin <url>
dbsm git push
dbsm git pull
Specify the project name, environment, and database type. Environment naming convention is up to user. For example, there is no requirement to use dev, stage, test
vs level1, level2, level3
.
./bin/dbsm init webproject1 dev mysql
./bin/dbsm project list
This makes it simple to include dbsm
in shell scripts in order to assign project
parameters to local environment variables.
#!/bin/bash
# Use configuration without password
source <(./bin/dbsm project echovars webapp1 dev);
# Use configuration with password
source <(./bin/dbsm project echovars webapp1 dev echopass);
echo "$DB_HOST";
echo "$DB_NAME";
echo "$DB_USERNAME";
echo "$DB_PASSWORD";
Scripts are available to all environtments
so only require a project name and script name to create:
./bin/dbsm script add webproject1 top10cities.sql
The user's editor (defined in the user's $EDITOR env var) will open the script for editing. If the script already exists for the specified project then the user will be prompted to edit the script or cancel.
Run a script under the context of a project's environment:
./bin/dbsm script run webapp1 dev top10projects.sql
./bin/dbsm script list webapp1
This will initialize ~/.dbsm
as a git repository.
./bin/dbsm git init
This will add a remote origin to the ~/.dbsm
repository.
./bin/dbsm git remote origin git@gitlab.com:somegroup/dbscripts.git
Push all new modifications to the remote origin
./bin/dbsm git push
Pull the latest modifications from the remote origin
./bin/dbsm git pull
Clone the repository to your local system:
git clone https://github.com/cnstechnicalgroup/dbsm.git
cd dbsm/
panda install .
- Add tests (added basic tests)
- Add
cp
,mv
to scripts / projects - Add additional Database support
- Sam Morrison
Copyright 2016 Sam Morrison
This library is free software; you can redistribute it and/or modify it under the Artistic License 2.0.