dummy_domains.js 790 B

123456789101112131415161718192021222324252627282930313233
  1. const nanoid = require("nanoid");
  2. const { v4: uuid } = require("uuid");
  3. function createDomain() {
  4. return {
  5. address: nanoid(Math.floor(Math.random() * 10) + 10) + ".com",
  6. homepage: Math.random() > 0.7 ? nanoid(Math.floor(Math.random() * 10) + 3) + ".com" : null,
  7. banned: Math.random() < 0.05,
  8. user_id: Math.random() > 0.2 ? Math.floor(Math.random() * 1_000_000) : null,
  9. uuid: uuid(),
  10. }
  11. }
  12. /**
  13. * @param { import("knex").Knex } knex
  14. * @returns { Promise<void> }
  15. */
  16. async function seed(knex) {
  17. // creating domains
  18. let domains = [];
  19. for (let i = 0; i < 1_000_000; ++i) {
  20. domains.push(createDomain());
  21. if (i % 1000 === 0) {
  22. await knex.batchInsert("domains", domains, domains.length);
  23. domains = [];
  24. }
  25. }
  26. };
  27. module.exports = {
  28. seed,
  29. }