> For the complete documentation index, see [llms.txt](https://docs.scrt.network/secret-network-documentation/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.scrt.network/secret-network-documentation/development/development-concepts/contract-migration/contract-migration-flow-from-v1.21/migration-logic.md).

# Migration Logic

#### Migration Scenarios

| Admin           | RequireGovernance | Behavior                                                        |
| --------------- | ----------------- | --------------------------------------------------------------- |
| ""              | false             | ❌ Not upgradable                                                |
| GovernanceProxy | true              | ✅ Governance-only migration (requires GovernanceProxy contract) |
| Admin           | false             | ✅ Admin-only migration                                          |
| Admin           | true              | ✅ Admin + governance required                                   |

#### Governance-Only Migration Pattern

For contracts that should only be upgradable through governance (no admin), a special migration contract pattern is used:

**The GovernanceProxy Contract Pattern**

1. **Deploy GovernanceProxy Contract**: A simple contract that can execute migration messages
2. **Set Admin**: Set the GovernanceProxy contract as admin of the target contract
3. **Enable Governance**: Set require\_governance = true on the target contract
4. **Migration Flow:**
   1. Governance proposal authorizes migration
   2. Anyone can call GovernanceProxy contract to execute the migration
   3. GovernanceProxy contract calls the migration message

**The example of GovernanceProxy Contract Implementation**&#x20;

```rust
#[entry_point]
pub fn execute(
    _deps: DepsMut,
    _env: Env,
    _info: MessageInfo,
    msg: ExecuteMsg,
) -> StdResult<Response> {
    match msg {
        ExecuteMsg::MigrateContract {
            contract_addr,
            new_code_id,
            migrate_msg,
            code_hash,
        } => {
            let migrate_msg = CosmosMsg::Wasm(WasmMsg::Migrate {
                contract_addr: contract_addr.clone(),
                code_id: new_code_id,
                msg: migrate_msg,                
                code_hash: code_hash,
            });

            Ok(Response::new()
                .add_message(migrate_msg)
                .add_attribute("method", "migrate_contract")
                .add_attribute("contract_addr", contract_addr)
                .add_attribute("new_code_id", new_code_id.to_string()))
        }
    }
}
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.scrt.network/secret-network-documentation/development/development-concepts/contract-migration/contract-migration-flow-from-v1.21/migration-logic.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
