`migra` is written in Python so you need to install it with `pip`, the Python Package Manager (don't worry, you don't need to know or use any Python to use the `migra` command).
1. Make sure you have [pip](https://pip.pypa.io/en/stable/installing/) properly installed.
Migra will then generate whatever SQL is required to change the schema of database `alpha` to match database `beta`.
If the two database schemas match exactly, you'll get empty output, because no changes are required. This functions like the well-known [diff command](https://en.wikipedia.org/wiki/Diff_utility), which also returns empty output when comparing two identical files.
### Warning
Don't blindly copy-and-paste the output of the `migra` command.
`migra` features a safeguard against generation of dangerous statements. If the command generates a drop statement, `migra` will exit with an error. If you're sure you want the drop statement(s), you can turn off this safeguard behaviour with the `--unsafe` flag:
If you're making changes to a serious production database, use a copy of it for these steps instead so you're not changing your production environment until you intend to.
You can make a schema-only dump of your PostgreSQL database with the following command:
Get the connection string of the database you want to make changes to. `migra` needs to connect to this database so it can analyse the database's schema.
2. Prepare a second PostgreSQL database. This database needs to have the new/desired/target schema. You might create a temporary database and set it up for this purpose.
3. Generate a migration script using the following command (substituting your own connection strings):
4. Carefully review the migration script in `migration_script.sql`
Consider in particular:
- The generated script may result in data loss from your database when you apply this script. Consider if you intend for this to happen or if you need to add statements to copy data out of the relevant tables/columns before you drop them forever.
- Some migration operations can take a long time and cause interruptions and downtime, particularly when involving tables containing large amounts of data..