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
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.