MCPcopy
hub / github.com/directus/directus / bootstrap

Function bootstrap

api/src/cli/commands/bootstrap/index.ts:17–77  ·  view source on GitHub ↗
({ skipAdminInit }: { skipAdminInit?: boolean })

Source from the content-addressed store, hash-verified

15import { getSchema } from '../../../utils/get-schema.js';
16
17export default async function bootstrap({ skipAdminInit }: { skipAdminInit?: boolean }): Promise<void> {
18 const logger = useLogger();
19
20 logger.info('Initializing bootstrap...');
21
22 const env = useEnv();
23
24 const database = getDatabase();
25
26 await waitForDatabase(database);
27
28 if ((await isInstalled()) === false) {
29 logger.info('Installing Directus system tables...');
30
31 await installDatabase(database);
32
33 logger.info('Running migrations...');
34 await runMigrations(database, 'latest');
35
36 const schema = await getSchema();
37
38 /*
39 * Initialize only the entitlement manager, not the full license
40 * manager: a single admin fits within core license limits, and
41 * staying at this layer keeps tests simple.
42 *
43 * Required regardless — createAdmin below triggers the seat
44 * counter, which errors if entitlements aren't registered.
45 */
46 getEntitlementManager();
47
48 if (skipAdminInit == null) {
49 await createAdmin(schema);
50 } else {
51 logger.info('Skipping creation of default Admin user and role...');
52 }
53
54 const settingsService = new SettingsService({ schema });
55
56 if (env['PROJECT_NAME'] && typeof env['PROJECT_NAME'] === 'string' && env['PROJECT_NAME'].length > 0) {
57 await settingsService.upsertSingleton({ project_name: env['PROJECT_NAME'] });
58 }
59
60 if (email().safeParse(env['PROJECT_OWNER']).success) {
61 await settingsService.setOwner({
62 project_owner: env['PROJECT_OWNER'] as string,
63 org_name: null,
64 project_usage: null,
65 product_updates: false,
66 });
67 }
68 } else {
69 logger.info('Database already initialized, skipping install');
70 logger.info('Running migrations...');
71 await runMigrations(database, 'latest');
72 }
73
74 await database.destroy();

Callers

nothing calls this directly

Calls 10

setOwnerMethod · 0.95
useEnvFunction · 0.90
useLoggerFunction · 0.85
getDatabaseFunction · 0.85
waitForDatabaseFunction · 0.85
isInstalledFunction · 0.85
getSchemaFunction · 0.85
getEntitlementManagerFunction · 0.85
createAdminFunction · 0.85
upsertSingletonMethod · 0.65

Tested by

no test coverage detected