Skip to content

Commit 8821b54

Browse files
Merge pull request #86 from imcaizheng/make-some-fields-for-resource-booking-optional
make fields startDate, endDate, memberRate and customerRate optional
2 parents 59240c4 + 600c7d9 commit 8821b54

File tree

10 files changed

+406
-30
lines changed

10 files changed

+406
-30
lines changed

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,19 @@ 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+
76+
The following parameters can be set in the config file or via env variables:
77+
78+
- `username`: set via env `DB_USERNAME`; datebase username
79+
- `password`: set via env `DB_PASSWORD`; datebase password
80+
- `database`: set via env `DB_NAME`; datebase name
81+
- `host`: set via env `DB_HOST`; datebase host name
82+
7083
## ElasticSearch Setup
7184
- Go to https://www.elastic.co/downloads/ download and install the elasticsearch.
7285
- Modify `esConfig` under `config/default.js` to meet your environment.

config/config.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* Configuration for DB migration.
3+
*/
4+
5+
module.exports = {
6+
development: {
7+
username: process.env.DB_USERNAME || 'postgres',
8+
password: process.env.DB_PASSWORD || 'postgres',
9+
database: process.env.DB_NAME || 'postgres',
10+
host: process.env.DB_HOST || '127.0.0.1',
11+
dialect: 'postgres'
12+
},
13+
test: {
14+
username: process.env.DB_USERNAME || 'postgres',
15+
password: process.env.DB_PASSWORD || 'postgres',
16+
database: process.env.DB_NAME || 'postgres',
17+
host: process.env.DB_HOST || '127.0.0.1',
18+
dialect: 'postgres'
19+
},
20+
production: {
21+
username: process.env.DB_USERNAME,
22+
password: process.env.DB_PASSWORD,
23+
database: process.env.DB_NAME,
24+
host: process.env.DB_HOST,
25+
dialect: 'postgres'
26+
}
27+
}

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+
}

docs/swagger.yaml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1861,10 +1861,6 @@ components:
18611861
- projectId
18621862
- userId
18631863
- status
1864-
- startDate
1865-
- endDate
1866-
- memberRate
1867-
- customerRate
18681864
- rateType
18691865
- createdAt
18701866
- createdBy
@@ -1935,10 +1931,6 @@ components:
19351931
- projectId
19361932
- userId
19371933
- status
1938-
- startDate
1939-
- endDate
1940-
- memberRate
1941-
- customerRate
19421934
- rateType
19431935
properties:
19441936
projectId:
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)