user.ts 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. import { Knex } from "knex";
  2. export async function createUserTable(knex: Knex) {
  3. const hasTable = await knex.schema.hasTable("users");
  4. if (!hasTable) {
  5. await knex.schema.createTable("users", table => {
  6. table.increments("id").primary();
  7. table.string("apikey");
  8. table
  9. .boolean("banned")
  10. .notNullable()
  11. .defaultTo(false);
  12. table
  13. .integer("banned_by_id")
  14. .references("id")
  15. .inTable("users");
  16. table.specificType("cooldowns", "timestamptz[]");
  17. table
  18. .string("email")
  19. .unique()
  20. .notNullable();
  21. table.string("password").notNullable();
  22. table.dateTime("reset_password_expires");
  23. table.string("reset_password_token");
  24. table.dateTime("change_email_expires");
  25. table.string("change_email_token");
  26. table.string("change_email_address");
  27. table.dateTime("verification_expires");
  28. table.string("verification_token");
  29. table
  30. .boolean("verified")
  31. .notNullable()
  32. .defaultTo(false);
  33. table.timestamps(false, true);
  34. });
  35. }
  36. }