Skip to content
Open
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
20 changes: 2 additions & 18 deletions packages/btcindexer/src/db.test.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,9 @@
import * as path from "path";
import { readdir } from "fs/promises";
import { D1Database } from "@cloudflare/workers-types";
import { initDb as initDbShared } from "@gonative-cc/lib/common-setup/db.test";

const MIGRATIONS_PATH = path.resolve(__dirname, "../db/migrations");

export async function initDb(db: D1Database) {
const migrationFiles = await readdir(MIGRATIONS_PATH);
migrationFiles.sort();

for (const filename of migrationFiles) {
if (filename.endsWith(".sql")) {
const file = Bun.file(path.join(MIGRATIONS_PATH, filename));
const migration = await file.text();
const cleanedMigration = migration
.replace(/--.*/g, "")
.replace(/\n/g, " ")
.replace(/\s{2,}/g, " ")
.trim();
if (cleanedMigration.length > 0) {
await db.exec(cleanedMigration);
}
}
}
await initDbShared(db, MIGRATIONS_PATH);
}
3 changes: 2 additions & 1 deletion packages/lib/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"license": "MPL-2.0",
"version": "0.0.1",
"exports": {
"./*": "./src/*.ts"
"./*": "./src/*.ts",
"./common-setup/*": "./src/common-setup/*.ts"
},
"scripts": {
"typecheck": "tsc",
Expand Down
23 changes: 23 additions & 0 deletions packages/lib/src/common-setup/db.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import * as path from "path";
import { readdir } from "fs/promises";
import { D1Database } from "@cloudflare/workers-types";

export async function initDb(db: D1Database, migrationsPath: string) {
const migrationFiles = await readdir(migrationsPath);
migrationFiles.sort();

for (const filename of migrationFiles) {
if (filename.endsWith(".sql")) {
const file = Bun.file(path.join(migrationsPath, filename));
const migration = await file.text();
const cleanedMigration = migration
.replace(/--.*/g, "")
.replace(/\n/g, " ")
.replace(/\s{2,}/g, " ")
.trim();
if (cleanedMigration.length > 0) {
await db.exec(cleanedMigration);
}
}
}
}
2 changes: 1 addition & 1 deletion packages/redeem_solver/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"deploy:prod": "wrangler deploy -c ./wrangler-prod.jsonc",
"typecheck": "tsc",
"cf-typegen": "wrangler types",
"test": "echo no tests"
"test": "bun test"
},
"dependencies": {
"@gonative-cc/lib": "workspace:*",
Expand Down
9 changes: 9 additions & 0 deletions packages/redeem_solver/src/db.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import * as path from "path";
import { D1Database } from "@cloudflare/workers-types";
import { initDb as initDbShared } from "@gonative-cc/lib/common-setup/db.test";

const MIGRATIONS_PATH = path.resolve(__dirname, "../../btcindexer/db/migrations");

export async function initDb(db: D1Database) {
await initDbShared(db, MIGRATIONS_PATH);
}
Loading
Loading