| 20 | import { printDatasource } from class="st">'../utils/printDatasource' |
| 21 | |
| 22 | export class MigrateResolve implements Command { |
| 23 | public static new(): MigrateResolve { |
| 24 | return new MigrateResolve() |
| 25 | } |
| 26 | |
| 27 | private static help = format(` |
| 28 | Resolve issues with database migrations in deployment databases: |
| 29 | - recover from failed migrations |
| 30 | - baseline databases when starting to use Prisma Migrate on existing databases |
| 31 | - reconcile hotfixes done manually on databases with your migration history |
| 32 | |
| 33 | Run class="st">"prisma migrate status" to identify if you need to use resolve. |
| 34 | |
| 35 | Read more about resolving migration history issues: ${link(class="st">'https:class="cm">//pris.ly/d/migrate-resolve')} |
| 36 | |
| 37 | ${bold(class="st">'Usage')} |
| 38 | |
| 39 | ${dim(class="st">'$')} prisma migrate resolve [options] |
| 40 | |
| 41 | The datasource URL configuration is read from the Prisma config file (e.g., ${italic(class="st">'prisma.config.ts')}). |
| 42 | |
| 43 | ${bold(class="st">'Options')} |
| 44 | |
| 45 | -h, --help Display this help message |
| 46 | --config Custom path to your Prisma config file |
| 47 | --schema Custom path to your Prisma schema |
| 48 | --applied Record a specific migration as applied |
| 49 | --rolled-back Record a specific migration as rolled back |
| 50 | |
| 51 | ${bold(class="st">'Examples')} |
| 52 | |
| 53 | Update migrations table, recording a specific migration as applied |
| 54 | ${dim(class="st">'$')} prisma migrate resolve --applied 20201231000000_add_users_table |
| 55 | |
| 56 | Update migrations table, recording a specific migration as rolled back |
| 57 | ${dim(class="st">'$')} prisma migrate resolve --rolled-back 20201231000000_add_users_table |
| 58 | |
| 59 | Specify a schema |
| 60 | ${dim(class="st">'$')} prisma migrate resolve --rolled-back 20201231000000_add_users_table --schema=./schema.prisma |
| 61 | `) |
| 62 | |
| 63 | public async parse(argv: string[], config: PrismaConfigInternal, baseDir: string): Promise<string | Error> { |
| 64 | const args = arg( |
| 65 | argv, |
| 66 | { |
| 67 | class="st">'--help': Boolean, |
| 68 | class="st">'-h': class="st">'--help', |
| 69 | class="st">'--applied': String, |
| 70 | class="st">'--rolled-back': String, |
| 71 | class="st">'--schema': String, |
| 72 | class="st">'--config': String, |
| 73 | class="st">'--telemetry-information': String, |
| 74 | }, |
| 75 | false, |
| 76 | ) |
| 77 | |
| 78 | if (isError(args)) { |
| 79 | return this.help(args.message) |