@knetik/micro-postgres
v3.0.17
Published
This package adds postgres support using sequelize to any [micro-core](https://www.npmjs.com/package/@knetik/micro-core) application as a multi tenant adaptor.
Downloads
13
Readme
Knetik Micro Postgres
This package adds postgres support using sequelize to any micro-core application as a multi tenant adaptor.
When a customer connects to a micro-core application, the required app_id is passed into the postgres initializer and used as the database name. Then creating a connection and loading any sequelize models defined in the models directory.
Example Usage
In app/models/example.postgres.js
const Sequelize = require('sequelize');
module.exports = (sequelize) => {
return sequelize.define('example', {
prop: {
type: Sequelize.NUMBER
}
},
{
timestamps : true,
underscored : true
});
}
In micro-console
App.connect(app_id, access_token)
.then(App => App.Postgres.get('Example'))
.then(Example => Example.create({ prop: 42 }))
.then(res => console.log(res))
.catch(err => console.log(err))
In a micro-core
module
module.exports (App) => {
cosnt Example = App.Postgres.get('Exmaple')
Example.create({ prop: 42 })
}
Migrations
Migrations are handled with umzug: https://github.com/sequelize/umzug
- Add migrations to
APP_ROOT/db/migrations
- Migration status will be checked on each request.
- If there are pending migrations, they will be run and then the status will be cached in the mc_internal_metadata table per client.
Feel free to add migration hook into your deploy tooling.