Running migrations with "jets deploy" command

question

#1

I need to run migrations on when jets app is deployed using jets deploy command. Is there an inbuilt option?


#2

There’s no built-in option. Generally recommend using jets db:migrate outside the deploy process. A wrapper script could work. Something like bin/deploy:

jets db:migrate # the machine needs access to be able to migrate
jets deploy

#3

Hello @tung,

Can you give us an example of your proposal? IMHO the deploy process has the responsibility of executing the migrations.

Thank you.


#4

Wondering if you may have missed the script above :thinking: Here is the bin/deploy script in a more full form:

bin/deploy:

#!/bin/bash
jets db:migrate # the machine needs access to be able to migrate
jets deploy

NOTE: the machine you’re calling jets db:migrate from needs to have access to the db.

Cool. Guess there are mixed opinions on this:

Think it’s fine to have the deploy run migrations automatically, particularly on small DBs. On larger DBs, it’s often not feasible. The main issue is the script needs ran from a machine that has DB access.


#5

Thanks for answer so fast!

In the project that I’m working I don’t have bin/deploy file, do I need to create it?


#6

Yes. You want to make it executable also. You can do that with this: chmod a+x bin/deploy.


#7

Hi @tung

That I understood was to add this file to my project to automatically run the migrations when I’m deploying the project to AWS.

I did it, and after that, I thought that it is to run migrations locally before deploy.

I want to run migrations in the action of deploy. I created an Aurora RDS with a MySQL instance, without external access and I want to run migrations. I know if I have access to the RDS I can do it, but I’m thinking to do it automatically.


#8

The thing here @tung, is that when we are using an aurora serverless we can’t have public access.


#9

Yup. Aurora serverless DBs are only accessible within the VPC. Essentially, you cannot run jets db:migrate from outside the VPC with Aurora.

Think you may be better off running a bin/deploy wrapper script on something like CodeBuild and configure the CodeBuild project to be within your vpc. The CodeBuild project script would run on an EC2 instance within the VPC, which has access to Aurora DB. This may help: https://docs.aws.amazon.com/codebuild/latest/userguide/vpc-support.html

The #2 method in How do I Migrate the Database? could also work. As the lambda function, which runs the migrate command, would also be within the VPC. Note, the lambda would need to be configured with vpc_config like so Is anyone using vpc_config? This approach is a bit of a hack though.

Both ways are some work.