diff --git a/common/data/package.json b/common/data/package.json index 44a8199d3..00f767586 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": "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": { diff --git a/common/data/scripts/postgres.ts b/common/data/scripts/postgres.ts index 8b52e9037..63431fd02 100644 --- a/common/data/scripts/postgres.ts +++ b/common/data/scripts/postgres.ts @@ -17,6 +17,7 @@ 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 () { @@ -24,6 +25,9 @@ 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'] @@ -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`) }() \ No newline at end of file diff --git a/common/data/src/schemas/account.schema.json b/common/data/src/schemas/account.schema.json index dabd7d995..fc4b632f6 100644 --- a/common/data/src/schemas/account.schema.json +++ b/common/data/src/schemas/account.schema.json @@ -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" diff --git a/scripts/local/dev.ts b/scripts/local/dev.ts index c09e05413..f7b002835 100644 --- a/scripts/local/dev.ts +++ b/scripts/local/dev.ts @@ -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