Skip to content

Commit 2cc2459

Browse files
committed
feat: migrate default postgres schema
- Migrate schema from public to stacks-blockchain-api. BREAKING CHANGE: This change will require resyncing from genesis
1 parent 32f879f commit 2cc2459

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

.env

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ PG_PORT=5490
33
PG_USER=postgres
44
PG_PASSWORD=postgres
55
PG_DATABASE=stacks_blockchain_api
6-
PG_SCHEMA=public
6+
PG_SCHEMA=stacks_blockchain_api
77
PG_SSL=false
88
# Idle connection timeout in seconds, defaults to 30
99
# PG_IDLE_TIMEOUT=30

tests/event-replay/import-export.test.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { exportEventsAsTsv, importEventsFromTsv } from '../../src/event-replay/e
77
import { startEventServer } from '../../src/event-stream/event-server';
88
import { httpPostRequest } from '../../src/helpers';
99
import { useWithCleanup } from '../api/test-helpers';
10-
import { migrate } from '../utils/test-helpers';
10+
import { createSchema, migrate } from '../utils/test-helpers';
1111
import { PgSqlClient, dangerousDropAllTables, databaseHasData } from '@hirosystems/api-toolkit';
1212
import { getConnectionArgs } from '../../src/datastore/connection';
1313

@@ -27,7 +27,9 @@ describe('import/export tests', () => {
2727
});
2828

2929
test('event import and export cycle - remote', async () => {
30+
const args = getConnectionArgs();
3031
// Import from mocknet TSV
32+
await createSchema(args);
3133
await importEventsFromTsv('tests/event-replay/tsv/mocknet.tsv', 'archival', true, true);
3234
const chainTip = await db.getChainTip(db.sql);
3335
expect(chainTip.block_height).toBe(28);
@@ -60,7 +62,9 @@ describe('import/export tests', () => {
6062
});
6163

6264
test('event import and export cycle - local', async () => {
65+
const args = getConnectionArgs();
6366
// Import from mocknet TSV
67+
await createSchema(args);
6468
await importEventsFromTsv('tests/event-replay/tsv/mocknet.tsv', 'archival', true, true);
6569
const chainTip = await db.getChainTip(db.sql);
6670
expect(chainTip.block_height).toBe(28);

tests/utils/test-helpers.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,25 @@ import { CoreRpcPoxInfo, StacksCoreRpcClient } from '../../src/core-rpc/client';
4545
import { DbBlock, DbTx, DbTxStatus } from '../../src/datastore/common';
4646
import { PgWriteStore } from '../../src/datastore/pg-write-store';
4747
import { BitcoinAddressFormat, ECPair, getBitcoinAddressFromKey } from '../../src/ec-helpers';
48-
import { coerceToBuffer, connectPostgres, runMigrations, timeout } from '@hirosystems/api-toolkit';
48+
import {
49+
coerceToBuffer,
50+
connectPostgres,
51+
PgConnectionArgs,
52+
runMigrations,
53+
timeout,
54+
} from '@hirosystems/api-toolkit';
4955
import { MIGRATIONS_DIR } from '../../src/datastore/pg-store';
5056
import { getConnectionArgs } from '../../src/datastore/connection';
5157
import { AddressStxBalance } from '../../src/api/schemas/entities/addresses';
5258
import { ServerStatusResponse } from '../../src/api/schemas/responses/responses';
5359

5460
export async function migrate(direction: 'up' | 'down') {
5561
const connArgs = getConnectionArgs();
62+
await createSchema(connArgs);
63+
await runMigrations(MIGRATIONS_DIR, direction, connArgs);
64+
}
65+
66+
export async function createSchema(connArgs: PgConnectionArgs) {
5667
if (typeof connArgs !== 'string' && connArgs.schema) {
5768
const sql = await connectPostgres({
5869
usageName: 'tests-migrations-setup',
@@ -61,7 +72,6 @@ export async function migrate(direction: 'up' | 'down') {
6172
await sql`CREATE SCHEMA IF NOT EXISTS ${sql(connArgs.schema)}`;
6273
await sql.end();
6374
}
64-
await runMigrations(MIGRATIONS_DIR, direction, connArgs);
6575
}
6676

6777
export interface TestEnvContext {

0 commit comments

Comments
 (0)