# Migrations

Transform options and partial results.

[Read the migrations guide](/docs/migrations/). Signatures below come from the published SDK declarations. Access SDK services through `db`; use their constructors only when integrating at a lower level.

## MigrationOptions


```ts
interface MigrationOptions {
  dryRun?: boolean;
  queue?: boolean;
  signal?: AbortSignal;
}
```

## MigrationResult


```ts
interface MigrationResult<T extends object> {
  examined: number;
  changed: number;
  rows: Row<T>[];
  receipts: WriteReceipt[];
}
```

## NostrbaseMigrations


```ts
/** Rewrites only records owned by the current signer. Run a dry run to inspect changes first. */
declare class NostrbaseMigrations<DB extends SchemaShape<DB>> {}
```

### constructor


```ts
constructor(host: MigrationHost<DB>);
```

### run


```ts
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


```ts
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>[];
  }>;
}
```
