<commit_before>import { container } from 'core/app.inversify'
import { Table } from 'core/database/interfaces'
import roles from 'core/services/admin/community-roles'
import { TYPES } from 'core/types'
import Knex from 'knex'

const insertRoles = async (knex: Knex, tableName: string) => {
  return knex.batchInsert(
    tableName,
    roles.map((role, index) => {
      return { ...role, id: index + 1, team: 1, rules: JSON.stringify(role.rules) }
    })
  )
}

export class AuthRolesTable extends Table {
  name: string = 'auth_roles'

  bootstrap() {
    return this.knex
      .createTableIfNotExists(this.name, table => {
        table.increments('id')
        table.string('name').notNullable()
        table.text('description')
        table.json('rules').notNullable()
        table
          .integer('team')
          .references('auth_teams.id')
          .onDelete('CASCADE')
        table.unique(['team', 'name'])
        table.timestamps(true, true)
      })
      .then(async created => {
        // Pro submodule have its own seeding for auth roles
        const edition = container.get<string>(TYPES.BotpressEdition)
        if (created && edition !== 'ce') {
          await insertRoles(this.knex, this.name)
        }
        return created
      })
  }
}
<commit_msg>seed db with appropriate roles in ce<commit_after>import { container } from 'core/app.inversify'
import { Table } from 'core/database/interfaces'
import roles from 'core/services/admin/community-roles'
import { TYPES } from 'core/types'
import Knex from 'knex'

const insertRoles = async (knex: Knex, tableName: string) => {
  return knex.batchInsert(
    tableName,
    roles.map((role, index) => {
      return { ...role, id: index + 1, team: 1, rules: JSON.stringify(role.rules) }
    })
  )
}

export class AuthRolesTable extends Table {
  name: string = 'auth_roles'

  bootstrap() {
    return this.knex
      .createTableIfNotExists(this.name, table => {
        table.increments('id')
        table.string('name').notNullable()
        table.text('description')
        table.json('rules').notNullable()
        table
          .integer('team')
          .references('auth_teams.id')
          .onDelete('CASCADE')
        table.unique(['team', 'name'])
        table.timestamps(true, true)
      })
      .then(async created => {
        // Pro submodule have its own seeding for auth roles
        const edition = container.get<string>(TYPES.BotpressEdition)
        if (created && edition === 'ce') {
          await insertRoles(this.knex, this.name)
        }
        return created
      })
  }
}

{'fraction_non_alphanumeric': 0.13554100885637274, 'fraction_numerical': 0.0015402387370042356, 'mean_word_length': 2.6133518776077884, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5522405', 'n_tokens_mistral': 805, 'n_tokens_neox': 798, 'n_words': 184}