# Migrate Azure Database for PostgreSQL: JSON document metadata

Move PostgreSQL data from Azure Database for PostgreSQL to Ample, one component at a time. Destination verified on Ample: a jsonb column with a GIN index queried by path and containment, with an aggregate over matching documents (json=ok).

### Source procedure:
Take a logical backup with `pg_dump -Fc` from an allowed network or private endpoint.  
Not migrated automatically: Microsoft Entra authentication, zone-redundant HA and PITR have no equivalent on the managed database.

### Cutover:
Freeze writes with the user's go-ahead, take the final dump, restore, validate, redeploy with the managed DATABASE_URL, keep the Azure server until confirmed.

### Rollback:
Keep the source untouched until you confirm; nothing at the source is changed or deleted by this guide.

## Steps to Migrate:

1. **Inventory the source**  
   List what Azure Database for PostgreSQL provides beyond the component you are moving. Out of scope here: Microsoft Entra authentication, zone-redundant HA and PITR have no equivalent on the managed database.

2. **Source step 1**  
   Take a logical backup with `pg_dump -Fc` from an allowed network or private endpoint.

3. **Source step 2**  
   Check the engine major version, extensions and server parameters the app depends on.

4. **Source step 3**  
   Restore into a scratch managed database first and compare row counts.

5. **Provision and restore**  
   Deploy the app once so a managed PostgreSQL 16 database exists (or create one with `ample database create --engine postgres`), then restore the dump with `pg_restore` using its connection string; keep migrations idempotent.
   
   ```bash
   ample database create --name <name> --engine postgres
   ```

6. **Validate before cutover**  
   Run the app's own checks and, for data, compare counts and checksums; the example checks are the pattern self-tests (/p/json-document-metadata).

7. **Cut over**  
   Freeze writes with the user's go-ahead, take the final dump, restore, validate, redeploy with the managed DATABASE_URL, keep the Azure server until confirmed.

8. **Rollback**  
   Point DNS or configuration back to the source. The source was never modified; deletion is a separate, user-executed step after validation.

## Prerequisites:
- Authorized access to the Azure Database for PostgreSQL source and its export tooling.
- An inventory of every component in scope and out of scope.
- A validated backup or copy before any cutover.
- An Ample account token with servers:write, databases:read.

## Success Checks:
- Destination app responds on its public URL.
- json-document-metadata check from the destination example.
- Data or object counts and checksums match the source.

## Limitations:
- Documentation only: nothing is executed automatically and no execution binding is offered.
- No full source-product parity is claimed: Microsoft Entra authentication, zone-redundant HA and PITR have no equivalent on the managed database.
- Verified on the node-22 template at s-1vcpu-1gb; region, compliance and request-duration limits are unknown.

## Cost Estimate:
- **Currency:** USD
- **Monthly Amount:** 10.0
- **Components:**  
  - App server: size s-1vcpu-1gb, quantity 1.0, monthly amount 5.0
  - Managed PostgreSQL database: size s-1vcpu-1gb, quantity 1.0, monthly amount 5.0

## Evidence Summary:
- Destination side verified: the Express pattern fixture deployed on Ample and its checks passed.

## Next Actions:
1. Browse the catalog index.
2. Search published recipes by intent, stack and constraints.
3. Prepare a side-effect-free deployment plan for an authorized project.
4. Read the existing agent authentication setup.
5. Browse Azure Database for PostgreSQL.
6. Browse JSON document metadata.
7. Browse Migrate Postgres.
