Skip to content

Commit

Permalink
Add seed flag to postgres script
Browse files Browse the repository at this point in the history
  • Loading branch information
shanejearley committed Mar 13, 2023
1 parent 2627d3f commit b04c6d2
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 5 deletions.
4 changes: 2 additions & 2 deletions common/data/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
4 changes: 4 additions & 0 deletions common/data/scripts/postgres.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand All @@ -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']

Expand Down
4 changes: 2 additions & 2 deletions scripts/local/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {

Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion services/users/scripts/seed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit b04c6d2

Please sign in to comment.