mysql-migration 1.2.3 → 1.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +118 -28
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,25 +1,73 @@
|
|
|
1
|
-
|
|
1
|
+
<div align="center">
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
# 🗄️ MySQL Migration Database
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
**A command-line companion that helps you manage versioned MySQL schema changes from your Node.js projects.**
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
[](https://www.npmjs.com/package/mysql-migration)
|
|
8
|
+
[](LICENSE.md)
|
|
9
|
+
[](https://nodejs.org/)
|
|
8
10
|
|
|
9
|
-
|
|
11
|
+
</div>
|
|
10
12
|
|
|
11
|
-
|
|
13
|
+
---
|
|
12
14
|
|
|
13
|
-
|
|
15
|
+
## ✨ Features
|
|
14
16
|
|
|
15
|
-
|
|
17
|
+
- 🎯 **Multi-database support** — Orchestrate migrations across different environments
|
|
18
|
+
- ⏱️ **Timestamped migration files** — Generated with a single command
|
|
19
|
+
- ⚡ **Forward and backward execution** — Run or roll back batches confidently
|
|
20
|
+
- 🔧 **Scriptable CLI** — Plugs into CI/CD pipelines via standard Node.js tooling
|
|
21
|
+
- 📦 **Zero dependencies** — Lightweight and fast
|
|
16
22
|
|
|
17
|
-
|
|
23
|
+
## 📋 Prerequisites
|
|
18
24
|
|
|
19
|
-
-
|
|
20
|
-
-
|
|
21
|
-
-
|
|
22
|
-
|
|
25
|
+
- **Node.js** v16 or later.
|
|
26
|
+
- **MySQL** instance reachable from where you run the CLI.
|
|
27
|
+
- A project workspace where you can store migration files and configuration.
|
|
28
|
+
|
|
29
|
+
## 📦 Installation
|
|
30
|
+
|
|
31
|
+
Install locally within your project:
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
npm install --save-dev mysql-migration
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
Or run ad hoc without installing by prefixing commands with `npx`.
|
|
38
|
+
|
|
39
|
+
## 🚀 Quick Start
|
|
40
|
+
|
|
41
|
+
**1️⃣ Create a configuration file**
|
|
42
|
+
|
|
43
|
+
Create `mysql-migration.config.json` in your project root (see [Configuration](#%EF%B8%8F-configuration)).
|
|
44
|
+
|
|
45
|
+
**2️⃣ Initialize the migrations table**
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
npx mysql-migration init
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
**3️⃣ Generate your first migration**
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
npx mysql-migration create add_users_table main-db
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
**4️⃣ Apply pending migrations**
|
|
58
|
+
|
|
59
|
+
```bash
|
|
60
|
+
npx mysql-migration run main-db
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
## ⚙️ Configuration
|
|
64
|
+
|
|
65
|
+
The CLI reads settings from `mysql-migration.config.json`. Define each database you manage inside the `databases` object. Every entry requires the connection credentials documented below:
|
|
66
|
+
|
|
67
|
+
- `host`: MySQL server host name or IP.
|
|
68
|
+
- `database`: Database schema name.
|
|
69
|
+
- `user`: User with migration privileges.
|
|
70
|
+
- `password`: Corresponding password.
|
|
23
71
|
|
|
24
72
|
```json
|
|
25
73
|
{
|
|
@@ -34,29 +82,71 @@ The configuration file `mysql-migration.config.json` should export an object wit
|
|
|
34
82
|
}
|
|
35
83
|
```
|
|
36
84
|
|
|
37
|
-
|
|
85
|
+
Add as many database entries as you need. You can then target each one via the CLI commands below.
|
|
86
|
+
|
|
87
|
+
## 📖 Usage
|
|
88
|
+
|
|
89
|
+
### 📝 Available Commands
|
|
90
|
+
|
|
91
|
+
| Command | Description |
|
|
92
|
+
|---------|-------------|
|
|
93
|
+
| `npx mysql-migration help` | 📚 Show all available commands |
|
|
94
|
+
| `npx mysql-migration init` | 🎬 Initialize the migrations table |
|
|
95
|
+
| `npx mysql-migration create <name> <dbName>` | ✏️ Scaffold a timestamped migration file |
|
|
96
|
+
| `npx mysql-migration run [dbName]` | ▶️ Execute all pending migrations |
|
|
97
|
+
| `npx mysql-migration rollback <dbName> <batch>` | ⏪ Roll back migrations to specified batch |
|
|
98
|
+
| `npx mysql-migration batch <dbName>` | 📊 Display recorded batches |
|
|
99
|
+
|
|
100
|
+
### ✏️ Create a New Migration
|
|
101
|
+
|
|
102
|
+
```bash
|
|
103
|
+
npx mysql-migration create migration-name database-name
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
A new file appears in the `migrations/` directory, timestamped and ready for your SQL `up` and `down` statements.
|
|
107
|
+
|
|
108
|
+
### ▶️ Run Pending Migrations
|
|
109
|
+
|
|
110
|
+
```bash
|
|
111
|
+
npx mysql-migration run database-name
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
All migrations that have not yet been applied will run sequentially for the selected database.
|
|
115
|
+
|
|
116
|
+
### ⏪ Roll Back Migrations
|
|
117
|
+
|
|
118
|
+
```bash
|
|
119
|
+
npx mysql-migration rollback database-name batch
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
Use this when you need to revert the database state to the specified batch number.
|
|
123
|
+
|
|
124
|
+
### 📊 Inspect Batches
|
|
125
|
+
|
|
126
|
+
```bash
|
|
127
|
+
npx mysql-migration batch database-name
|
|
128
|
+
```
|
|
38
129
|
|
|
39
|
-
|
|
130
|
+
View the recorded batches to understand which migrations were executed together.
|
|
40
131
|
|
|
41
|
-
|
|
132
|
+
## 🔧 Troubleshooting
|
|
42
133
|
|
|
43
|
-
|
|
44
|
-
|
|
134
|
+
- **Authentication errors**: Verify credentials in `mysql-migration.config.json` match your MySQL user.
|
|
135
|
+
- **Connection refused**: Ensure the MySQL server accepts remote connections from your host and the port is open.
|
|
136
|
+
- **Missing migrations folder**: Run `npx mysql-migration init` to scaffold the `migrations/` directory and configuration file.
|
|
45
137
|
|
|
46
|
-
|
|
138
|
+
## 💬 Support
|
|
47
139
|
|
|
48
|
-
|
|
140
|
+
Use `npx mysql-migration help` to review commands, or open an issue on the repository if you encounter bugs or have enhancement ideas.
|
|
49
141
|
|
|
50
|
-
|
|
51
|
-
 `npx mysql-migration run database-name(optional)`
|
|
142
|
+
---
|
|
52
143
|
|
|
53
|
-
|
|
144
|
+
<div align="center">
|
|
54
145
|
|
|
55
|
-
###
|
|
146
|
+
### 📄 License
|
|
56
147
|
|
|
57
|
-
|
|
58
|
-
 `npx mysql-migration rollback database-name batch`
|
|
148
|
+
This project is distributed under a **custom non-commercial license**. Please review [`LICENSE.md`](LICENSE.md) for the full terms before using the software.
|
|
59
149
|
|
|
60
|
-
|
|
150
|
+
Made with ❤️ by [SherKan](https://github.com/SherKan-n)
|
|
61
151
|
|
|
62
|
-
>
|
|
152
|
+
</div>
|