Database deployments remain one of the most nerve-wracking parts of shipping code to production. One wrong move can bring down your entire application or corrupt critical data. The stakes are high: your schema migrations need to run in the correct order, data transitions must be handled carefully, and there's often no easy way back if things go wrong. While modern deployment tools have made shipping code changes relatively straightforward, database migrations still cause developers to break into a cold sweat. With DeployHQ you can deploy your database migrations with the same confidence as your code deployments!
Handling Node.js with Prisma
Say you're running a Node.js project, like a Next.js app with PostgreSQL, and you use Prisma to manage your database. You need to add a new users table during your next deployment. Here's how DeployHQ helps you do it.
First, set up your project by installing Prisma. Open your terminal and run:
npm install prisma @prisma/client
Next, initialize Prisma in your project:
npx prisma init
This creates a prisma
folder with a schema.prisma
file. Define your new table in the schema like this:
model User {
id Int @id @default(autoincrement())
name String
}
Then, create a migration by running:
npx prisma migrate dev --name add_users_table
This generates a migration file in the prisma/migrations
folder that looks something like this:
-- CreateTable
CREATE TABLE "User" (
"id" SERIAL NOT NULL,
"name" TEXT NOT NULL,
CONSTRAINT "User_pkey" PRIMARY KEY ("id")
);
Now, in DeployHQ, connect your project to your Git repository and choose your server. Enable zero-downtime deployments in the server settings — this uploads files to a temporary spot first, then switches them live only when everything's ready, keeping your app online the whole time.
Then, go to the "SSH Commands" section in your server settings. Add this command to run after the files are uploaded:
cd /path/to/deployment && npx prisma migrate deploy
Replace /path/to/deployment
with your server's deployment folder. When DeployHQ runs this, it applies your migration and updates the database. Make sure your database connection string is set up in your environment variables or .env
file on the server. You can define the .env
file as a config file in DeployHQ.
Managing Python with Alembic
Now let's look at a Python project, like a Flask app using SQLAlchemy and Alembic for database migrations. You want to add that same users table. DeployHQ makes it just as easy.
Start by installing the tools you need. In your terminal, type:
pip install alembic flask-sqlalchemy
Set up Alembic with:
alembic init migrations
Then, create a migration file for your new table by running:
alembic revision -m "add users table"
Edit the file it generates to look like this:
def upgrade():
op.create_table('users',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('name', sa.String(), nullable=False),
sa.PrimaryKeyConstraint('id')
)
def downgrade():
op.drop_table('users')
This adds the table when you deploy and removes it if you need to roll back.
In DeployHQ, link your project to your repository and set up your server. Turn on zero-downtime deployments to keep things seamless. Then, in the "SSH Commands" section, add:
cd /path/to/deployment && alembic upgrade head
Update the path to match your server's deployment folder. This command runs your migration after the files are in place, keeping your database in sync with your code.
Updating Data Alongside Schema Changes
Sometimes you need to update data too — like filling a new field with values—not just change the database structure. With DeployHQ, you can handle this easily. In Prisma, you can use seeders or add data changes to your migration files. With Alembic, include data updates in the migration script itself.
If you'd rather keep them separate, write a script for data updates and add another SSH command in DeployHQ to run it after the migration. Just make sure it happens in order: schema changes first, then data updates.
Keeping Things Safe if Problems Pop Up
With zero-downtime deployments, if something goes wrong, it won't switch to the new version — your app stays live on the old one. But if a migration updates your database and then something fails, the database might be ahead of your code.
To fix this, you can roll back manually. For Node.js, undo the last migration with:
npx prisma migrate undo
For Python, use:
alembic downgrade -1
Check the deployment logs in DeployHQ to catch any issues quickly. We recommend testing everything on a staging server first to make sure it all works before going live. If you need to rollback the code as well, you can do that natively with DeployHQ. Of course, you can also automate this process. How exactly that looks depends on your specific setup!
Tips for Smooth Deployments
To get the most out of DeployHQ for database deployments, keep your migration files in version control so you can track changes. Store database credentials securely—use environment variables or DeployHQ's config files. And monitor your deployments through the logs to stay on top of things.
Make backwards compatible migrations. Always add, never remove.
Test on a staging server before going live.
Make sure that rollbacks actually work. You don't want to realize too late that you can't roll back a failed migration!
Have backups of your database. You never know when you'll need them!
FAQ
You got questions? We got answers!
What is zero-downtime deployment?
Zero-downtime deployment is a deployment strategy where all changes are uploaded to a temporary location first, and only after everything is ready, the new version is switched live. This ensures your application stays online during the entire deployment process and prevents partial deployments that could break your application.
Do I need to use Prisma or Alembic?
No, you don't have to use Prisma or Alembic. While they are popular choices, DeployHQ works with any database migration tool. You can use:
- TypeORM
- Django migrations
- Flyway
- Or any other database migration tool
How do I handle failed migrations?
If a migration fails, DeployHQ's zero-downtime deployment ensures your application stays on the old version. You can:
- Check the deployment logs in DeployHQ to identify the issue
- Fix the migration file
- Commit and push the fix
- Deploy again
Can I roll back database changes?
Yes! Most migration tools provide rollback capabilities:
- Prisma:
npx prisma migrate reset
- Alembic:
alembic downgrade -1
Does DeployHQ have a free tier?
Yes! DeployHQ offers a free tier that includes:
- 1 project
- Auto-deploys
- 30 build minutes per month
- All integrations
How much does DeployHQ cost?
You can get started for free! All DeployHQ plans cover the basics of deploying your applications. Here's a quick overview:
Looking for more? Our Business ($39/mo) and Enterprise ($99/mo) plans include additional features like custom domains, priority deployments, and the ability to deploy behind firewalls.
Start free, no credit card required →
With DeployHQ, database deployments don't have to be complicated. Whether you're working with Node.js or Python, our SSH commands and zero-downtime deployments streamline schema migrations and data updates. You can deploy with confidence, knowing your app and database stay in sync, every time.