From b04c6d235a23be4d0560d10dcf49b3bdd2b0db8a Mon Sep 17 00:00:00 2001 From: Shane Earley Date: Mon, 13 Mar 2023 13:11:32 -0400 Subject: [PATCH] Add seed flag to postgres script --- common/data/package.json | 4 ++-- common/data/scripts/postgres.ts | 4 ++++ scripts/local/dev.ts | 4 ++-- services/users/scripts/seed.ts | 2 +- 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/common/data/package.json b/common/data/package.json index 1bfa10645..8c034d543 100644 --- a/common/data/package.json +++ b/common/data/package.json @@ -6,8 +6,8 @@ "build": "echo '@casimir/data build not specified. Disregard this warning and any listed errors above if @casimir/types is not needed for the current project build.' && exit 0", "clean:postgres": "ts-node --transpile-only scripts/clean.ts", "configure:python": "poetry install && poetry run ipython kernel install --user --name=casimir-data", - "dev:postgres": "ts-node --transpile-only scripts/postgres.ts --clean \"$npm_config_clean\" --tables \"$npm_config_tables\"", - "watch:postgres": "ts-node-dev --watch src --respawn --transpile-only scripts/postgres.ts --clean \"$npm_config_clean\" --tables \"$npm_config_tables\"", + "dev:postgres": "ts-node --transpile-only scripts/postgres.ts --clean \"$npm_config_clean\" --seed \"$npm_config_seed\" --tables \"$npm_config_tables\"", + "watch:postgres": "ts-node-dev --watch src --respawn --transpile-only scripts/postgres.ts --clean \"$npm_config_clean\" --seed \"$npm_config_seed\" --tables \"$npm_config_tables\"", "test": "echo \"Error: no test specified\" && exit 1" }, "dependencies": { diff --git a/common/data/scripts/postgres.ts b/common/data/scripts/postgres.ts index 8e8dc37cc..d07ca636d 100644 --- a/common/data/scripts/postgres.ts +++ b/common/data/scripts/postgres.ts @@ -18,6 +18,7 @@ const tableSchemas = { * * Arguments: * --clean: delete existing pgdata before deploy (optional, i.e., --clean) + * --seed: seed database with resources (optional, i.e., --seed=user) * --tables: tables to deploy (optional, i.e., --tables=accounts,users) */ void async function () { @@ -28,6 +29,9 @@ void async function () { /** Default to keep data */ const clean = argv.clean === true || argv.clean === 'true' + /** Default to no db seed or seed user resources if set vaguely */ + const seed = argv.seed === 'true' || argv.seed === true ? 'user' : argv.seed === 'false' ? false : argv.seed + /** Default to all tables */ const tables = argv.tables ? argv.tables.split(',') : ['accounts', 'nonces', 'users'] diff --git a/scripts/local/dev.ts b/scripts/local/dev.ts index bae3773eb..0ab526375 100644 --- a/scripts/local/dev.ts +++ b/scripts/local/dev.ts @@ -11,7 +11,7 @@ import { loadCredentials, getSecret, spawnPromise } from '@casimir/helpers' * --fork: fork name (optional, i.e., --fork=goerli) * --mock: mock services (optional, i.e., --mock=true) * --network: network name (optional, i.e., --network=goerli) - * --seed: seed database (optional, i.e., --seed=true) + * --seed: seed database with resources (optional, i.e., --seed=user) */ void async function () { @@ -69,7 +69,7 @@ void async function () { if (mock) { /** Mock postgres database */ $`npm run watch:postgres --clean ${clean} --seed ${seed} --tables=${tables.join(',')} --workspace @casimir/data` - // $`npm run dev:postgres --clean --tables=${tables.join(',')} --workspace @casimir/data` + // $`npm run dev:postgres --clean --seed ${seed} --tables=${tables.join(',')} --workspace @casimir/data` /** Mock services */ let port = 4000 diff --git a/services/users/scripts/seed.ts b/services/users/scripts/seed.ts index 249fb5ede..e26175466 100644 --- a/services/users/scripts/seed.ts +++ b/services/users/scripts/seed.ts @@ -30,7 +30,7 @@ void async function () { if (resources?.length) { console.log(`Seeding ${resources.length} ${plural} to API...`) - /** Seed resources with users API */ + /** Seed Account or User resources with users API */ const port = process.env.PUBLIC_USERS_PORT || 4000 const seed = await fetch(`http://localhost:${port}/seed/${plural}`, { method: 'POST',