2020-11-14 01:38:56 +00:00
|
|
|
# MyVC (MySQL Version Control)
|
|
|
|
|
2020-11-15 18:24:25 +00:00
|
|
|
Utilities to ease the maintenance of MySQL or MariaDB database versioning using
|
|
|
|
a Git repository.
|
|
|
|
|
|
|
|
This project is just to bring an idea to life and is still in an early stage of
|
|
|
|
development, so it may not be fully functional.
|
|
|
|
|
|
|
|
Any help is welcomed! Feel free to contribute.
|
2020-11-14 01:38:56 +00:00
|
|
|
|
2020-12-02 07:35:26 +00:00
|
|
|
## Requirements
|
2020-11-14 01:38:56 +00:00
|
|
|
|
2021-10-16 06:44:19 +00:00
|
|
|
* Node.js >= 14.0
|
2020-11-15 18:24:25 +00:00
|
|
|
* Git
|
2020-12-04 16:30:26 +00:00
|
|
|
* Docker (Local server)
|
2020-11-14 01:38:56 +00:00
|
|
|
|
2020-11-14 15:08:27 +00:00
|
|
|
## Installation
|
|
|
|
|
|
|
|
It's recommended to install the package globally.
|
2020-11-17 11:47:20 +00:00
|
|
|
|
2020-11-15 18:24:25 +00:00
|
|
|
```text
|
2020-11-14 15:08:27 +00:00
|
|
|
# npm install -g myvc
|
2020-11-17 10:53:31 +00:00
|
|
|
$ myvc [command]
|
2020-11-14 15:08:27 +00:00
|
|
|
```
|
|
|
|
|
2020-11-15 18:24:25 +00:00
|
|
|
You can also install locally and use the *npx* command to execute it.
|
2020-11-17 11:47:20 +00:00
|
|
|
|
2020-11-15 18:24:25 +00:00
|
|
|
```text
|
|
|
|
$ npm install myvc
|
2020-11-17 10:53:31 +00:00
|
|
|
$ npx myvc [command]
|
2020-11-14 01:38:56 +00:00
|
|
|
```
|
|
|
|
|
2020-11-15 18:24:25 +00:00
|
|
|
## How to use
|
2020-11-14 01:38:56 +00:00
|
|
|
|
2020-11-17 10:53:31 +00:00
|
|
|
Execute *myvc* with the desired command.
|
2020-11-17 11:47:20 +00:00
|
|
|
|
2020-11-15 18:24:25 +00:00
|
|
|
```text
|
2020-12-04 16:30:26 +00:00
|
|
|
$ myvc [-w|--workspace] [-r|--remote] [-d|--debug] [-h|--help] command
|
2020-11-14 01:38:56 +00:00
|
|
|
```
|
2020-11-17 11:47:20 +00:00
|
|
|
|
2020-11-17 13:11:15 +00:00
|
|
|
The default workspace directory is the current working directory and unless
|
2020-12-04 16:30:26 +00:00
|
|
|
otherwise indicated, the default remote is *local*.
|
2020-11-14 01:38:56 +00:00
|
|
|
|
2020-12-04 16:30:26 +00:00
|
|
|
Database versioning commands:
|
2020-11-17 10:53:31 +00:00
|
|
|
|
2020-11-19 12:51:27 +00:00
|
|
|
* **init**: Initialize an empty workspace.
|
|
|
|
* **pull**: Export database routines into workspace.
|
2020-12-02 07:35:26 +00:00
|
|
|
* **push**: Apply changes into database.
|
2020-11-17 12:04:57 +00:00
|
|
|
|
2020-12-04 16:30:26 +00:00
|
|
|
Local server management commands:
|
2020-11-17 12:04:57 +00:00
|
|
|
|
2020-12-02 07:35:26 +00:00
|
|
|
* **dump**: Export database structure and fixtures from *production*.
|
|
|
|
* **run**: Build and starts local database server container.
|
|
|
|
* **start**: Start local database server container.
|
2020-11-15 18:24:25 +00:00
|
|
|
|
2020-11-17 10:53:31 +00:00
|
|
|
Each command can have its own specific commandline options.
|
2020-11-14 01:38:56 +00:00
|
|
|
|
|
|
|
## Basic information
|
|
|
|
|
2020-11-19 12:51:27 +00:00
|
|
|
First of all you have to initalize your workspace.
|
2020-11-15 18:38:23 +00:00
|
|
|
|
2020-11-19 12:51:27 +00:00
|
|
|
```text
|
|
|
|
$ myvc init
|
|
|
|
```
|
|
|
|
|
2020-12-02 07:35:26 +00:00
|
|
|
Now you can configure MyVC using *myvc.config.yml* file, located at the root of
|
2020-11-19 12:51:27 +00:00
|
|
|
your workspace. This file should include the project codename and schemas/tables
|
|
|
|
wich are exported when you use *pull* or *dump* commands.
|
2020-11-15 18:38:23 +00:00
|
|
|
|
2020-12-04 16:30:26 +00:00
|
|
|
### Remotes
|
2020-11-16 00:58:27 +00:00
|
|
|
|
2020-11-19 12:51:27 +00:00
|
|
|
Create database connection configuration for each environment at *remotes*
|
2020-12-04 16:30:26 +00:00
|
|
|
folder using standard MySQL *ini* configuration files. The convention remote
|
|
|
|
names are *production* and *test*.
|
2020-11-17 11:47:20 +00:00
|
|
|
|
2020-11-15 18:24:25 +00:00
|
|
|
```text
|
2020-12-04 16:30:26 +00:00
|
|
|
remotes/[remote].ini
|
2020-11-14 01:38:56 +00:00
|
|
|
```
|
|
|
|
|
2020-11-16 00:58:27 +00:00
|
|
|
### Dumps
|
|
|
|
|
2020-11-19 12:51:27 +00:00
|
|
|
Structure and fixture dumps will be created into hidden file *dump/.dump.sql*.
|
|
|
|
You can also create your local fixture and structure files.
|
2020-11-16 00:58:27 +00:00
|
|
|
|
2020-11-19 12:51:27 +00:00
|
|
|
* *dump/structure.sql*
|
|
|
|
* *dump/fixtures.sql*
|
2020-11-14 01:38:56 +00:00
|
|
|
|
2020-11-15 18:24:25 +00:00
|
|
|
### Routines
|
|
|
|
|
|
|
|
Routines should be placed inside *routines* folder. All objects that have
|
2020-11-16 00:58:27 +00:00
|
|
|
PL/SQL code are considered routines. It includes events, functions, procedures,
|
|
|
|
triggers and views with the following structure.
|
2020-11-17 11:47:20 +00:00
|
|
|
|
2020-11-15 18:24:25 +00:00
|
|
|
```text
|
2020-11-14 01:38:56 +00:00
|
|
|
routines
|
|
|
|
`- schema
|
|
|
|
|- events
|
|
|
|
| `- eventName.sql
|
|
|
|
|- functions
|
|
|
|
| `- functionName.sql
|
|
|
|
|- procedures
|
|
|
|
| `- procedureName.sql
|
|
|
|
|- triggers
|
|
|
|
| `- triggerName.sql
|
|
|
|
`- views
|
|
|
|
`- viewName.sql
|
|
|
|
```
|
|
|
|
|
2020-11-15 18:24:25 +00:00
|
|
|
### Versions
|
2020-11-14 01:38:56 +00:00
|
|
|
|
2020-11-19 12:51:27 +00:00
|
|
|
Versions should be placed inside *versions* folder with the following structure.
|
|
|
|
Don't place your PL/SQL objects here, use the routines folder!
|
2020-11-17 11:47:20 +00:00
|
|
|
|
2020-11-15 18:24:25 +00:00
|
|
|
```text
|
2020-11-19 12:51:27 +00:00
|
|
|
versions
|
2020-11-14 01:38:56 +00:00
|
|
|
|- 00001-firstVersionCodeName
|
|
|
|
| |- 00-firstExecutedScript.sql
|
|
|
|
| |- 01-secondScript.sql
|
|
|
|
| `- 99-lastScript.sql
|
|
|
|
`- 00002-secondVersion
|
|
|
|
|- 00-firstExecutedScript.sql
|
|
|
|
`- 00-sameNumbers.sql
|
|
|
|
```
|
2020-11-17 11:47:20 +00:00
|
|
|
|
2020-11-17 12:04:57 +00:00
|
|
|
### Local server
|
|
|
|
|
|
|
|
The local server will be created as a MariaDB Docker container using the base
|
|
|
|
dump created with the *dump* command plus pushing local versions and changed
|
|
|
|
routines.
|
|
|
|
|
2020-11-17 11:47:20 +00:00
|
|
|
## Why
|
|
|
|
|
|
|
|
The main reason for starting this project it's because there are no fully free
|
|
|
|
and opensource migration tools available that allow versioning database routines
|
|
|
|
with an standard CVS system as if they were normal application code.
|
|
|
|
|
|
|
|
Also, the existing tools are too complex and require too much knowledge to start
|
|
|
|
a small project.
|
|
|
|
|
|
|
|
## Todo
|
|
|
|
|
2020-11-17 12:44:46 +00:00
|
|
|
Improve the pull command to, instead of completely overwriting the routines
|
2020-11-17 11:47:20 +00:00
|
|
|
directory, merge the database changes with the local SQL files. It is possible
|
|
|
|
using a library that allows to manipulate git repositories (nodegit) and running
|
2020-11-17 12:04:57 +00:00
|
|
|
the following steps:
|
2020-11-17 11:47:20 +00:00
|
|
|
|
2020-11-17 12:44:46 +00:00
|
|
|
1. Save the current HEAD.
|
|
|
|
2. Check out to the last database push commit (saved in versioning tables).
|
|
|
|
3. Create and checkout to a new branch.
|
|
|
|
4. Export database routines.
|
|
|
|
5. Commit the new changes.
|
|
|
|
5. Checkout to the original HEAD.
|
|
|
|
6. Merge the new branch into.
|
|
|
|
7. Let the user deal with merge conflicts.
|
|
|
|
|
2020-12-19 01:06:06 +00:00
|
|
|
Use a custom *Dockerfile* for local database container.
|
|
|
|
|
|
|
|
Allow to specify a custom workspece subdirectory inside project directory.
|
|
|
|
|
|
|
|
Create a lock during push to avoid collisions.
|
2020-11-17 11:47:20 +00:00
|
|
|
|
2020-11-14 01:38:56 +00:00
|
|
|
## Built With
|
|
|
|
|
|
|
|
* [Git](https://git-scm.com/)
|
|
|
|
* [nodejs](https://nodejs.org/)
|
|
|
|
* [docker](https://www.docker.com/)
|