File size: 765 Bytes
4327358
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import * as path from 'node:path';

import { Knex } from 'knex';

function migrateSDK(knex: Knex): Promise<any> {
  const config = {
    directory: `${__dirname}/migrations`,
    tableName: 'apps_migrations',
    loadExtensions: ['.js'],
  };
  return knex.migrate.latest(config);
}

function migrateApp(knex: Knex, app: string): Promise<any> {
  // one level upp
  const appsDirectory = path.join(__dirname, '..', '..', 'apps');
  const directory = path.join(appsDirectory, app, 'migrations');
  const config = {
    directory: directory,
    tableName: `app_${app}_migrations`,
    loadExtensions: ['.js'],
  };
  return knex.migrate.latest(config);
}

export async function migrate(knex: Knex) {
  await migrateSDK(knex);
  await migrateApp(knex, 'chatwoot');
}