summaryrefslogtreecommitdiff
path: root/packages/backend/scripts/check_migrations_clean.js
blob: ce67b1cd812cd7f9a858f07fc6d555e1544fe5c4 (plain)
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
/*
 * SPDX-FileCopyrightText: syuilo and misskey-project
 * SPDX-License-Identifier: AGPL-3.0-only
 */

// This script checks if the database migrations has been generated correctly.

import dataSource from '../ormconfig.js';

await dataSource.initialize();

const sqlInMemory = await dataSource.driver.createSchemaBuilder().log();

if (sqlInMemory.upQueries.length > 0 || sqlInMemory.downQueries.length > 0) {
	console.error('There are several pending migrations. Please make sure you have generated the migrations correctly, or configured entities class correctly.');
	for (const query of sqlInMemory.upQueries) {
		console.error(`- ${query.query}`);
	}
	for (const query of sqlInMemory.downQueries) {
		console.error(`- ${query.query}`);
	}
	process.exit(1);
} else {
	console.log('All migrations are clean.');
	process.exit(0);
}