| 56 | ) |
| 57 | |
| 58 | export class MigrateDiff implements Command { |
| 59 | public static new(): MigrateDiff { |
| 60 | return new MigrateDiff() |
| 61 | } |
| 62 | |
| 63 | private static help = format(` |
| 64 | ${ |
| 65 | process.platform === class="st">'win32' ? class="st">'' : class="st">'🔍 ' |
| 66 | }Compares the database schema from two arbitrary sources, and outputs the differences either as a human-readable summary (by default) or an executable script. |
| 67 | |
| 68 | ${green(`prisma migrate diff`)} is a read-only command that does not write to your datasource(s). |
| 69 | ${green(`prisma db execute`)} can be used to execute its ${green(`--script`)} output. |
| 70 | |
| 71 | The command takes a source ${green(`--from-...`)} and a destination ${green(`--to-...`)}. |
| 72 | The source and destination must use the same provider, |
| 73 | e.g. a diff using 2 different providers like PostgreSQL and SQLite is not supported. |
| 74 | |
| 75 | It compares the source with the destination to generate a diff. |
| 76 | The diff can be interpreted as generating a migration that brings the source schema (from) to the shape of the destination schema (to). |
| 77 | The default output is a human readable diff, it can be rendered as SQL using \`--script\` on SQL databases. |
| 78 | |
| 79 | See the documentation for more information ${link(class="st">'https:class="cm">//pris.ly/d/migrate-diff')} |
| 80 | |
| 81 | ${helpOptions} |
| 82 | ${bold(class="st">'Examples')} |
| 83 | |
| 84 | From the configured database to a Prisma datamodel |
| 85 | e.g. roll forward after a migration failed in the middle |
| 86 | ${dim(class="st">'$')} prisma migrate diff \\ |
| 87 | --from-config-datasource \\ |
| 88 | --to-schema=next_datamodel.prisma \\ |
| 89 | --script |
| 90 | |
| 91 | From a Prisma datamodel to the configured database |
| 92 | e.g. roll forward after a migration failed in the middle |
| 93 | ${dim(class="st">'$')} prisma migrate diff \\ |
| 94 | --from-schema=next_datamodel.prisma \\ |
| 95 | --to-config-datasource \\ |
| 96 | --script |
| 97 | |
| 98 | From a Prisma Migrate \`migrations\` directory to the configured database |
| 99 | e.g. generate a migration for a hotfix already applied on production |
| 100 | ${dim(class="st">'$')} prisma migrate diff \\ |
| 101 | --from-migrations ./migrations \\ |
| 102 | --to-config-datasource \\ |
| 103 | --script |
| 104 | |
| 105 | Execute the --script output with \`prisma db execute\` using bash pipe \`|\` |
| 106 | ${dim(class="st">'$')} prisma migrate diff \\ |
| 107 | --from-[...] \\ |
| 108 | --to-[...] \\ |
| 109 | --script | prisma db execute --stdin --url=class="st">"$DATABASE_URL" |
| 110 | |
| 111 | Detect if both sources are in sync, it will exit with exit code 2 if changes are detected |
| 112 | ${dim(class="st">'$')} prisma migrate diff \\ |
| 113 | --exit-code \\ |
| 114 | --from-[...] \\ |
| 115 | --to-[...] |