Skip to content

Commit 3ff4177

Browse files
authored
feat: refactor pg classes, switch to postgres.js (#1148)
* refactor: split postgres-store into several files * refactor: inherit all from PgStore * refactor: start using PgStore everywhere * refactor: fix test imports * refactor: restore notifier into PgStore * refactor: rename to PgWriteStore * fix: tests and lint * fix: unused exports * refactor: pg-store converted * refactor: pg-write-store * refactor: use legacy pg for event requests, notifier and migrations * refactor: update tests * refactor: tx insert mode * refactor: first test passing * refactor: transformed some inserts * refactor: transform all inserts * refactor: fix token-tests * refactor: some more tests fixed * fix: more tests * fix: nasty mempool query * fix: microblock hash test * fix: events weird test * fix: api tests all passing * fix: mb tests * fix: bns code * fix: datastore connection tests * fix: rosetta, bns, token tests * fix: faucet write db * fix: write store to api server for faucet * style: cleanup * fix: faucet launch * fix: upgrade postgres * fix: test launch * fix: remove type transform * refactor: go back to buffer fields * fix: insert numeric as string so values can fit * refactor: move all types to common.ts * style: comments * fix: rosetta cli tests * fix: undo launch custom * refactor: bytea type, api tests pass * fix: pg uri test * chore: define PgNumeric type * style: sql object references * style: clean up tx events query * style: add explicit PgJsonb type * feat: dont parse into buffer from pg * fix: datastore tests * fix: rosetta tests * fix: bns tests * fix: microblock tests * chore: add nvmrc set to v16.15.0 * chore: update package-lock.json * chore: restore vscode config * chore: shorten poll connection name to avoid hitting pg limits * fix: remove returning statements when not required, use count instead * fix: nvmrc back to v16 * fix: pool max env config * refactor: move `PgNotifier` to use postgres lib (#1168) * refactor: use postgres instead of pg-listen * chore: remove pg-listen dependency * fix: update to latest postgres lib * fix: pool max env config * fix: re-throw connection errors
1 parent 7747a9b commit 3ff4177

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+8801
-9596
lines changed

.vscode/launch.json

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,48 @@
206206
"preLaunchTask": "stacks-node:deploy-dev",
207207
"postDebugTask": "stacks-node:stop-dev"
208208
},
209+
{
210+
"type": "node",
211+
"request": "launch",
212+
"name": "Jest: rosetta-cli-data",
213+
"program": "${workspaceFolder}/node_modules/.bin/jest",
214+
"args": [
215+
"--testTimeout=3600000",
216+
"--runInBand",
217+
"--no-cache",
218+
"--config",
219+
"${workspaceRoot}/jest.config.rosetta-cli-data.js"
220+
],
221+
"outputCapture": "std",
222+
"console": "integratedTerminal",
223+
"preLaunchTask": "stacks-node:deploy-dev",
224+
"postDebugTask": "stacks-node:stop-dev",
225+
"env": {
226+
"NODE_ENV": "development",
227+
"STACKS_CHAIN_ID": "0x80000000"
228+
}
229+
},
230+
{
231+
"type": "node",
232+
"request": "launch",
233+
"name": "Jest: rosetta-cli-construction",
234+
"program": "${workspaceFolder}/node_modules/.bin/jest",
235+
"args": [
236+
"--testTimeout=3600000",
237+
"--runInBand",
238+
"--no-cache",
239+
"--config",
240+
"${workspaceRoot}/jest.config.rosetta-cli-construction.js"
241+
],
242+
"outputCapture": "std",
243+
"console": "integratedTerminal",
244+
"preLaunchTask": "stacks-node:deploy-dev",
245+
"postDebugTask": "stacks-node:stop-dev",
246+
"env": {
247+
"NODE_ENV": "development",
248+
"STACKS_CHAIN_ID": "0x80000000"
249+
}
250+
},
209251
{
210252
"type": "node",
211253
"request": "launch",

package-lock.json

Lines changed: 14 additions & 79 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@
133133
"pg": "8.7.1",
134134
"pg-copy-streams": "5.1.1",
135135
"pg-cursor": "2.7.1",
136-
"pg-listen": "1.7.0",
136+
"postgres": "github:porsager/postgres#master",
137137
"prom-client": "14.0.1",
138138
"rpc-bitcoin": "2.0.0",
139139
"socket.io": "4.4.0",

src/api/controllers/cache-controller.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { RequestHandler, Request, Response } from 'express';
22
import * as prom from 'prom-client';
33
import { logger } from '../../helpers';
4-
import { DataStore } from '../../datastore/common';
54
import { asyncHandler } from '../async-handler';
5+
import { PgStore } from '../../datastore/pg-store';
66

77
const CACHE_OK = Symbol('cache_ok');
88

@@ -161,7 +161,7 @@ export function parseIfNoneMatchHeader(
161161
* returns a string which can be used later for setting the cache control `ETag` response header.
162162
*/
163163
async function checkETagCacheOK(
164-
db: DataStore,
164+
db: PgStore,
165165
req: Request,
166166
etagType: ETagType
167167
): Promise<ETag | undefined | typeof CACHE_OK> {
@@ -219,7 +219,7 @@ async function checkETagCacheOK(
219219
* ```
220220
*/
221221
export function getETagCacheHandler(
222-
db: DataStore,
222+
db: PgStore,
223223
etagType: ETagType = ETagType.chainTip
224224
): RequestHandler {
225225
const requestHandler = asyncHandler(async (req, res, next) => {
@@ -240,7 +240,7 @@ export function getETagCacheHandler(
240240
return requestHandler;
241241
}
242242

243-
async function calculateETag(db: DataStore, etagType: ETagType): Promise<ETag | undefined> {
243+
async function calculateETag(db: PgStore, etagType: ETagType): Promise<ETag | undefined> {
244244
switch (etagType) {
245245
case ETagType.chainTip:
246246
const chainTip = await db.getUnanchoredChainTip();

0 commit comments

Comments
 (0)