mirror of
https://github.com/laurent22/joplin.git
synced 2025-01-02 12:47:41 +02:00
Chore: Fixed server debug tools
This commit is contained in:
parent
05a4c05236
commit
dc8a095e47
@ -374,8 +374,10 @@ export async function dropTables(db: DbConnection): Promise<void> {
|
||||
}
|
||||
}
|
||||
|
||||
export async function truncateTables(db: DbConnection): Promise<void> {
|
||||
export async function truncateTables(db: DbConnection, includedTables: string[] = []): Promise<void> {
|
||||
for (const tableName of allTableNames()) {
|
||||
if (includedTables.length && !includedTables.includes(tableName)) continue;
|
||||
|
||||
try {
|
||||
await db(tableName).truncate();
|
||||
} catch (error) {
|
||||
|
@ -1,5 +1,5 @@
|
||||
import time from '@joplin/lib/time';
|
||||
import { DbConnection, dropTables, migrateLatest } from '../db';
|
||||
import { DbConnection, dropTables, migrateLatest, truncateTables } from '../db';
|
||||
import newModelFactory from '../models/factory';
|
||||
import { AccountType } from '../models/UserModel';
|
||||
import { User, UserFlagType } from '../services/database/types';
|
||||
@ -26,6 +26,25 @@ export async function clearDatabase(db: DbConnection) {
|
||||
await migrateLatest(db);
|
||||
}
|
||||
|
||||
const includedTables = [
|
||||
'changes',
|
||||
'emails',
|
||||
'events',
|
||||
'item_resources',
|
||||
'items',
|
||||
'notifications',
|
||||
'sessions',
|
||||
'share_users',
|
||||
'shares',
|
||||
'subscriptions',
|
||||
'teams',
|
||||
'team_users',
|
||||
'user_deletions',
|
||||
'user_flags',
|
||||
'user_items',
|
||||
'users',
|
||||
];
|
||||
|
||||
export async function createTestUsers(db: DbConnection, config: Config, options: CreateTestUsersOptions = null) {
|
||||
options = {
|
||||
count: 0,
|
||||
@ -34,9 +53,16 @@ export async function createTestUsers(db: DbConnection, config: Config, options:
|
||||
};
|
||||
|
||||
const password = '111111';
|
||||
|
||||
const models = newModelFactory(db, config);
|
||||
|
||||
await truncateTables(db, includedTables);
|
||||
|
||||
await models.user().save({
|
||||
email: 'admin@localhost',
|
||||
password: 'admin',
|
||||
is_admin: 1,
|
||||
});
|
||||
|
||||
if (options.count) {
|
||||
const users: User[] = [];
|
||||
|
||||
@ -46,14 +72,12 @@ export async function createTestUsers(db: DbConnection, config: Config, options:
|
||||
email: `user${userNum}@example.com`,
|
||||
password,
|
||||
full_name: `User ${userNum}`,
|
||||
account_type: userNum % 2 === 0 ? AccountType.Pro : AccountType.Basic,
|
||||
});
|
||||
}
|
||||
|
||||
await models.user().saveMulti(users);
|
||||
} else {
|
||||
await dropTables(db);
|
||||
await migrateLatest(db);
|
||||
|
||||
for (let userNum = 1; userNum <= 3; userNum++) {
|
||||
await models.user().save({
|
||||
email: `user${userNum}@example.com`,
|
||||
@ -112,3 +136,4 @@ export async function createUserDeletions(db: DbConnection, config: Config) {
|
||||
await models.userDeletion().add(users[i].id, Date.now() + 60 * Second + (i * 10 * Minute));
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user