@defra/wls-eps-api
Version:
The API to support the wildlife licencing of European Protected Species
49 lines (43 loc) • 981 B
JavaScript
import { SEQUELIZE } from '@defra/wls-connectors-lib'
import pkg from 'sequelize'
const { DataTypes } = pkg
const models = {}
const createModels = async () => {
const sequelize = SEQUELIZE.getSequelize()
models.users = await sequelize.define('user', {
id: {
type: DataTypes.UUID,
primaryKey: true
},
sddsId: {
type: DataTypes.UUID
}
}, {
timestamps: true
})
models.applications = await sequelize.define('applications', {
id: {
type: DataTypes.UUID,
primaryKey: true
},
sddsId: {
type: DataTypes.UUID
},
userId: {
type: DataTypes.UUID,
references: {
model: models.users,
key: 'id'
}
},
application: {
type: DataTypes.JSONB
}
}, {
timestamps: true,
indexes: [{ unique: false, fields: ['user_id'], name: 'application_user_fk' }]
})
await models.users.sync()
await models.applications.sync()
}
export { models, createModels }