sqliteormvpsremix.rundrizzle

How to run generate & migrate in production on a VPS with SQLite database using Drizzle ORM & Remix?


So I have a database in development that I run db:generate & db:migrate on to create the database & then run my app that uses that database.

And it works fine.

But how do I do that in production when I can't run direct commands. I'm using https://easypanel.io on a self-hosted VPS.

Do I just use pre-scripts or post-scripts? What is the recommended way to go about it?

    "scripts": {
        "build": "remix build",
        "dev": "remix dev --manual",
        "lint": "eslint --ignore-path .gitignore --cache --cache-location ./node_modules/.cache/eslint .",
        "prestart": "npm run db:generate",
        "start": "remix-serve ./build/index.js",
        "clean": "rimraf .cache/ build/ public/build/",
        "db:push": "drizzle-kit push:sqlite --config drizzle.config.ts",
        "db:generate": "drizzle-kit generate:sqlite --config drizzle.config.ts",
        "db:studio": "drizzle-kit studio --host localhost --port 3002 --verbose --config drizzle.config.ts",
        "db:seed": "cross-env NODE_ENV=development tsx ./app/seed/index.ts",
        "typecheck": "tsc",
        "prettier": "prettier --write app/**/*.{ts,tsx}"
    },

I'm thinking of prestart like above. What is the best way to do it? I only want it to run one time to create ./sqlite.db & then don't want it.


Solution

  • I figured it out in Next.js using Docker which I had to learn but I bet its similar in Remix. This is the solution for Next.js but I'll post a Remix one soon as I have another app which uses the same stack but Next.js is replaced with Remix.