Skip to content

make fields startDate, endDate, memberRate and customerRate optional #86

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,19 @@ The following parameters can be set in config files or in env variables:
- Modify `DATABASE_URL` under `config/default.js` to meet your environment.
- Run `npm run init-db` to create table(run `npm run init-db force` to force creating table)

## DB Migration
- `npm run migrate`: run any migration files which haven't run yet.
- `npm run migrate:undo`: revert most recent migration.

Configuration for migration is at `./config/config.json`.

The following parameters can be set in the config file or via env variables:

- `username`: set via env `DB_USERNAME`; datebase username
- `password`: set via env `DB_PASSWORD`; datebase password
- `database`: set via env `DB_NAME`; datebase name
- `host`: set via env `DB_HOST`; datebase host name

## ElasticSearch Setup
- Go to https://www.elastic.co/downloads/ download and install the elasticsearch.
- Modify `esConfig` under `config/default.js` to meet your environment.
Expand Down
27 changes: 27 additions & 0 deletions config/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Configuration for DB migration.
*/

module.exports = {
development: {
username: process.env.DB_USERNAME || 'postgres',
password: process.env.DB_PASSWORD || 'postgres',
database: process.env.DB_NAME || 'postgres',
host: process.env.DB_HOST || '127.0.0.1',
dialect: 'postgres'
},
test: {
username: process.env.DB_USERNAME || 'postgres',
password: process.env.DB_PASSWORD || 'postgres',
database: process.env.DB_NAME || 'postgres',
host: process.env.DB_HOST || '127.0.0.1',
dialect: 'postgres'
},
production: {
username: process.env.DB_USERNAME,
password: process.env.DB_PASSWORD,
database: process.env.DB_NAME,
host: process.env.DB_HOST,
dialect: 'postgres'
}
}
23 changes: 23 additions & 0 deletions config/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"development": {
"username": "postgres",
"password": "postgres",
"database": "postgres",
"host": "127.0.0.1",
"dialect": "postgres"
},
"test": {
"username": "root",
"password": null,
"database": "database_test",
"host": "127.0.0.1",
"dialect": "mysql"
},
"production": {
"username": "root",
"password": null,
"database": "database_production",
"host": "127.0.0.1",
"dialect": "mysql"
}
}
8 changes: 0 additions & 8 deletions docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1861,10 +1861,6 @@ components:
- projectId
- userId
- status
- startDate
- endDate
- memberRate
- customerRate
- rateType
- createdAt
- createdBy
Expand Down Expand Up @@ -1935,10 +1931,6 @@ components:
- projectId
- userId
- status
- startDate
- endDate
- memberRate
- customerRate
- rateType
properties:
projectId:
Expand Down
18 changes: 18 additions & 0 deletions migrations/2021-01-04-make-some-resouce-booking-fields-optional.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* Make ResourceBooking fields startDate, endDate, memberRate and customerRate optional.
*/

const targetFields = ['start_date', 'end_date', 'member_rate', 'customer_rate']

module.exports = {
up: queryInterface => {
return Promise.all(targetFields.map(field =>
queryInterface.sequelize.query(`ALTER TABLE bookings.resource_bookings ALTER COLUMN ${field} DROP NOT NULL`)
))
},
down: queryInterface => {
return Promise.all(targetFields.map(field =>
queryInterface.sequelize.query(`ALTER TABLE bookings.resource_bookings ALTER COLUMN ${field} SET NOT NULL`)
))
}
}
Loading