Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
"prisma": "dotenv -e .env -c -- prisma",
"docker": "./scripts/docker-exec-shortcuts.sh",
"ci:integration:test": "yarn pretest && dotenv -e .env.test -- ts-node -O '{\"module\":\"commonjs\"}' node_modules/jest/bin/jest.js tests/integration-tests --forceExit",
"tarDebug": "tar cf debug.tar logs/ paybutton-config.json .env*"
"tarDebug": "tar cf debug.tar logs/ paybutton-config.json .env*",
"updateAllPrices": "./scripts/update-all-prices.sh"
},
"dependencies": {
"@emotion/react": "^11.8.2",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/*
Warnings:

- You are about to alter the column `value` on the `Price` table. The data in that column could be lost. The data in that column will be cast from `Decimal(36,8)` to `Decimal(36,14)`.

*/
-- AlterTable
ALTER TABLE `Price` MODIFY `value` DECIMAL(36, 14) NOT NULL;
2 changes: 1 addition & 1 deletion prisma/migrations/migration_lock.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Please do not edit this file manually
# It should be added in your version-control system (i.e. Git)
# It should be added in your version-control system (e.g., Git)
provider = "mysql"
2 changes: 1 addition & 1 deletion prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ model Quote {

model Price {
id Int @id @default(autoincrement())
value Decimal @db.Decimal(36, 8)
value Decimal @db.Decimal(36, 14)
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
timestamp Int
Expand Down
4 changes: 2 additions & 2 deletions prisma/seeds/prices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import * as fs from 'fs'
import * as path from 'path'
import { promisify } from 'util'

interface PriceFileData extends KeyValueT<string> {
export interface PriceFileData extends KeyValueT<string> {
ticker: string
date: string
priceInCAD: string
Expand Down Expand Up @@ -60,7 +60,7 @@ export async function createPricesFile (): Promise<void> {
console.log(`\n\nstart: ${start.format('HH:mm:ss')}\nfinish: ${finish.format('HH:mm:ss')}\nduration: ${(finish.diff(start) / 1000).toFixed(2)} seconds`)
}

async function getPricesFromFile (): Promise<PriceFileData[]> {
export async function getPricesFromFile (): Promise<PriceFileData[]> {
if (await fileExists(fs, PATH_PRICE_CSV_FILE)) {
const csvContent = await readCsv(fs, PATH_PRICE_CSV_FILE)
const res: PriceFileData[] = []
Expand Down
6 changes: 3 additions & 3 deletions scripts/paybutton-server-start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ yarn || exit 1
# Clear logs

logtime=$(date +%Y-%m-%d@%H:%M)
mv logs/next.log logs/history/next_"$logtime".log
mv logs/jobs.log logs/history/jobs_"$logtime".log
mv logs/ws-server.log logs/history/ws-server_"$logtime".log
[ -e logs/next.log ] && mv logs/next.log logs/history/next_"$logtime".log
[ -e logs/jobs.log ] && mv logs/jobs.log logs/history/jobs_"$logtime".log
[ -e logs/ws-server.log ] && mv logs/ws-server.log logs/history/ws-server_"$logtime".log

if [ "$ENVIRONMENT" = "production" ]; then
yarn prisma migrate deploy || exit 1
Expand Down
9 changes: 9 additions & 0 deletions scripts/update-all-prices.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
set -e

echo Are you sure you want to update all prices? This will affect the database.[y/N]
read ans
if [[ $ans = "Y" || $ans = "y" ]]; then
dotenv -e .env -c -- ts-node -O '{"module":"commonjs"}' -r tsconfig-paths/register ./scripts/updateAllPrices.ts
else
echo Exited.
fi
28 changes: 28 additions & 0 deletions scripts/updateAllPrices.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { createPricesFile, getPricesFromFile, PriceFileData } from '../prisma/seeds/prices'
import { NETWORK_IDS } from 'constants/index'
import { upsertPricesForNetworkId } from '../services/priceService'
import moment from 'moment'

async function updatePricesFromFile (prices: PriceFileData[]): Promise<void> {
for (const price of prices) {
const networkId = NETWORK_IDS[price.ticker]
const priceData = {
Price_in_CAD: price.priceInCAD,
Price_in_USD: price.priceInUSD
}
const timestamp = moment(price.date).unix()
await upsertPricesForNetworkId(
priceData,
networkId,
timestamp
)
}
}

async function run (): Promise<void> {
await createPricesFile()
const prices = await getPricesFromFile()
await updatePricesFromFile(prices)
}

void run()