Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Programmatically run drizzle migrations #1936

Open
gnllucena opened this issue Jan 29, 2025 · 0 comments
Open

Programmatically run drizzle migrations #1936

gnllucena opened this issue Jan 29, 2025 · 0 comments

Comments

@gnllucena
Copy link

Hey, guys!

I'm using drizzle with libsql, and due to some constraints I cannot use drizzle-kit push to run migrations.

I know some drizzle packages have the migrate function which you can use to run migrations programmatically, something lile:

import { drizzle } from 'drizzle-orm/node-postgres'
import { migrate } from 'drizzle-orm/node-postgres/migrator'
import { Pool } from 'pg'
import { Resource } from 'sst'

export const handler = async () => {
  const pool = new Pool({
    user: Resource.RDS.username,
    password: Resource.RDS.password,
    database: Resource.RDS.database,
    host: Resource.RDS.host,
    port: Resource.RDS.port,
  })

  const db = drizzle(pool)

  try {
    await migrate(db, { migrationsFolder: './migrations' })

    return {
      statusCode: 200,
      body: JSON.stringify({ message: 'Migrations completed successfully.' }),
    }
  } catch (err: any) {
    return {
      statusCode: 500,
      body: JSON.stringify({
        message: 'Migration failed.',
        error: err.message,
      }),
    }
  }
}

And I can't seem to find the migrate function on drizzle libsql package:

import { drizzle } from "drizzle-orm/libsql"

is it possible to do that with libsql?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant