Skip to content

Commit

Permalink
Add env var to control seeding
Browse files Browse the repository at this point in the history
  • Loading branch information
NickPhura committed Nov 22, 2023
1 parent bff9416 commit 66d18c3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
11 changes: 5 additions & 6 deletions database/src/seeds/04_mock_test_data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ import { faker } from '@faker-js/faker';
import random from 'geojson-random';
import { Knex } from 'knex';

// Disable mock data seeding by default, unless manually enabled
const ENABLED = false;
// Disable mock data seeding by default. Set `ENABLE_MOCK_FEATURE_DATA=true` to enable.
const ENABLE_MOCK_FEATURE_SEEDING = Boolean(process.env.ENABLE_MOCK_FEATURE_SEEDING === 'true' || false);
const NUM_MOCK_FEATURE_SUBMISSIONS = Number(process.env.NUM_MOCK_FEATURE_SUBMISSIONS || 0);

/**
* Sample query for performance testing.
Expand Down Expand Up @@ -40,7 +41,7 @@ const ENABLED = false;
* @return {*} {Promise<void>}
*/
export async function seed(knex: Knex): Promise<void> {
if (!ENABLED) {
if (!ENABLE_MOCK_FEATURE_SEEDING) {
return knex.raw(`SELECT null;`); // dummy query to appease knex
}

Expand All @@ -49,9 +50,7 @@ export async function seed(knex: Knex): Promise<void> {
SET SEARCH_PATH = 'biohub','public';
`);

const numSubmissions = 10000; // Number of submissions (ie: surveys)

for (let i = 0; i < numSubmissions; i++) {
for (let i = 0; i < NUM_MOCK_FEATURE_SUBMISSIONS; i++) {
await insertRecord(knex);
}
}
Expand Down
8 changes: 8 additions & 0 deletions env_config/env.docker
Original file line number Diff line number Diff line change
Expand Up @@ -151,3 +151,11 @@ GEOSERVER_ADMIN_PASSWORD=geoserver

ROOT_WEBAPP_REDIRECT=true
TOMCAT_EXTRAS=false

# ------------------------------------------------------------------------------
# Seeding - Development
# ------------------------------------------------------------------------------
# Enable or disable the mock data seeding in '04_mock_test_data.ts'
ENABLE_MOCK_FEATURE_SEEDING=false
# Configure how many feature submission records to seed
NUM_MOCK_FEATURE_SUBMISSIONS=0

0 comments on commit 66d18c3

Please sign in to comment.