Skip to content

Commit

Permalink
Add clean back to postgres script options
Browse files Browse the repository at this point in the history
  • Loading branch information
shanejearley committed Mar 14, 2023
1 parent 89037ab commit 55ffa1f
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 15 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": "ts-node --transpile-only scripts/clean.ts",
"configure:python": "poetry install && poetry run ipython kernel install --user --name=casimir-data",
"dev": "ts-node --transpile-only scripts/postgres.ts --tables \"$npm_config_tables\"",
"watch": "ts-node-dev --watch src --respawn --transpile-only scripts/postgres.ts --tables \"$npm_config_tables\"",
"dev": "ts-node --transpile-only scripts/postgres.ts --clean \"$npm_config_clean\" --tables \"$npm_config_tables\"",
"watch": "ts-node-dev --watch src --respawn --transpile-only scripts/postgres.ts --clean \"$npm_config_clean\" --tables \"$npm_config_tables\"",
"test": "echo \"Error: no test specified\" && exit 1"
},
"dependencies": {
Expand Down
11 changes: 8 additions & 3 deletions common/data/scripts/postgres.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,17 @@ const tableSchemas = {
* Run a local postgres database with the given tables.
*
* Arguments:
* --clean: clean the database before starting (optional, i.e., --clean)
* --tables: tables to deploy (optional, i.e., --tables=accounts,users)
*/
void async function () {

/** Parse command line arguments */
const argv = minimist(process.argv.slice(2))

/** Default to clean services and data */
const clean = argv.clean !== 'false' || argv.clean !== false

/** Default to all tables */
const tables = argv.tables ? argv.tables.split(',') : ['accounts', 'nonces', 'users']

Expand All @@ -38,11 +42,12 @@ void async function () {
console.log(`${schema.getTitle()} JSON schema parsed to SQL:`)
console.log(postgresTable)

// Todo if file exists, make alter statements to reflect schema changes

fs.writeFileSync(`${sqlDir}/${table}.sql`, postgresTable)
}

/** Start local database */
/** Start or restart local database */
if (clean) {
await run('npm run clean --workspace @casimir/data')
}
await run(`docker compose -p casimir-data -f ${resources}/docker-compose.yaml up -d`)
}()
4 changes: 0 additions & 4 deletions common/data/src/schemas/account.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,6 @@
"type": "array",
"description": "The account transactions"
},
"updated_at": {
"type": "string",
"description": "The account last update date in ISO 8601 format"
},
"wallet": {
"type": "string",
"description": "The account wallet provider"
Expand Down
8 changes: 2 additions & 6 deletions scripts/local/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,10 @@ void async function () {
const { chains, services, tables } = apps[app as keyof typeof apps]

if (mock) {

/** Mock postgres database */
if (clean) {
await run('npm run clean --workspace @casimir/data')
}
$`npm run watch --tables=${tables.join(',')} --workspace @casimir/data`
$`npm run watch --clean=${clean} --tables=${tables.join(',')} --workspace @casimir/data`
/** Comment out line above and uncomment line below when schemas are stable */
// $`npm run dev --tables=${tables.join(',')} --workspace @casimir/data`
// $`npm run dev --clean=${clean} --tables=${tables.join(',')} --workspace @casimir/data`

/** Mock services */
let port = 4000
Expand Down

0 comments on commit 55ffa1f

Please sign in to comment.