# Premium DM Cluster ID Decoupling

## Analysis

| Area | Impact | Verification |
| --- | --- | --- |
| `dataflow-service-ng/app/models/premium_dm/worker.go` | Replace `sharedPoolID == dmClusterID` assumption with list-first DM cluster resolution. | Premium DM worker unit tests for single-cluster resolution, create path, multiple clusters, scale-out, and scale-in. |
| `dataflow-service-ng/app/container/container.go` | Provide Snowflake `IDGenerator` to Premium DM worker. | `make app-unit-test-local` |
| `.domain-knowledge/ng-premium-dm.md` | Document that list result is authoritative and no task-level cache is persisted. | Manual review in diff. |

## Dead Code / Cascade Check

- No public API or protobuf change is required.
- `PremiumDMTask.ID` remains the DM task string identifier and is not reused for DM cluster IDs.
- `ListDMClusters(sharedPoolID)` is the authoritative source of DM cluster identity for Premium DM worker reconciliation.

## Execution Steps

1. Inject numeric ID generation into Premium DM worker.
   - Pass the existing Snowflake `IDGenerator` from DI into `NewPremiumDMTaskWorker`.
   - Use generated `uint64` IDs only when creating a brand-new DM cluster.
   - Verify with `go test ./dataflow-service-ng/app/models/premium_dm/...`.

2. Add DM cluster resolution logic.
   - Introduce a helper that resolves a DM cluster from `ListDMClusters`, and finally `CreateDMCluster`.
   - Fail fast when a shared pool has multiple DM clusters instead of guessing.
   - Verify with targeted worker tests for single-cluster resolution and create path.

3. Replace all `sharedPoolID`-as-cluster-ID usages in Premium DM worker.
   - Update scale-out and scale-in flows to use resolved `dmClusterID`.
   - Verify with targeted worker tests for scale-out and delete-time scale-in.

4. Run final verification.
   - Run `make app-unit-test-local`.
   - Expected result: Premium DM tests and the broader local app test suite pass without compilation or migration regressions.

## Risks

- If multiple DM clusters exist in one shared pool, worker operations for that pool will now fail fast instead of guessing, which may surface pre-existing data issues.
- Creating a new cluster now depends on the Snowflake ID generator; DI miswiring would break the create path and should be caught by tests.
