user.ts 972 B

12345678910111213141516171819202122232425262728293031323334
  1. import * as 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("verification_expires");
  25. table.string("verification_token");
  26. table
  27. .boolean("verified")
  28. .notNullable()
  29. .defaultTo(false);
  30. table.timestamps(false, true);
  31. });
  32. }
  33. }