Skip to content

Commit 4fa94f5

Browse files
committed
add migration script
1 parent b0bd4dd commit 4fa94f5

File tree

5 files changed

+356
-6
lines changed

5 files changed

+356
-6
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,12 @@ The following parameters can be set in config files or in env variables:
6767
- Modify `DATABASE_URL` under `config/default.js` to meet your environment.
6868
- Run `npm run init-db` to create table(run `npm run init-db force` to force creating table)
6969

70+
## DB Migration
71+
- `npm run migrate`: run any migration files which haven't run yet.
72+
- `npm run migrate:undo`: revert most recent migration.
73+
74+
Configuration for migration is at `./config/config.json`.
75+
7076
## ElasticSearch Setup
7177
- Go to https://www.elastic.co/downloads/ download and install the elasticsearch.
7278
- Modify `esConfig` under `config/default.js` to meet your environment.

config/config.json

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"development": {
3+
"username": "postgres",
4+
"password": "postgres",
5+
"database": "postgres",
6+
"host": "127.0.0.1",
7+
"dialect": "postgres"
8+
},
9+
"test": {
10+
"username": "root",
11+
"password": null,
12+
"database": "database_test",
13+
"host": "127.0.0.1",
14+
"dialect": "mysql"
15+
},
16+
"production": {
17+
"username": "root",
18+
"password": null,
19+
"database": "database_production",
20+
"host": "127.0.0.1",
21+
"dialect": "mysql"
22+
}
23+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/*
2+
* Make ResourceBooking fields startDate, endDate, memberRate and customerRate optional.
3+
*/
4+
5+
const targetFields = ['start_date', 'end_date', 'member_rate', 'customer_rate']
6+
7+
module.exports = {
8+
up: queryInterface => {
9+
return Promise.all(targetFields.map(field =>
10+
queryInterface.sequelize.query(`ALTER TABLE bookings.resource_bookings ALTER COLUMN ${field} DROP NOT NULL`)
11+
))
12+
},
13+
down: queryInterface => {
14+
return Promise.all(targetFields.map(field =>
15+
queryInterface.sequelize.query(`ALTER TABLE bookings.resource_bookings ALTER COLUMN ${field} SET NOT NULL`)
16+
))
17+
}
18+
}

0 commit comments

Comments
 (0)