You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+76-15Lines changed: 76 additions & 15 deletions
Original file line number
Diff line number
Diff line change
@@ -2,26 +2,36 @@
2
2
3
3
MySQL migration tool for typescript projects. Supports mysqljs and node-mysql2 driver.
4
4
5
-
## IMPORTANT NOTICE
6
-
7
-
This code is work in progress. Please test your upgrade and downgrade scripts well before use it on production database!
8
-
9
-
Please also note the following paragraph from License:
10
-
11
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
12
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
13
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
14
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
15
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
16
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
17
-
SOFTWARE.
18
-
19
5
## Installation
20
6
21
7
```ssh
22
8
npm i ts-mysql-migrate
23
9
```
24
10
11
+
## Changelog
12
+
13
+
### v1.1.0
14
+
15
+
Now it is possible to [generate migration scripts](#cli--support-for-timestamp) with timestamps in order not to create problems when merging from different branches. That was an annoying issue in larger teams working on same project.
16
+
17
+
You can control behavior of strict order with environment variable `MIGRATIONS_STRICT_ORDER`. See [environment variables](#environment-variables) for details.
18
+
19
+
## Environment variables
20
+
21
+
This project utilizes environment variables to configure various aspects of the migration process. You can define these variables in a `.env` file at the root of your project. To use `.env` files, ensure the `dotenv` package is installed, as it is required for loading these variables into your environment.
22
+
23
+
Here are some key environment variables used in this project:
24
+
25
+
***`MIGRATIONS_STRICT_ORDER`**: Ensures migration scripts follow a strict index/timeline order. Possible to override with passing `strictOrder` parameter to constructor. Default is `true` in production (`NODE_ENV='production'`), otherwise `false`.
26
+
***`MIGRATIONS_NUMERIC_ORDER`**: Enforces strict number order for migration scripts ordered by numbers. Should be disabled if scripts are prefixed with timestamps. Possible to override with passing `numOrder` parameter to constructor. Set to `false` by default.
27
+
***`MIGRATION_FOLDER`**: Specifies the default path to the migrations folder for the CLI script generator.
28
+
***Database Configuration for running tests**:
29
+
*`DB_HOST`: Database host
30
+
*`DB_PORT`: Database port.
31
+
*`DB_USER`: Database user.
32
+
*`DB_PASSWORD`: Database password.
33
+
*`DB_DATABASE`: Database name.
34
+
25
35
## API
26
36
27
37
### initialize()
@@ -48,7 +58,9 @@ Closes database connection and releases handles.
48
58
49
59
### Create migration scripts
50
60
51
-
Create migration scripts and name them with number prefix to set the order of execution (versions). Each migration script should have ```upgrade``` and ```downgrade``` functions exported. These functions must have ```queryFn``` as parameter - see examples below.
61
+
Create migration scripts and name them with number prefix to set the order of execution (versions). In v2 you can also generate it with [CLI](#cli--support-for-timestamp) to have a timestamp as identifier.
62
+
63
+
Each migration script should have ```upgrade``` and ```downgrade``` functions exported. These functions must have ```queryFn``` as parameter - see examples below.
52
64
53
65
Example: ```/src/migrations/1-init_db.ts```
54
66
@@ -178,3 +190,52 @@ You can put them in ```package.json``` and run it from npm. Example:
You can now save script names with any number as a prefix - this is meant to be used with unix timestamp. To generate script with current timestamp, you can run CLI command from local installation by running
199
+
200
+
```sh
201
+
npx generate-migration
202
+
```
203
+
204
+
Alternatively you can also install package globally
205
+
206
+
```sh
207
+
npm i ts-mysql-migrate -g
208
+
```
209
+
210
+
Then you can call the command in the root of your project.
211
+
212
+
```sh
213
+
generate-migration
214
+
```
215
+
216
+
You can set the env variable `MIGRATION_FOLDER` to customize default or even set script in your `package.json` for example:
0 commit comments