Read the migrations guide. Signatures below come from the published SDK declarations. Access SDK services through db; use their constructors only when integrating at a lower level.
MigrationOptions
interface MigrationOptions {
dryRun?: boolean;
queue?: boolean;
signal?: AbortSignal;
}
MigrationResult
interface MigrationResult<T extends object> {
examined: number;
changed: number;
rows: Row<T>[];
receipts: WriteReceipt[];
}
NostrbaseMigrations
/** Rewrites only records owned by the current signer. Run a dry run to inspect changes first. */
declare class NostrbaseMigrations<DB extends SchemaShape<DB>> {}
constructor
constructor(host: MigrationHost<DB>);
run
run<K extends keyof DB & string, Old extends object = DB[K]>(
table: K,
transform: (data: Old, row: Row<Old>) => DB[K] | null | Promise<DB[K] | null>,
options?: MigrationOptions,
): Promise<Result<MigrationResult<DB[K]>>>;
Supporting declarations
These types appear in public signatures but are not package exports.
MigrationHost
interface MigrationHost<DB extends SchemaShape<DB>> {
namespace: string;
auth: {
requireSigner(): Promise<{
signer: Signer;
session: {
user: {
pubkey: string;
};
};
}>;
};
from<K extends keyof DB & string>(table: K): QueryBuilder<DB[K]>;
definition<T extends object>(table: string): TableDefinition<T> | undefined;
ready(): Promise<void>;
assertTable(table: string): void;
readTable<T extends object>(
table: string,
state: QueryState,
authors: string[],
definition: TableDefinition<T>,
): Promise<{
rows: Row<T>[];
}>;
}