diff options
Diffstat (limited to 'src/routers/vault/models/vault/login_log.js')
-rw-r--r-- | src/routers/vault/models/vault/login_log.js | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/src/routers/vault/models/vault/login_log.js b/src/routers/vault/models/vault/login_log.js new file mode 100644 index 0000000..5f42469 --- /dev/null +++ b/src/routers/vault/models/vault/login_log.js @@ -0,0 +1,45 @@ +const Sequelize = require("sequelize"); // from npm registry + +// NOTE: to get the ip, use something like +// select *, INET6_NTOA(ip) as ip_ from vault.login_log; +// and to search by ip use something like +// select * from vault.login_log where ip = INET6_ATON("ip addr"); + +module.exports = { + fields: { + id: { + type: Sequelize.INTEGER.UNSIGNED, + primaryKey: true, + autoIncrement: true, + allowNull: false, + }, + userId: { + type: Sequelize.INTEGER.UNSIGNED, + allowNull: false, + }, + action: { + type: Sequelize.ENUM("LOGIN", "LOGOUT", "CREATE"), + allowNull: false, + defaultValue: "LOGIN", + }, + ip: { + type: "VARBINARY(16)", + allowNull: false, + }, + date: { + type: Sequelize.DATE, + allowNull: false, + defaultValue: Sequelize.NOW, + }, + }, + options: { + indexes: [ + { + fields: ["user_id"], // BUG: {underscored: true} does not work on indexes + }, + { + fields: ["ip"], + } + ] + } +}; |