-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
migrate pglite dynamically if no postgres url
- Loading branch information
Showing
6 changed files
with
62 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { drizzle } from 'drizzle-orm/pglite'; | ||
import { migrate as pgliteMigrate } from 'drizzle-orm/pglite/migrator'; | ||
import { PGlite } from '@electric-sql/pglite'; | ||
import { config } from 'dotenv'; | ||
|
||
config({ path: '../../.env' }); | ||
|
||
async function runMigrations() { | ||
if (process.env.POSTGRES_URL) { | ||
console.log('Using PostgreSQL database'); | ||
// You'll need to add PostgreSQL migration logic here if needed | ||
return; | ||
} | ||
|
||
console.log('Using PGlite database'); | ||
const client = new PGlite('file://../../pglite'); | ||
const db = drizzle(client); | ||
|
||
try { | ||
await pgliteMigrate(db, { | ||
migrationsFolder: './drizzle/migrations', | ||
}); | ||
console.log('Migrations completed successfully'); | ||
} catch (error) { | ||
console.error('Migration failed:', error); | ||
process.exit(1); | ||
} | ||
} | ||
|
||
runMigrations().catch(console.error); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters