MCPcopy Create free account
hub / github.com/Openpanel-dev/openpanel / migrate

Function migrate

packages/db/code-migrations/migrate.ts:17–89  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

15} from './helpers';
16
17async function migrate() {
18 const args = process.argv.slice(2);
19 const migration = args.filter((arg) => !arg.startsWith('--'))[0];
20
21 const migrationsDir = path.join(__dirname, '..', 'code-migrations');
22 const migrations = fs
23 .readdirSync(migrationsDir)
24 .filter((file) => {
25 const version = file.split('-')[0];
26 return (
27 !Number.isNaN(Number.parseInt(version ?? '')) && file.endsWith('.ts')
28 );
29 })
30 .sort((a, b) => {
31 const aVersion = Number.parseInt(a.split('-')[0]!);
32 const bVersion = Number.parseInt(b.split('-')[0]!);
33 return aVersion - bVersion;
34 });
35
36 const finishedMigrations = await db.codeMigration.findMany();
37
38 printBoxMessage('📋 Plan', [
39 '\t✅ Finished:',
40 ...finishedMigrations.map(
41 (migration) => `\t- ${migration.name} (${migration.createdAt})`,
42 ),
43 '',
44 '\t🔄 Will run now:',
45 ...migrations
46 .filter(
47 (migration) =>
48 !finishedMigrations.some(
49 (finishedMigration) => finishedMigration.name === migration,
50 ),
51 )
52 .map((migration) => `\t- ${migration}`),
53 ]);
54
55 printBoxMessage('🤝 Config', [
56 `isClustered: ${getIsCluster()}`,
57 `isSelfHosting: ${getIsSelfHosting()}`,
58 ]);
59
60 printBoxMessage('🌍 Environment', [
61 `POSTGRES: ${process.env.DATABASE_URL}`,
62 `CLICKHOUSE: ${process.env.CLICKHOUSE_URL}`,
63 ]);
64
65 if (!getIsSelfHosting()) {
66 if (!getIsDry()) {
67 printBoxMessage('🕒 Migrations starts in 10 seconds', []);
68 await new Promise((resolve) => setTimeout(resolve, 10000));
69 } else {
70 printBoxMessage('🕒 Migrations starts now (dry run)', []);
71 }
72 }
73
74 if (migration) {

Callers 1

migrate.tsFile · 0.85

Calls 9

printBoxMessageFunction · 0.90
getIsClusterFunction · 0.90
getIsSelfHostingFunction · 0.90
getIsDryFunction · 0.90
runMigrationFunction · 0.85
joinMethod · 0.80
mapMethod · 0.45
someMethod · 0.45
logMethod · 0.45

Tested by

no test coverage detected