Last active
February 7, 2020 07:55
-
-
Save jschr/873a4ad8591760202c20ea702e6d3c99 to your computer and use it in GitHub Desktop.
.ebextension file and package.json for migrating a db with knex migrate cli and a single docker container beanstalk app
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
container_commands: | |
migrate_db: | |
command: > | |
docker run -e "DB_HOST=${DB_HOST}" -e "DB_PORT=${DB_PORT}" -e "DB_NAME=${DB_NAME}" -e "DB_USER=${DB_USER}" -e "DB_PASSWORD=${DB_PASSWORD}" aws_beanstalk/staging-app:latest npm run db:migration:run | |
leader_only: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as path from 'path' | |
import * as dotenv from 'dotenv' | |
import * as Knex from 'knex' | |
dotenv.config({ path: path.resolve(__dirname, '../../.env') }) | |
const config: Knex.Config = { | |
client: 'pg', | |
connection: { | |
host: process.env.DB_HOST, | |
port: process.env.DB_PORT, | |
database: process.env.DB_NAME, | |
user: process.env.DB_USER, | |
password: process.env.DB_PASSWORD | |
}, | |
migrations: { | |
tableName: 'migrations' | |
} | |
} | |
// using module.exports to be compatible with knex migrate cli | |
// this also means we need to use require('./config') to import | |
module.exports = config |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"scripts": { | |
"db:migration:run": "node node_modules/knex/bin/cli.js migrate:latest --knexfile build/database/config.js", | |
"db:migration:rollback": "node node_modules/knex/bin/cli.js migrate:rollback --knexfile build/database/config.js", | |
"db:seed:run": "node node_modules/knex/bin/cli.js seed:run --knexfile build/database/config.js" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment