Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

migrate.ts 687 B

You have to be logged in to leave a comment. Sign In
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
  1. import * as path from 'path';
  2. import { migrate } from 'drizzle-orm/better-sqlite3/migrator';
  3. import logger from './logger';
  4. import { getDb } from './database';
  5. /**
  6. * Run migrations on the database, skipping the ones already applied. Also creates the sqlite db if it doesn't exist.
  7. */
  8. export async function runDbMigrations() {
  9. try {
  10. const db = getDb();
  11. const migrationsFolder = path.join(__dirname, '..', 'drizzle');
  12. logger.debug(`Running migrations from ${migrationsFolder}...`);
  13. await migrate(db, { migrationsFolder });
  14. } catch (error) {
  15. logger.error('Error running database migrations:', error);
  16. }
  17. }
  18. if (require.main === module) {
  19. runDbMigrations();
  20. }
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...