Files
dcrouter/ts_migrations

@serve.zone/dcrouter-migrations

@serve.zone/dcrouter-migrations is dcrouter's versioned SmartMigration chain for persistent database schema and data transitions. The main dcrouter runtime runs it after the database is ready and before DB-backed managers read collections.

Issue Reporting and Security

For reporting bugs, issues, or security vulnerabilities, please visit community.foss.global/. This is the central community hub for all issue reporting. Developers who sign and comply with our contribution agreement and go through identification can also get a code.foss.global/ account to submit Pull Requests directly.

Install

pnpm add @serve.zone/dcrouter-migrations

If you boot DcRouter, you usually do not install or call this package directly; startup handles it.

API

Export Purpose
createMigrationRunner(db, targetVersion) Builds a configured SmartMigration runner for the supplied Smartdata database and target app version.
IMigrationRunner Minimal runner interface with run().
IMigrationRunResult Result shape logged after a migration run.
import { createMigrationRunner } from '@serve.zone/dcrouter-migrations';

const migration = await createMigrationRunner(db, '13.25.0');
const result = await migration.run();

console.log(result.currentVersionBefore, result.currentVersionAfter);

Current Chain

The current migration chain covers:

  • TargetProfileDoc.targets[].host to TargetProfileDoc.targets[].ip
  • legacy domain source manual to dcrouter
  • legacy DNS record source manual to local
  • route collection unification from StoredRouteDoc to RouteDoc
  • route origin backfill for migrated API routes
  • systemKey backfill for persisted config, email, and DNS routes

Migration Rules

All schema migrations must live in ts_migrations/index.ts as SmartMigration steps. Do not put migration logic in application services, managers, startup hooks, or document classes.

Every step must be idempotent. SmartMigration may re-run steps during skip-forward or resume flows, so an already-migrated database must remain safe.

The .to() version of a step must match the release version that ships the migration so SmartMigration can plan the step correctly.

Collection Name Warning

smartdata uses the exact class name as the MongoDB collection name. Do not lowercase new collection references.

Examples:

Document class MongoDB collection
StoredRouteDoc StoredRouteDoc
TargetProfileDoc TargetProfileDoc
RouteDoc RouteDoc

When writing migrations in ts_migrations/index.ts, use exact class-name casing in calls such as ctx.mongo!.collection('ClassName') and db.listCollections({ name: 'ClassName' }).

Historical migration steps may still reference older lowercased collections from earlier behavior. Do not copy that pattern for new migrations.

When To Use This Package Directly

  • You are testing dcrouter schema transitions without booting the full runtime.
  • You are embedding dcrouter persistence in another process and need the same version chain.
  • You are authoring a migration and want a focused test harness around createMigrationRunner().

Development

This folder is published from the dcrouter monorepo via tspublish.json with order 2.

Useful source entry points:

  • index.ts defines the public runner factory and all migration steps.
  • ../AGENTS.md contains the local migration authoring rules that must be followed.

This repository contains open-source code licensed under the MIT License. A copy of the license can be found in the license file.

Please note: The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.

Trademarks

This project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH or third parties, and are not included within the scope of the MIT license granted herein.

Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines or the guidelines of the respective third-party owners, and any usage must be approved in writing. Third-party trademarks used herein are the property of their respective owners and used only in a descriptive manner, e.g. for an implementation of an API or similar.

Company Information

Task Venture Capital GmbH Registered at District Court Bremen HRB 35230 HB, Germany

For any legal inquiries or further information, please contact us via email at hello@task.vc.

By using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.