-
Notifications
You must be signed in to change notification settings - Fork 4
Use @fastify/fastify-postgres. CheckerNetwork/roadmap#220 #341
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 2 commits
31a5f9b
6206573
51bfcad
3717210
973b0da
826d075
e89a63c
26d73c7
2608fdc
c0a95b2
6a76461
f6a0319
59448e4
9423683
97ac2bd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -13,12 +13,12 @@ | |||||||
}, | ||||||||
"dependencies": { | ||||||||
"@filecoin-station/spark-evaluate": "^1.2.0", | ||||||||
"pg": "^8.13.3", | ||||||||
"pg": "^8.14.0", | ||||||||
"postgrator": "^8.0.0" | ||||||||
}, | ||||||||
"standard": { | ||||||||
"env": [ | ||||||||
"mocha" | ||||||||
] | ||||||||
} | ||||||||
} | ||||||||
} | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ping @Goddhi |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
juliangruber marked this conversation as resolved.
Show resolved
Hide resolved
|
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
@@ -1,9 +1,28 @@ | ||||||||||
import { | ||||||||||
getPgPools, | ||||||||||
migrateEvaluateDB, | ||||||||||
migrateStatsDB | ||||||||||
migrateStatsDB, | ||||||||||
getPgPools | ||||||||||
} from '@filecoin-station/spark-stats-db' | ||||||||||
|
||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please undo this change to keep the diff clean There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Alright, noted |
||||||||||
const pgPools = await getPgPools() | ||||||||||
await migrateStatsDB(pgPools.stats) | ||||||||||
await migrateEvaluateDB(pgPools.evaluate) | ||||||||||
const { | ||||||||||
DATABASE_URL, | ||||||||||
EVALUATE_DB_URL | ||||||||||
} = process.env | ||||||||||
|
const { | |
DATABASE_URL, | |
EVALUATE_DB_URL | |
} = process.env |
These constants seem not to be used anywhere. Let's delete them.
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's try to add correct types to migrate functions rather then using @ts-ignore
. Using it should be avoided.
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Likewise, let's please not use @ts-ignore
juliangruber marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
@@ -1,23 +1,26 @@ | ||||||||||
import '../lib/instrument.js' | ||||||||||
import { createApp } from '../lib/app.js' | ||||||||||
import { getPgPools } from '@filecoin-station/spark-stats-db' | ||||||||||
|
||||||||||
const { | ||||||||||
PORT = '8080', | ||||||||||
HOST = '127.0.0.1', | ||||||||||
SPARK_API_BASE_URL = 'https://api.filspark.com/', | ||||||||||
REQUEST_LOGGING = 'true' | ||||||||||
REQUEST_LOGGING = 'true', | ||||||||||
DATABASE_URL, | ||||||||||
EVALUATE_DB_URL | ||||||||||
|
DATABASE_URL, | |
EVALUATE_DB_URL | |
DATABASE_URL = 'postgres://localhost:5432/spark_stats', | |
EVALUATE_DB_URL = 'postgres://localhost:5432/spark_evaluate' |
juliangruber marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
Original file line number | Diff line number | Diff line change | ||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -2,6 +2,7 @@ import * as Sentry from '@sentry/node' | |||||||||||||||
import Fastify from 'fastify' | ||||||||||||||||
import cors from '@fastify/cors' | ||||||||||||||||
import urlData from '@fastify/url-data' | ||||||||||||||||
import fastifyPostgres from '@fastify/postgres' | ||||||||||||||||
|
||||||||||||||||
import { addRoutes } from './routes.js' | ||||||||||||||||
import { addPlatformRoutes } from './platform-routes.js' | ||||||||||||||||
|
@@ -12,18 +13,38 @@ import { addPlatformRoutes } from './platform-routes.js' | |||||||||||||||
/** | ||||||||||||||||
* @param {object} args | ||||||||||||||||
* @param {string} args.SPARK_API_BASE_URL | ||||||||||||||||
* @param {import('@filecoin-station/spark-stats-db').PgPools} args.pgPools | ||||||||||||||||
* @param {Fastify.FastifyLoggerOptions} args.logger | ||||||||||||||||
* @returns | ||||||||||||||||
* @param {string} args.DATABASE_URL - Connection string for stats database | ||||||||||||||||
* @param {string} args.EVALUATE_DB_URL - Connection string for evaluate database | ||||||||||||||||
* @param {import('fastify').FastifyLoggerOptions} args.logger | ||||||||||||||||
* @returns {Promise<import('fastify').FastifyInstance>} | ||||||||||||||||
*/ | ||||||||||||||||
export const createApp = ({ | ||||||||||||||||
export const createApp = async ({ | ||||||||||||||||
SPARK_API_BASE_URL, | ||||||||||||||||
pgPools, | ||||||||||||||||
DATABASE_URL, | ||||||||||||||||
EVALUATE_DB_URL, | ||||||||||||||||
logger | ||||||||||||||||
}) => { | ||||||||||||||||
const app = Fastify({ logger }) | ||||||||||||||||
Sentry.setupFastifyErrorHandler(app) | ||||||||||||||||
|
||||||||||||||||
await app.register(fastifyPostgres, { | ||||||||||||||||
connectionString: DATABASE_URL, | ||||||||||||||||
name: 'stats' | ||||||||||||||||
}) | ||||||||||||||||
|
||||||||||||||||
await app.register(fastifyPostgres, { | ||||||||||||||||
connectionString: EVALUATE_DB_URL, | ||||||||||||||||
name: 'evaluate', | ||||||||||||||||
}) | ||||||||||||||||
|
||||||||||||||||
const pgPools = { | ||||||||||||||||
stats: app.pg.stats, | ||||||||||||||||
evaluate: app.pg.evaluate, | ||||||||||||||||
async end() { | ||||||||||||||||
await app.close() | ||||||||||||||||
} | ||||||||||||||||
} | ||||||||||||||||
|
const pgPools = { | |
stats: app.pg.stats, | |
evaluate: app.pg.evaluate, | |
async end() { | |
await app.close() | |
} | |
} |
I don't see this being used anywhere. If it's not used, let's removed. YAGNI
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is being passed to addRoutes()
and addPlatformRoutes()
below. However, instead of passing pgPools
, the route handlers should access app.pg.stats
etc. directly
Uh oh!
There was an error while loading. Please reload this page.