planetscale/cli

`deploy-request` seems to make assumptions about `main` branch

yquansah opened this issue ยท 4 comments

Repro steps:

$ pscale database create test-db
Database test-db was successfully created.

View this database in the browser: https://app.planetscale.com/yqsummon/test-db
$ pscale branch create test-db feat-branch
Branch feat-branch was successfully created.

View this branch in the browser: https://app.planetscale.com/yqsummon/test-db/feat-branch
$ pscale branch promote test-db feat-branch
Branch feat-branch in test-db was successfully promoted.
$ pscale branch list test-db
  NAME          PARENT BRANCH   PRODUCTION   READY   CREATED AT      UPDATED AT
 ------------- --------------- ------------ ------- --------------- ---------------
  main          n/a             No           Yes     2 minutes ago   1 minute ago
  feat-branch   n/a             Yes          Yes     1 minute ago    9 seconds ago

$ pscale deploy-request create test-db main
Error: Database branch main is not a production branch.
$ pscale branch delete test-db main
? Please type test-db/main to confirm: test-db/main
Branch main was successfully deleted from test-db.
$ pscale branch create test-db another-feat-branch
Branch another-feat-branch was successfully created.

View this branch in the browser: https://app.planetscale.com/yqsummon/test-db/another-feat-branch
$ pscale branch list test-db
  NAME                  PARENT BRANCH   PRODUCTION   READY   CREATED AT       UPDATED AT
 --------------------- --------------- ------------ ------- ---------------- ----------------
  feat-branch           n/a             Yes          Yes     3 minutes ago    2 minutes ago
  another-feat-branch   feat-branch     No           No      11 seconds ago   11 seconds ago

$ pscale deploy-request create test-db another-feat-branch
Error: Database branch main is invalid or does not exist.

It seems as though main branch must be present in order for a successful deploy request to be created from one branch to the primary branch (which is main in this case). Is it the case that the main branch needs to be present? Or can any branch serve as the primary branch of which feature branches branch off of in order to create a deploy request?

It seems to suggest that you can make any branch a production branch as I did with feat-branch, when I promoted it.

Thanks for for thorough report and reproduction steps. You shouldn't need a branch named main, other branches can be promoted, be the target of deploy requests, and become the default branch.

I think this is caused by the default value of the --deploy-to argument:

$ pscale --version
pscale version 0.126.0 (build date: 2022-12-19T16:14:33Z commit: 080016c)

$ pscale deploy-request create test-db another-feat-branch
Error: Database branch main is invalid or does not exist.

$ pscale deploy-request create test-db another-feat-branch --deploy-to feat-branch
Deploy request #1 successfully created.

View this deploy request in the browser: https://app.planetscale.com/jgreet/test-db/deploy-requests/1
$ pscale deploy-request create --help
Create a deploy request from a branch

Usage:
  pscale deploy-request create <database> <branch> [flags]

Flags:
      --deploy-to string   Branch to deploy the branch. By default it's set to 'main' (default "main")

Perhaps we can change this to use the default branch setting for the database, which is updated to feat-branch when you delete main. I believe that's how it works in the web app.

@jgreet Ah, that makes sense. Did not notice the --deploy-to flag there. Thanks for the response.

Would it make sense for --deploy-to to be explicitly provided by the user? (Since there is a case where main can be deleted.)

It seems as though if a user had a dev workflow of a lower environment schema before deploying to main, they would have to provide that flag value of --deploy-to most times anyway.

Hey @yquansah! Thanks for opening this issue.

We've gone ahead and cut a new release that removes these assumptions about the name being main, now defaulting to either the parent branch (if present) or the default branch of the database. Let us know if you run into any more hiccups!

@iheanyi Thank you ๐Ÿ™ will give it a try.