1. MooseStack
  2. Moose Migrate
  3. Externally Managed Lifecycle

On this page

When to UseWhy Model External Tables in MooseStack?Syncing External ModelsConfiguration

Externally Managed

LifeCycle.EXTERNALLY_MANAGED tells MooseStack to interact with existing resources without managing their schema or lifecycle. In this mode, you are fully responsible for creating and maintaining the database schema outside the context of your code.

When to Use

Mark a table EXTERNALLY_MANAGED when you want to connect to an existing database table where the schema is owned by another team, process, or tool (e.g., PeerDB, Debezium, ClickPipes).

Why Model External Tables in MooseStack?

Defining the table lets you write type-safe queries, create Views, Materialized Views, and API endpoints against schemas you don't own while still getting full IDE autocompletion.

Syncing External Models

Because MooseStack doesn't manage the schema, your code definitions must match the database exactly. Mismatches can cause runtime errors.

Use moose db pull to generate Moose OLAP models from your remote database:

moose db pull --clickhouse-url <YOUR_CLICKHOUSE_URL>

Configuration

ExternallyManagedExample.ts
import { Stream, OlapTable, LifeCycle, Key } from "@514labs/moose-lib"; interface ExternalUserData {  userId: Key<string>;  fullName: string;  emailAddress: string;  createdAt: Date;} // Connect to existing database tableconst legacyUserTable = new OlapTable<ExternalUserData>("legacy_users", {  lifeCycle: LifeCycle.EXTERNALLY_MANAGED}); // Connect to existing Kafka topicconst legacyStream = new Stream<ExternalUserData>("legacy_user_stream", {  lifeCycle: LifeCycle.EXTERNALLY_MANAGED,  destination: legacyUserTable});
Local Development Behavior

moose dev WILL CREATE EXTERNALLY_MANAGED tables in your local ClickHouse instance to enable development of queries and views against your schema.

  • Local Updates: Schema changes in code WILL update your local database.
  • No Remote Impact: These changes are NEVER applied to the remote database.
FiveonefourFiveonefour
Fiveonefour Docs
MooseStackTemplates
Changelog
Source506
  • Overview
  • Quick Start
  • Templates / Examples
Fundamentals
  • Moose Runtime
  • MooseDev MCP
  • Data Modeling
MooseStack in your App
  • App / API frameworks
Modules
  • Moose OLAP
  • Moose Streaming
  • Moose Workflows
  • Moose APIs
Deployment & Lifecycle
  • Moose Migrate
    • Migration Modes
    • Automatic Migrations
    • Planned Migrations
    • Plan Reference
    • Executing Migrations
    • moose migrate (CLI)
    • moose prod (Runtime)
    • Lifecycle Management
    • Fully Managed
    • Deletion Protected
    • Externally Managed
    • Advanced Topics
    • Failed Migrations
  • Moose Deploy
Reference
  • API Reference
  • Data Types
  • Table Engines
  • CLI
  • Configuration
  • Observability Metrics
  • Help
  • Changelog
Contribution
  • Documentation
  • Framework