Skip to content

chore: use new rds #2336

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

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
4 changes: 2 additions & 2 deletions apps/web/app/api/registry/entries/route.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { NextRequest, NextResponse } from 'next/server';
import { getVercelDb } from 'apps/web/src/utils/datastores/rds';
import { getDb } from 'apps/web/src/utils/datastores/rds';
import { getKv } from 'apps/web/src/utils/datastores/kv';
import { logger } from 'apps/web/src/utils/logger';
import { withTimeout } from 'apps/web/app/api/decorators';
Expand All @@ -18,7 +18,7 @@ async function handler(req: NextRequest) {

// Base query for filtering by category if provided
try {
const db = getVercelDb();
const db = getDb();
let baseQuery = db.selectFrom('content');

if (category) {
Expand Down
4 changes: 2 additions & 2 deletions apps/web/app/api/registry/featured/route.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { NextResponse } from 'next/server';
import { getVercelDb } from 'apps/web/src/utils/datastores/rds';
import { getDb } from 'apps/web/src/utils/datastores/rds';
import { getKv } from 'apps/web/src/utils/datastores/kv';
import { logger } from 'apps/web/src/utils/logger';
import { withTimeout } from 'apps/web/app/api/decorators';
Expand All @@ -8,7 +8,7 @@ const PAGE_KEY = 'api.ocs_registry.featured';

async function handler() {
try {
const db = getVercelDb();
const db = getDb();
const content = await db
.selectFrom('content')
.where('is_featured', '=', true)
Expand Down
1 change: 0 additions & 1 deletion apps/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
"@types/three": "0.153.0",
"@vercel/blob": "^0.23.4",
"@vercel/og": "^0.6.2",
"@vercel/postgres-kysely": "^0.8.0",
"base-ui": "0.1.1",
"classnames": "^2.5.1",
"cloudinary": "^2.5.1",
Expand Down
22 changes: 0 additions & 22 deletions apps/web/src/utils/datastores/rds/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { createKysely } from '@vercel/postgres-kysely';
import { Kysely, PostgresDialect } from 'kysely';
import { Pool } from 'pg';
import { isDevelopment } from 'apps/web/src/constants';
Expand Down Expand Up @@ -30,31 +29,10 @@ function createDefaultRDSManager() {
}
}

function createVercelRDSManager() {
try {
return createKysely<Database>();
} catch (error) {
if (isDevelopment) {
console.error('Failed to connect to Vercel RDS', error);
} else {
logger.error('Failed to connect to Vercel Postgres', error);
}
throw new Error(`Failed to connect to Vercel Postgres: ${error}`);
}
}

let db: Kysely<Database> | undefined = undefined;
export function getDb() {
if (!db) {
db = createDefaultRDSManager();
}
return db;
}

let vercelDb: Kysely<Database> | undefined = undefined;
export function getVercelDb() {
if (!vercelDb) {
vercelDb = createVercelRDSManager();
}
return vercelDb;
}
6 changes: 3 additions & 3 deletions apps/web/src/utils/proofs/discount_code_storage.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { getVercelDb } from 'apps/web/src/utils/datastores/rds';
import { getDb } from 'apps/web/src/utils/datastores/rds';

const publicTableName = 'public.basenames_discount_codes';

export async function getDiscountCode(code: string) {
const db = getVercelDb();
const db = getDb();
let query = db.selectFrom(publicTableName).where('code', 'ilike', code);
return query.selectAll().limit(1).execute();
}
Expand All @@ -12,7 +12,7 @@ export async function incrementDiscountCodeUsage(code: string) {
const tableName = publicTableName;

// Perform the update and return the updated row in a single query
const db = getVercelDb();
const db = getDb();
const result = await db
.updateTable(tableName)
.set((eb) => ({
Expand Down
4 changes: 2 additions & 2 deletions apps/web/src/utils/proofs/proofs_storage.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getVercelDb } from 'apps/web/src/utils/datastores/rds';
import { getDb } from 'apps/web/src/utils/datastores/rds';
import { Address } from 'viem';

export enum ProofTableNamespace {
Expand All @@ -15,7 +15,7 @@ export async function getProofsByNamespaceAndAddress(
namespace: ProofTableNamespace,
caseInsensitive = true, // set false for big data sets
) {
const db = getVercelDb();
const db = getDb();
let query = db.selectFrom(proofTableName).where('namespace', '=', namespace.valueOf());

/**
Expand Down
81 changes: 1 addition & 80 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,6 @@ __metadata:
"@typescript-eslint/utils": ^7.8.0
"@vercel/blob": ^0.23.4
"@vercel/og": ^0.6.2
"@vercel/postgres-kysely": ^0.8.0
autoprefixer: ^10.4.13
base-ui: 0.1.1
classnames: ^2.5.1
Expand Down Expand Up @@ -5159,15 +5158,6 @@ __metadata:
languageName: node
linkType: hard

"@neondatabase/serverless@npm:0.7.2":
version: 0.7.2
resolution: "@neondatabase/serverless@npm:0.7.2"
dependencies:
"@types/pg": 8.6.6
checksum: bfcd7e209aae0c0b05cbf40c5cbc105d9cf43a4f65171cee5f2a170132d015a547c5a8ee2b4cd6e963670ebe77eab5fd0db62d1636e816129fa343b1bd8ec141
languageName: node
linkType: hard

"@next/bundle-analyzer@npm:^15.1.6":
version: 15.1.7
resolution: "@next/bundle-analyzer@npm:15.1.7"
Expand Down Expand Up @@ -8432,17 +8422,6 @@ __metadata:
languageName: node
linkType: hard

"@types/pg@npm:8.6.6":
version: 8.6.6
resolution: "@types/pg@npm:8.6.6"
dependencies:
"@types/node": "*"
pg-protocol: "*"
pg-types: ^2.2.0
checksum: ac145553a8ad2f357feacad1bceaf5d6ce904eb9d66233b84c469a2b4fa3738d4ebdf29b7ea45387be2d07f915fd873a229f90a2f766d7c377afa7c41fbcf8d1
languageName: node
linkType: hard

"@types/pg@npm:^8.11.6":
version: 8.11.11
resolution: "@types/pg@npm:8.11.11"
Expand Down Expand Up @@ -9157,29 +9136,6 @@ __metadata:
languageName: node
linkType: hard

"@vercel/postgres-kysely@npm:^0.8.0":
version: 0.8.0
resolution: "@vercel/postgres-kysely@npm:0.8.0"
dependencies:
"@vercel/postgres": 0.8.0
peerDependencies:
kysely: ^0.24.2 || ^0.25.0 || ^0.26.0 || ^0.27.0
checksum: 3e4cb9fa2e4752c7693aefb6f15b946658d68ab38c0dcb9ae74e49f5dad22bf5a6510c4df9d78e3916115d9f1250817f5ed3361615796ec56d5181347a57abe8
languageName: node
linkType: hard

"@vercel/postgres@npm:0.8.0":
version: 0.8.0
resolution: "@vercel/postgres@npm:0.8.0"
dependencies:
"@neondatabase/serverless": 0.7.2
bufferutil: 4.0.8
utf-8-validate: 6.0.3
ws: 8.14.2
checksum: c6e2683bec4df7abd0f9dfc525a62d8eab38bdc64928616b21c507445ca5574bff133ff868e7b20fe653fbca1b55341c3ab7dce6255cc05013eaa60414debd71
languageName: node
linkType: hard

"@vercel/static-config@npm:3.0.0":
version: 3.0.0
resolution: "@vercel/static-config@npm:3.0.0"
Expand Down Expand Up @@ -10651,16 +10607,6 @@ __metadata:
languageName: node
linkType: hard

"bufferutil@npm:4.0.8":
version: 4.0.8
resolution: "bufferutil@npm:4.0.8"
dependencies:
node-gyp: latest
node-gyp-build: ^4.3.0
checksum: 7e9a46f1867dca72fda350966eb468eca77f4d623407b0650913fadf73d5750d883147d6e5e21c56f9d3b0bdc35d5474e80a600b9f31ec781315b4d2469ef087
languageName: node
linkType: hard

"bufferutil@npm:^4.0.8":
version: 4.0.9
resolution: "bufferutil@npm:4.0.9"
Expand Down Expand Up @@ -20288,7 +20234,7 @@ __metadata:
languageName: node
linkType: hard

"pg-types@npm:^2.1.0, pg-types@npm:^2.2.0":
"pg-types@npm:^2.1.0":
version: 2.2.0
resolution: "pg-types@npm:2.2.0"
dependencies:
Expand Down Expand Up @@ -24804,16 +24750,6 @@ __metadata:
languageName: node
linkType: hard

"utf-8-validate@npm:6.0.3":
version: 6.0.3
resolution: "utf-8-validate@npm:6.0.3"
dependencies:
node-gyp: latest
node-gyp-build: ^4.3.0
checksum: 5e21383c81ff7469c1912119ca69d07202d944c73ddd8a54b84dddcc546b939054e5101c78c294e494d206fe93bd43428adc635a0660816b3ec9c8ec89286ac4
languageName: node
linkType: hard

"utf-8-validate@npm:^5.0.2":
version: 5.0.10
resolution: "utf-8-validate@npm:5.0.10"
Expand Down Expand Up @@ -25575,21 +25511,6 @@ __metadata:
languageName: node
linkType: hard

"ws@npm:8.14.2":
version: 8.14.2
resolution: "ws@npm:8.14.2"
peerDependencies:
bufferutil: ^4.0.1
utf-8-validate: ">=5.0.2"
peerDependenciesMeta:
bufferutil:
optional: true
utf-8-validate:
optional: true
checksum: 3ca0dad26e8cc6515ff392b622a1467430814c463b3368b0258e33696b1d4bed7510bc7030f7b72838b9fdeb8dbd8839cbf808367d6aae2e1d668ce741d4308b
languageName: node
linkType: hard

"ws@npm:8.17.1, ws@npm:~8.17.1":
version: 8.17.1
resolution: "ws@npm:8.17.1"
Expand Down