Skip to content

Commit 6adb666

Browse files
committed
feat: revert multiple schemas setup
1 parent 3978835 commit 6adb666

File tree

11 files changed

+32
-44
lines changed

11 files changed

+32
-44
lines changed

apps/processing/README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@ Available options:
2828
|-----------------------------|--------------------------------------------------------------------------------------------------------------------------------|-----------|----------------------------------|-----------------------------------------------------------------|
2929
| `CHAINS` | JSON array of chain configurations | N/A | Yes | Each chain object requires: `id` (number), `name` (string), `rpcUrls` (string array). Optional: `fetchLimit` (default: 500), `fetchDelayMs` (default: 1000) |
3030
| `DATABASE_URL` | PostgreSQL Data Layer database connection URL | N/A | Yes | |
31-
| `DATABASE_SCHEMA` | PostgreSQL Data Layer database chain-data schema name | public | Yes | |
32-
| `DATABASE_REGISTRIES_SCHEMA` | PostgreSQL Data Layer database registries schema name | public | Yes | |
31+
| `DATABASE_SCHEMA` | PostgreSQL Data Layer database schema name | public | Yes | |
3332
| `INDEXER_GRAPHQL_URL` | GraphQL endpoint for the indexer | N/A | Yes | |
3433
| `INDEXER_ADMIN_SECRET` | Admin secret for indexer authentication | N/A | Yes | |
3534
| `IPFS_GATEWAYS_URL` | Array of IPFS gateway URLs | N/A | Yes | Multiple gateways for redundancy |

apps/processing/src/config/env.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ const baseSchema = z.object({
3030
}, "Chain IDs must be unique"),
3131
DATABASE_URL: z.string(),
3232
DATABASE_SCHEMA: z.string().default("public"),
33-
DATABASE_REGISTRIES_SCHEMA: z.string().default("public"),
3433
INDEXER_GRAPHQL_URL: z.string().url(),
3534
INDEXER_ADMIN_SECRET: z.string(),
3635
PRICING_SOURCE: z.enum(["dummy", "coingecko"]).default("coingecko"),

apps/processing/src/services/sharedDependencies.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ export class SharedDependenciesService {
7676
);
7777
const strategyRepository = new KyselyStrategyRepository(
7878
kyselyDatabase,
79-
env.DATABASE_REGISTRIES_SCHEMA,
79+
env.DATABASE_SCHEMA,
8080
);
8181
const strategyRegistry = await InMemoryCachedStrategyRegistry.initialize(
8282
new Logger({ className: "InMemoryCachedStrategyRegistry" }),

package.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,15 @@
1010
"build": "turbo run build",
1111
"check-types": "turbo run check-types",
1212
"clean": "turbo run clean",
13+
"db:migrate": "pnpm run --filter @grants-stack-indexer/migrations db:migrate",
14+
"db:reset": "pnpm run --filter @grants-stack-indexer/migrations db:reset",
1315
"dev": "turbo run dev",
1416
"format": "turbo run format",
1517
"format:fix": "turbo run format:fix",
1618
"preinstall": "npx only-allow pnpm",
1719
"lint": "turbo run lint",
1820
"lint:fix": "turbo run lint:fix",
19-
"migrate:chain-data": "pnpm run --filter @grants-stack-indexer/migrations migrate:chain-data",
20-
"migrate:registries": "pnpm run --filter @grants-stack-indexer/migrations migrate:registries",
2121
"prepare": "husky",
22-
"reset:chain-data": "pnpm run --filter @grants-stack-indexer/migrations reset:chain-data",
23-
"reset:registries": "pnpm run --filter @grants-stack-indexer/migrations reset:registries",
2422
"start": "turbo run start",
2523
"test": "turbo run test",
2624
"test:cov": "turbo run test:cov",

scripts/migrations/README.md

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,10 @@ This package contains scripts for managing the database schema and migrations.
44

55
## Available Scripts
66

7-
| Script | Description |
8-
| -------------------- | ------------------------------------------------------------ |
9-
| `migrate:chain-data` | Runs all pending database migrations on chainData tables |
10-
| `migrate:registries` | Runs all pending database migrations on registries tables |
11-
| `reset:chain-data` | Drops and recreates the database schema on chainData tables |
12-
| `reset:registries` | Drops and recreates the database schema on registries tables |
7+
| Script | Description |
8+
| ------------ | --------------------------------------- |
9+
| `db:migrate` | Runs all pending database migrations |
10+
| `db:reset` | Drops and recreates the database schema |
1311

1412
## Environment Setup
1513

@@ -39,9 +37,13 @@ pnpm install
3937
To apply all pending migrations:
4038

4139
```bash
42-
pnpm migrate:chain-data --schema=schema_name
40+
pnpm db:migrate --schema=schema_name
4341
```
4442

43+
Optional arguments:
44+
45+
- `--schema` or `-s`: Database schema name where migrations are applied. Defaults to `public`.
46+
4547
This will:
4648

4749
1. Load environment variables
@@ -55,7 +57,7 @@ This will:
5557
To completely reset the database schema:
5658

5759
```bash
58-
pnpm reset:chain-data --schema=schema_name
60+
pnpm db:reset --schema=schema_name
5961
```
6062

6163
**Warning**: This will:
@@ -71,7 +73,7 @@ pnpm reset:chain-data --schema=schema_name
7173
1. Create a new migration file in [`packages/repository/src/migrations`](../../packages//repository/migrations)
7274
2. Name it using the format: `YYYYMMDDTHHmmss_description.ts`
7375
3. Implement the `up` and `down` functions
74-
4. Run `pnpm migrate:chain-data` to apply the new migration
76+
4. Run `pnpm db:migrate` to apply the new migration
7577

7678
Example migration file:
7779

scripts/migrations/package.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,12 @@
1616
"build": "tsc -p tsconfig.build.json",
1717
"check-types": "tsc --noEmit -p ./tsconfig.json",
1818
"clean": "rm -rf dist/",
19+
"db:migrate": "tsx src/migrateDb.script.ts",
20+
"db:reset": "tsx src/resetDb.script.ts",
1921
"format": "prettier --check \"{src,test}/**/*.{js,ts,json}\"",
2022
"format:fix": "prettier --write \"{src,test}/**/*.{js,ts,json}\"",
2123
"lint": "eslint \"{src,test}/**/*.{js,ts,json}\"",
2224
"lint:fix": "pnpm lint --fix",
23-
"migrate:chain-data": "tsx src/migrateDb.script.ts --folder chainData",
24-
"migrate:registries": "tsx src/migrateDb.script.ts --folder registries",
25-
"reset:chain-data": "tsx src/resetDb.script.ts --folder chainData",
26-
"reset:registries": "tsx src/resetDb.script.ts --folder registries",
2725
"test": "vitest run --config vitest.config.ts --passWithNoTests",
2826
"test:cov": "vitest run --config vitest.config.ts --coverage --passWithNoTests"
2927
},

scripts/migrations/src/migrateDb.script.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ configDotenv();
2222
* - DATABASE_URL: PostgreSQL connection string
2323
*
2424
* Script arguments:
25-
* - folder: Folder name to migrate (e.g. "chainData" or "registries")
2625
* - schema: Database schema name where migrations are applied
2726
*
2827
* The script will:
@@ -34,7 +33,7 @@ configDotenv();
3433

3534
export const main = async (): Promise<void> => {
3635
const { DATABASE_URL } = getDatabaseConfigFromEnv();
37-
const { folder, schema } = parseArguments();
36+
const { schema } = parseArguments();
3837

3938
const db = createKyselyDatabase({
4039
connectionString: DATABASE_URL,
@@ -46,7 +45,7 @@ export const main = async (): Promise<void> => {
4645
const migrationResults = await migrateToLatest({
4746
db,
4847
schema,
49-
migrationsFolder: getMigrationsFolder(folder),
48+
migrationsFolder: getMigrationsFolder(),
5049
});
5150

5251
if (migrationResults && migrationResults?.length > 0) {

scripts/migrations/src/migrations/chainData/20241029T120000_initial.ts renamed to scripts/migrations/src/migrations/20241029T120000_initial.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Kysely, sql } from "kysely";
22

3-
import { getSchemaName } from "../../utils/index.js";
3+
import { getSchemaName } from "../utils/index.js";
44

55
/**
66
* The up function is called when you update your database schema to the next version and down when you go back to previous version.

scripts/migrations/src/migrations/registries/20241210T175001_strategy_registry.ts renamed to scripts/migrations/src/migrations/20241210T175001_strategy_registry.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Kysely } from "kysely";
22

3-
import { getSchemaName } from "../../utils/index.js";
3+
import { getSchemaName } from "../utils/index.js";
44

55
/**
66
* The up function is called when you update your database schema to the next version and down when you go back to previous version.

scripts/migrations/src/resetDb.script.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ configDotenv();
2222
* - DATABASE_URL: PostgreSQL connection string
2323
*
2424
* Script arguments:
25-
* - folder: Folder name to migrate (e.g. "chainData" or "registries")
2625
* - schema: Database schema name where migrations are applied
2726
*
2827
* The script will:
@@ -37,7 +36,7 @@ configDotenv();
3736

3837
const main = async (): Promise<void> => {
3938
const { DATABASE_URL } = getDatabaseConfigFromEnv();
40-
const { folder, schema } = parseArguments();
39+
const { schema } = parseArguments();
4140

4241
const db = createKyselyDatabase({
4342
connectionString: DATABASE_URL,
@@ -49,7 +48,7 @@ const main = async (): Promise<void> => {
4948
const resetResults = await resetDatabase({
5049
db,
5150
schema,
52-
migrationsFolder: getMigrationsFolder(folder),
51+
migrationsFolder: getMigrationsFolder(),
5352
});
5453

5554
if (resetResults && resetResults?.length > 0) {

scripts/migrations/src/utils/parsing.ts

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,23 @@ import yargs from "yargs";
44
import { hideBin } from "yargs/helpers";
55
import { z } from "zod";
66

7+
const DEFAULT_SCHEMA = "public";
8+
79
const zodSchema = z.object({
8-
folder: z
10+
schema: z
911
.string()
10-
.refine((value) => ["chainData", "registries"].includes(value), {
11-
message: "Schema name must be either 'chainData' or 'registries'",
12-
})
13-
.describe("Folder name to migrate"),
14-
schema: z.string().describe("Database schema name where migrations are applied"),
12+
.default(DEFAULT_SCHEMA)
13+
.describe("Database schema name where migrations are applied"),
1514
});
1615

1716
export const parseArguments = (): z.infer<typeof zodSchema> => {
1817
return yargs(hideBin(process.argv))
19-
.option("folder", {
20-
type: "string",
21-
demandOption: true,
22-
description: "Folder name to migrate",
23-
})
2418
.option("schema", {
2519
alias: "s",
2620
type: "string",
2721
demandOption: true,
2822
description: "Database schema name where migrations are applied",
23+
default: DEFAULT_SCHEMA,
2924
})
3025
.check((argv) => {
3126
zodSchema.parse(argv);
@@ -34,15 +29,14 @@ export const parseArguments = (): z.infer<typeof zodSchema> => {
3429
.parseSync();
3530
};
3631

37-
export const getMigrationsFolder = (folder: string): string => {
32+
export const getMigrationsFolder = (): string => {
3833
const migrationsFolder = path.join(
3934
path.dirname(new URL(import.meta.url).pathname),
40-
`../migrations/${folder}`,
35+
`../migrations`,
4136
);
42-
console.log("migrationsFolder", migrationsFolder);
4337

4438
if (!existsSync(migrationsFolder)) {
45-
throw new Error(`Migrations folder '${folder}' not found`);
39+
throw new Error(`Migrations folder not found`);
4640
}
4741

4842
return migrationsFolder;

0 commit comments

Comments
 (0)