kutt/server/models/user.model.js

45 lines
1.2 KiB
JavaScript
Raw Permalink Normal View History

2024-11-19 07:58:57 +03:30
const { ROLES } = require("../consts");
2024-08-11 18:41:03 +03:30
async function createUserTable(knex) {
const hasTable = await knex.schema.hasTable("users");
if (!hasTable) {
await knex.schema.createTable("users", table => {
table.increments("id").primary();
table.string("apikey");
table
.boolean("banned")
.notNullable()
.defaultTo(false);
table
.integer("banned_by_id")
2024-10-07 14:37:36 +03:30
.unsigned()
.references("id")
.inTable("users");
table
.string("email")
.unique()
.notNullable();
2024-11-19 07:58:57 +03:30
table
.enu("role", [ROLES.USER, ROLES.ADMIN])
.notNullable()
.defaultTo(ROLES.USER);
table.string("password").notNullable();
table.dateTime("reset_password_expires");
table.string("reset_password_token");
2020-09-19 18:02:32 +04:30
table.dateTime("change_email_expires");
table.string("change_email_token");
table.string("change_email_address");
table.dateTime("verification_expires");
table.string("verification_token");
table
.boolean("verified")
.notNullable()
.defaultTo(false);
table.timestamps(false, true);
});
}
}
2024-08-11 18:41:03 +03:30
module.exports = {
createUserTable
};